From 386018b9569efa1d62b24144bc814e2e62151bb7 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Sun, 28 Jun 2026 12:36:02 +0200 Subject: [PATCH] feat(manual): add sublime syntax for Midas --- docs/midas.sublime-syntax | 176 ++++++++++++++++++++++++++++++++++++++ docs/template.typ | 2 + 2 files changed, 178 insertions(+) create mode 100644 docs/midas.sublime-syntax diff --git a/docs/midas.sublime-syntax b/docs/midas.sublime-syntax new file mode 100644 index 0000000..66db18e --- /dev/null +++ b/docs/midas.sublime-syntax @@ -0,0 +1,176 @@ +%YAML 1.2 +--- +name: Midas +file_extensions: + - midas +scope: source.midas + +variables: + identifier: "[a-zA-Z_][a-zA-Z0-9_]*" + +contexts: + main: + - include: comments + - include: keywords + - include: types + + comments: + - match: "//" + scope: punctuation.definition.comment.midas + push: + - meta_scope: comment.line.midas + - match: $ + pop: true + - match: /\* + scope: punctuation.definition.comment.midas + push: + - meta_scope: comment.block.midas + - match: \*/ + pop: true + + keywords: + - match: \btype\b + scope: keyword.declaration.midas + push: type-stmt + - match: \bextend\b + scope: keyword.declaration.midas + push: extend-stmt + - match: \bpredicate\b + scope: keyword.declaration.midas + push: predicate-stmt + + type-stmt: + - include: comments + - match: "{{identifier}}" + scope: entity.name.type + - match: \[ + push: type-params + - match: "=" + scope: keyword.operator.equal.midas + push: type-expr + - match: $ + pop: true + + type-expr: + - include: comments + - match: \b(fn)\s*(\() + captures: + 1: keyword.other.midas + 2: punctuation.section.group.begin + push: fn-params + - match: \b(where)\b + scope: keyword.other.midas + set: constraint + - match: "{{identifier}}" + scope: entity.name.type + - match: $ + pop: 2 + + fn-params: + - match: "({{identifier}})(:)" + captures: + 1: variable.parameter.midas + 2: punctuation.separator.annotation.midas + push: + - include: type-expr + - match: \? + scope: keyword.operator.qmark.midas + - match: "(?=,)" + scope: punctuation.separator.midas + pop: true + - match: '(?=\))' + pop: true + - include: type-expr + - match: '\)' + set: + - match: "->" + scope: keyword.operator.arrow.midas + set: type-expr + + constraint: + - include: comments + - match: $ + pop: 2 + + - match: \d+(\.\d+)? + scope: constant.numeric.midas + + - match: \b(true|false|none)\b + scope: constant.language.midas + + - match: (<=|>=|<|>|==|!=|&) + scope: keyword.operator + + - match: _ + scope: variable.language.midas + + - match: '{{identifier}}(?=\s*\()' + scope: variable.function.midas + + - match: "{{identifier}}" + scope: variable.other.readwrite.midas + + type-params: + - include: comments + - match: "<:" + scope: keyword.operator.subtype.midas + - match: "[a-zA-Z][a-zA-Z_0-9]*" + scope: entity.name.type + - match: "]" + pop: true + + extend-stmt: + - include: comments + - match: "{{identifier}}" + scope: entity.name.type + - match: \[ + push: type-params + - match: \{ + scope: punctuation.section.block.begin + push: extend-body + + extend-body: + - include: comments + - include: member-stmt + - match: \} + scope: punctuation.section.block.end + pop: 2 + + member-stmt: + - match: \b(prop|def)\b + scope: keyword.other.midas + push: + - match: "{{identifier}}" + scope: variable.other.member + - match: ":" + push: type-expr + - match: $ + pop: true + + predicate-stmt: + - include: comments + - match: "{{identifier}}" + scope: entity.name.function.midas + - match: '\(' + push: predicate-params + - match: "=" + scope: keyword.operator.equal.midas + set: constraint + - match: $ + pop: true + + predicate-params: + - match: "({{identifier}})(:)" + captures: + 1: variable.parameter.midas + 2: punctuation.separator.annotation.midas + push: + - include: type-expr + - match: "(?=,)" + scope: punctuation.separator.midas + pop: true + - match: '(?=\))' + pop: true + + - match: '\)' + pop: true diff --git a/docs/template.typ b/docs/template.typ index 1861b5f..c4c1386 100644 --- a/docs/template.typ +++ b/docs/template.typ @@ -77,6 +77,8 @@ numbering: "1 / 1", ) + set raw(syntaxes: path("midas.sublime-syntax")) + // Title page align(center)[ #std.title()