Merge pull request 'Update syntax definitions' (#34) from feat/update-syntax into main

Reviewed-on: #34
This commit was merged in pull request #34.
This commit is contained in:
2026-07-08 12:48:14 +00:00
9 changed files with 740 additions and 246 deletions

View File

@@ -632,7 +632,7 @@ class MidasParser(Parser[list[Stmt]]):
return WildcardExpr(location=token.get_location(), token=token) return WildcardExpr(location=token.get_location(), token=token)
if self.match(TokenType.LEFT_PAREN): if self.match(TokenType.LEFT_PAREN):
expr: Expr = self.constraint() expr: Expr = self.expression()
right: Token = self.consume(TokenType.RIGHT_PAREN, "Unclosed parenthesis") right: Token = self.consume(TokenType.RIGHT_PAREN, "Unclosed parenthesis")
return GroupingExpr(location=token.location_to(right), expr=expr) return GroupingExpr(location=token.location_to(right), expr=expr)

View File

@@ -380,7 +380,7 @@ class PythonParser:
for col in cols: for col in cols:
columns.append(self._parse_frame_column(col)) columns.append(self._parse_frame_column(col))
case ast.Slice() | ast.Name(): case ast.Slice() | ast.Name() | ast.Subscript():
columns.append(self._parse_frame_column(schema)) columns.append(self._parse_frame_column(schema))
case _: case _:
@@ -391,7 +391,7 @@ class PythonParser:
def _parse_frame_column(self, column: ast.expr) -> FrameColumn: def _parse_frame_column(self, column: ast.expr) -> FrameColumn:
loc: Location = Location.from_ast(column) loc: Location = Location.from_ast(column)
match column: match column:
case ast.Name(): case ast.Name() | ast.Subscript():
return FrameColumn( return FrameColumn(
location=loc, location=loc,
name=None, name=None,

View File

@@ -1,20 +1,8 @@
identifier ::= '[a-zA-Z][a-zA-Z_]*' Identifier ::= '[a-zA-Z][a-zA-Z_]*'
integer ::= '\d+' TypeArgs ::= "[" (Type ("," Type)*)? "]"
number ::= integer ["." integer]
boolean ::= "False" | "True"
none ::= "None"
value ::= number | boolean | none FrameColumn ::= ((Identifier | "_") ":")? Type
lambda-value ::= "_" | value FrameSchema ::= "[" (FrameColumn ("," FrameColumn)*)? "]"
lambda-operator ::= ">" | "<" | ">=" | "<=" | "==" | "!="
lambda ::= lambda-value lambda-operator lambda-value
constraint ::= identifier | "(" lambda ")" Type ::= "Frame" FrameSchema | Identifier TypeArgs?
base-type ::= identifier
type ::= base-type { "+" constraint }
column-type ::= type | "_"
column-def ::= [ identifier ":" ] column-type
frame-def ::= column-def { "," column-def }

View File

@@ -1,64 +1,72 @@
#import "@preview/fervojo:0.1.1": render #import "@preview/fervojo:0.1.1": default-css, render
#let value = ``` #let extra-css = ```css
{[`value` < svg.railroad .terminal rect {
[`number` 'digit' * ! <!, ["." 'digit' * !]>], fill: #F7DCD4;
[`boolean` <"False", "True">], }
[`none` "None"] ```
#let css = default-css() + bytes(extra-css.text)
#let type-args = ```
{[`type-args` "[" <!, 'type'*","> "]"]}
```
#let frame-schema = ```
{[`frame-schema` "[" <!, [[<'identifier', "_"> ":"]? 'type']*","> "]"]}
```
#let type = ```
{[`type` <
["Frame" 'frame-schema'],
['identifier' <!, 'type-args'>]
>]} >]}
``` ```
#let constraint = ```
{[`constraint` <"_", 'value'> <">", "<", ">=", "<=", "==", "!="> <"_", 'value'>]}
```
#let type-with-constraints = ```
{[`type-with-constraints` 'identifier' <!, ["+" "(" 'constraint' ")"] * !>]}
```
#let column-def = ```
{[`column-def` <!, ['identifier' ":"]> <"_", 'type-with-constraints'>]}
```
#let frame-def = ```
{[`frame-def` 'column-def' * ","]}
```
#let annotation = ```
{[`annotation` 'identifier' <!, ["[" 'frame-def' "]"]>]}
```
#let rules = ( #let rules = (
value, type-args: type-args,
constraint, frame-schema: frame-schema,
type-with-constraints, type: type,
column-def, )
frame-def,
annotation, #let inline = (
"type-args",
"frame-schema",
) )
#set text(font: "Source Sans 3") #set text(font: "Source Sans 3")
= Type annotation syntax #title[Supported Python annotation syntax]
#for rule in rules { = Outline
render(rule)
}
/* #box(
#let by-name = ( columns(
annotation: annotation, 2,
frame-def: frame-def, outline(title: none),
column-def: column-def, ),
type-with-constraints: type-with-constraints, height: 9cm,
constraint: constraint, stroke: 1pt,
value: value, inset: 1em,
) )
= Statements and expressions
#for (name, rule) in rules.pairs().rev() {
[== #name]
render(rule, css: css)
}
#let substitute(base-rule) = { #let substitute(base-rule) = {
let new-rule = base-rule let new-rule = base-rule
for (key, rule) in by-name.pairs() { for name in inline {
new-rule = new-rule.replace("'" + key + "'", rule.text.slice(1, -1)) let rule = rules.at(name)
let replacement = rule.text.slice(1, -1).replace(regex("\[`.*?`"), "[")
replacement = "[" + replacement + "#`" + name + "`]"
new-rule = new-rule.replace(
"'" + name + "'",
replacement,
)
} }
if new-rule != base-rule { if new-rule != base-rule {
new-rule = substitute(new-rule) new-rule = substitute(new-rule)
@@ -66,9 +74,16 @@
return new-rule return new-rule
} }
#let combined = raw(substitute(annotation.text))
#set page(flipped: true) #set page(flipped: true)
#render(combined)
*/
= Combined rules
#for (name, rule) in rules.pairs() {
if not name in inline {
[== #name]
let combined = substitute(rule.text)
render(raw(combined), css: css)
//raw(block: true, combined)
}
}

View File

@@ -4,40 +4,87 @@ Identifier ::= [a-zA-Z_] [a-zA-Z_0-9]*
Integer ::= '\d+' Integer ::= '\d+'
Number ::= "-"? Integer ("." Integer)? Number ::= "-"? Integer ("." Integer)?
Boolean ::= "False" | "True" Boolean ::= "False" | "True"
String ::= '(".*?")|(\'.*?\')'
None ::= "None" None ::= "None"
Value ::= Number | Boolean | None Literal ::= Number | Boolean | String | None
UnaryOp ::= "+" | "-" | "!"
FactorOp ::= "*" | "/"
TermOp ::= "+" | "-"
ComparisonOp ::= ">" | "<" | ">=" | "<=" ComparisonOp ::= ">" | "<" | ">=" | "<="
EqualityOp ::= "==" | "!=" EqualityOp ::= "==" | "!="
Grouping ::= "(" Constraint ")" PosArg ::= Expression
Primary ::= "_" | Value | Identifier | Grouping KwArg ::= Identifier "=" Expression
PosArgs ::= PosArg ("," PosArg)*
KwArgs ::= KwArg ("," KwArg)*
Args ::= (
PosArgs
| KwArgs
| PosArgs "," KwArgs
)
Grouping ::= "(" Expression ")"
Primary ::= "_" | Literal | Identifier | Grouping
Reference ::= Primary ("." Identifier)* Reference ::= Primary ("." Identifier)*
Unary ::= "-"? Unary | Reference CallArgs ::= "(" Args ")"
Comparison ::= Unary (ComparisonOp Unary)* Call ::= Reference CallArgs*
Unary ::= UnaryOp Unary | Call
Factor ::= Unary (FactorOp Unary)*
Term ::= Factor (TermOp Factor)*
Comparison ::= Term (ComparisonOp Term)*
Equality ::= Comparison (EqualityOp Comparison)* Equality ::= Comparison (EqualityOp Comparison)*
Constraint ::= Equality ("&" Equality)* Expression ::= Equality ("&" Equality)*
Constraint ::= Expression
TemplateParam ::= Identifier ("<:" Type)? TemplateParam ::= Identifier ("<:" Type)?
Template ::= "[" (TemplateParam ("," TemplateParam)*)? "]" Template ::= "[" (TemplateParam ("," TemplateParam)*)? "]"
ParamType ::= Type "?"?
PosParam ::= (Identifier ":")? ParamType
KwParam ::= Identifier ":" ParamType
PosParams ::= (
(PosParam ("," PosParam)* ("," "/")?)
| "/"
)
MixedParams ::= KwParam ("," KwParam)
KwParams ::= (
(("*", ",")? KwParam ("," KwParam)*)
| "*"
)
Params ::= (
PosParams
| MixedParams
| KwParams
| (PosParams "," MixedParams)
| (PosParams "," KwParams)
| (MixedParams "," KwParams)
| (PosParams "," MixedParams "," KwParams)
)
ParamSpec ::= "(" Params? ")"
TypeProperty ::= Identifier ":" Type TypeProperty ::= Identifier ":" Type
ComplexType ::= "{" TypeProperty* "}" ComplexType ::= "{" TypeProperty* "}"
NamedType ::= Identifier NamedType ::= Identifier
TypeParams ::= "[" (Type ("," Type)*)? "]" TypeArgs ::= "[" (Type ("," Type)*)? "]"
GenericType ::= NamedType TypeParams? FrameColumn ::= TOKEN ":" Type
FrameSchema ::= "[" (FrameColumn ("," FrameColumn)*)? "]"
GenericType ::= "Frame" FrameSchema | NamedType TypeArgs?
GroupedType ::= "(" Type ")" GroupedType ::= "(" Type ")"
BaseType ::= GroupedType | ComplexType | GenericType BaseType ::= GroupedType | ComplexType | GenericType
ConstraintType ::= BaseType ("where" Constraint)? ConstraintType ::= BaseType ("where" Constraint)?
FuncType ::= "fn" ParamSpec "->" Type
Type ::= ConstraintType Type ::= ConstraintType
OpDefinition ::= "op" Identifier "(" Type ")" "->" Type MemberStatement ::= ("prop" | "def") Identifier ":" Type
ExtendBody ::= "{" OpDefinition* "}" ExtendBody ::= "{" MemberStatement* "}"
AliasStatement ::= "alias" Identifier "=" Type
TypeStatement ::= "type" Identifier Template? "=" Type TypeStatement ::= "type" Identifier Template? "=" Type
ExtendStatement ::= "extend" Type ExtendBody ExtendStatement ::= "extend" Type ExtendBody
PredicateStatement ::= "predicate" Identifier "(" Identifier ":" Type ")" "=" Constraint PredicateStatement ::= "predicate" Identifier ParamSpec* "=" Constraint
Statement ::= TypeStatement | ExtendStatement | PredicateStatement Statement ::= AliasStatement | TypeStatement | ExtendStatement | PredicateStatement

View File

@@ -7,40 +7,61 @@ svg.railroad .terminal rect {
``` ```
#let css = default-css() + bytes(extra-css.text) #let css = default-css() + bytes(extra-css.text)
#let value = ``` #let literal = ```
{[`value` < {[`literal` <
[`number` 'digit' * ! <!, ["." 'digit' * !]>], [`number` 'digit' * ! <!, ["." 'digit' * !]>],
[`boolean` <"False", "True">], [`boolean` <"False", "True">],
[`string` <["\"" 'char'*! "\""], ["'" 'char'*! "'"]>],
[`none` "None"] [`none` "None"]
>]} >]}
``` ```
#let grouping = ``` #let grouping = ```
{[`grouping` "(" 'constraint' ")"]} {[`grouping` "(" 'expression' ")"]}
``` ```
#let primary = ``` #let primary = ```
{[`primary` <"_", 'value', 'identifier', 'grouping'>]} {[`primary` <"_", 'literal', 'identifier', 'grouping'>]}
``` ```
#let reference = ``` #let reference = ```
{[`reference` 'primary' <!, ["." 'identifier']*!>]} {[`reference` 'primary' <!, ["." 'identifier']*!>]}
``` ```
#let call-args = ```
{[`call-args` "(" <!, <'expression', ['identifier' "=" 'expression']>*","#`Same rules as Python`> ")"]}
```
#let call = ```
{[`call` 'reference' <!, 'call-args'*!>]}
```
#let unary = ``` #let unary = ```
{[`unary` <[<!, "-"> 'unary'], 'reference'>]} {[`unary` <[<"+", "-", "!"> 'unary'], 'call'>]}
```
#let factor = ```
{[`factor` 'unary'*<"*", "/">]}
```
#let term = ```
{[`term` 'factor'*<"+", "-">]}
``` ```
#let comparison = ``` #let comparison = ```
{[`comparison` 'unary'*<">", "<", ">=", "<=">]} {[`comparison` 'term'*<">", "<", ">=", "<=">]}
``` ```
#let equality = ``` #let equality = ```
{[`equality` 'comparison'*<"==", "!=">]} {[`equality` 'comparison'*<"==", "!=">]}
``` ```
#let expression = ```
{[`expression` 'equality'*"&"]}
```
#let constraint = ``` #let constraint = ```
{[`constraint` 'equality'*"&"]} {[`constraint` 'expression']}
``` ```
#let template-param = ``` #let template-param = ```
@@ -63,12 +84,16 @@ svg.railroad .terminal rect {
{[`named-type` 'identifier']} {[`named-type` 'identifier']}
``` ```
#let type-params = ``` #let type-args = ```
{[`type-params` "[" <!, 'type'*","> "]"]} {[`type-args` "[" <!, 'type'*","> "]"]}
```
#let frame-schema = ```
{[`frame-schema` "[" <!, ['TOKEN' ":" 'type']*","> "]"]}
``` ```
#let generic-type = ``` #let generic-type = ```
{[`generic-type` 'named-type' <!, 'type-params'>]} {[`generic-type` <["Frame" 'frame-schema'], ['named-type' <!, 'type-args'>]>]}
``` ```
#let grouped-type = ``` #let grouped-type = ```
@@ -83,52 +108,82 @@ svg.railroad .terminal rect {
{[`constraint-type` 'base-type' <!, ["where" 'constraint']>]} {[`constraint-type` 'base-type' <!, ["where" 'constraint']>]}
``` ```
#let pos-param = ```
{[`pos-param` <!, ['identifier' ":"]> 'type' <!, "?">]}
```
#let kw-param = ```
{[`kw-param` 'identifier' ":" 'type' <!, "?">]}
```
#let param-spec = ```
{[`param-spec` "(" <!, <'pos-param', "/", "*", 'kw-param'>*",">#`Same rules as Python` ")"]}
```
#let func-type = ```
{[`func-type` "fn" 'param-spec' "->" 'type']}
```
#let type = ``` #let type = ```
{[`type` 'constraint-type']} {[`type` <'func-type', 'constraint-type'>]}
```
#let alias-statement = ```
{[`alias-statement` "alias" 'identifier' "=" 'type']}
``` ```
#let type-statement = ``` #let type-statement = ```
{[`type-statement` "type" 'identifier' <!, 'template'> "=" 'type']} {[`type-statement` "type" 'identifier' <!, 'template'> "=" 'type']}
``` ```
#let op-definition = ``` #let member-stmt = ```
{[`op-definition` "op" 'identifier' "(" 'type' ")" "->" 'type']} {[`member-stmt` <"prop", "def"> 'identifier' ":" 'type']}
``` ```
#let extend-statement = ``` #let extend-statement = ```
{[`extend-statement` "extend" 'type' "{" <!, 'op-definition'*!> "}"]} {[`extend-statement` "extend" 'type' "{" <!, 'member-stmt'*!> "}"]}
``` ```
#let predicate-statement = ``` #let predicate-statement = ```
{[`predicate-statement` "predicate" 'identifier' "(" 'identifier' ":" 'type' ")" "=" 'constraint']} {[`predicate-statement` "predicate" 'identifier' <!, 'param-spec'*!> "=" 'constraint']}
``` ```
#let statement = ``` #let statement = ```
{[`statement` <'type-statement', 'extend-statement', 'predicate-statement'>]} {[`statement` <'alias-statement', 'type-statement', 'extend-statement', 'predicate-statement'>]}
``` ```
#let rules = ( #let rules = (
value: value, literal: literal,
grouping: grouping, grouping: grouping,
primary: primary, primary: primary,
reference: reference, reference: reference,
call-args: call-args,
call: call,
unary: unary, unary: unary,
factor: factor,
term: term,
comparison: comparison, comparison: comparison,
equality: equality, equality: equality,
expression: expression,
constraint: constraint, constraint: constraint,
template-param: template-param, template-param: template-param,
template: template, template: template,
type-property: type-property, type-property: type-property,
complex-type: complex-type, complex-type: complex-type,
named-type: named-type, named-type: named-type,
type-params: type-params, type-args: type-args,
generic-type: generic-type, generic-type: generic-type,
grouped-type: grouped-type, grouped-type: grouped-type,
base-type: base-type, base-type: base-type,
constraint-type: constraint-type, constraint-type: constraint-type,
pos-param: pos-param,
kw-param: kw-param,
param-spec: param-spec,
func-type: func-type,
type: type, type: type,
alias-statement: alias-statement,
type-statement: type-statement, type-statement: type-statement,
op-definition: op-definition, member-stmt: member-stmt,
extend-statement: extend-statement, extend-statement: extend-statement,
predicate-statement: predicate-statement, predicate-statement: predicate-statement,
statement: statement, statement: statement,
@@ -136,18 +191,23 @@ svg.railroad .terminal rect {
#let inline = ( #let inline = (
"grouping", "grouping",
"value", "literal",
"template-param", "template-param",
"template", "template",
"type-property", "type-property",
"call-args",
"complex-type", "complex-type",
"type-params", "type-args",
"named-type", "named-type",
"grouped-type", "grouped-type",
"generic-type", "generic-type",
"base-type", "base-type",
"constraint-type", "constraint-type",
"op-definition", "pos-param",
"kw-param",
"func-type",
"member-stmt",
"alias-statement",
"type-statement", "type-statement",
"extend-statement", "extend-statement",
"predicate-statement", "predicate-statement",
@@ -164,7 +224,7 @@ svg.railroad .terminal rect {
2, 2,
outline(title: none), outline(title: none),
), ),
height: 9cm, height: 15cm,
stroke: 1pt, stroke: 1pt,
inset: 1em, inset: 1em,
) )

View File

@@ -1,19 +1,16 @@
{ {
"brackets": [ "brackets": [
["{", "}"], ["{", "}"],
["[", "]"], ["[", "]"]
["<", ">"]
], ],
"autoClosingPairs": [ "autoClosingPairs": [
{ "open": "{", "close": "}" }, { "open": "{", "close": "}" },
{ "open": "[", "close": "]" }, { "open": "[", "close": "]" },
{ "open": "(", "close": ")" }, { "open": "(", "close": ")" }
{ "open": "<", "close": ">" }
], ],
"surroundingPairs": [ "surroundingPairs": [
["{", "}"], ["{", "}"],
["[", "]"], ["[", "]"],
["(", ")"], ["(", ")"]
["<", ">"]
] ]
} }

View File

@@ -10,7 +10,6 @@
{ {
"id": "midas", "id": "midas",
"extensions": [ "extensions": [
".mpy",
".midas" ".midas"
], ],
"aliases": [ "aliases": [
@@ -23,10 +22,7 @@
{ {
"language": "midas", "language": "midas",
"scopeName": "source.midas", "scopeName": "source.midas",
"path": "./syntaxes/midas.tmLanguage.json", "path": "./syntaxes/midas.tmLanguage.json"
"embeddedLanguages": {
"meta.embedded.block.python": "python"
}
} }
] ]
} }

View File

@@ -2,167 +2,558 @@
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "Midas", "name": "Midas",
"scopeName": "source.midas", "scopeName": "source.midas",
"patterns": [{ "include": "#statement" }], "fileTypes": [
"midas"
],
"patterns": [
{
"include": "#comments"
},
{
"include": "#alias-stmt"
},
{
"include": "#type-stmt"
},
{
"include": "#extend-stmt"
},
{
"include": "#extend-body"
},
{
"include": "#predicate-stmt"
}
],
"repository": { "repository": {
"comment": { "comments": {
"begin": "(//)",
"end": "($)",
"name": "comment.line",
"beginCaptures": {
"1": {
"name": "comment.line.double-dash"
}
}
},
"type-def": {
"begin": "\\b(type)\\s+([a-zA-Z_][a-zA-Z_\\d]*)",
"end": "$",
"beginCaptures": {
"1": {
"name": "keyword.control.type.midas"
},
"2": {
"name" : "variable.name"
}
},
"patterns": [ "patterns": [
{ "include": "#type-base" }, {
{ "include": "#type-body" } "begin": "//",
"beginCaptures": {
"0": {
"name": "punctuation.definition.comment.midas"
}
},
"end": "$",
"name": "comment.line.double-slash.midas"
},
{
"begin": "/\\*",
"beginCaptures": {
"0": {
"name": "punctuation.definition.comment.midas"
}
},
"end": "\\*/",
"endCaptures": {
"0": {
"name": "punctuation.definition.comment.midas"
}
},
"name": "comment.block.midas"
}
] ]
}, },
"type-base": { "string": {
"begin": "(\\()([a-zA-Z_][a-zA-Z_\\d]*)(\\))", "begin": "\"",
"end": "$",
"beginCaptures": {
"1": {
"name": "punctuation.definition.base.begin.midas"
},
"2": {
"name": "variable.name"
},
"3": {
"name": "punctuation.definition.base.end.midas"
}
},
"patterns": [
{ "include": "#type-cond" }
]
},
"type-cond": {
"begin": "where",
"end": "$",
"beginCaptures": { "beginCaptures": {
"0": { "0": {
"name": "keyword.control.where.midas" "name": "punctuation.definition.string.begin.midas"
} }
} },
"end": "\"",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.end.midas"
}
},
"name": "string.quoted.double.c"
}, },
"type-body": { "alias-stmt": {
"begin": "\\b(alias)\\b",
"beginCaptures": {
"1": {
"name": "keyword.declaration.midas"
}
},
"end": "$",
"name": "meta.declaration.alias.midas",
"patterns": [
{
"include": "#comments"
},
{
"match": "[A-Za-z_][A-Za-z0-9_]*",
"name": "entity.name.type.midas"
},
{
"begin": "=",
"beginCaptures": {
"0": {
"name": "keyword.operator.equal.midas"
}
},
"end": "$",
"patterns": [
{
"include": "#type-expr"
}
]
}
]
},
"type-stmt": {
"begin": "\\b(type)\\b",
"beginCaptures": {
"1": {
"name": "keyword.declaration.midas"
}
},
"end": "$",
"name": "meta.declaration.type.midas",
"patterns": [
{
"include": "#comments"
},
{
"match": "[A-Za-z_][A-Za-z0-9_]*",
"name": "entity.name.type.midas"
},
{
"begin": "\\[",
"beginCaptures": {
"0": {
"name": "punctuation.section.brackets.begin.midas"
}
},
"end": "\\]",
"endCaptures": {
"0": {
"name": "punctuation.section.brackets.end.midas"
}
},
"patterns": [
{
"include": "#comments"
},
{
"include": "#type-params"
}
]
},
{
"begin": "=",
"beginCaptures": {
"0": {
"name": "keyword.operator.equal.midas"
}
},
"end": "$",
"patterns": [
{
"include": "#type-expr"
}
]
}
]
},
"type-params": {
"patterns": [
{
"include": "#comments"
},
{
"match": "<:",
"name": "keyword.operator.subtype.midas"
},
{
"match": "[A-Za-z][A-Za-z0-9_]*",
"name": "entity.name.type.midas"
}
]
},
"extend-stmt": {
"begin": "\\b(extend)\\b",
"beginCaptures": {
"1": {
"name": "keyword.declaration.midas"
}
},
"end": "(?=\\{)|$",
"name": "meta.declaration.extend.midas",
"patterns": [
{
"include": "#comments"
},
{
"match": "[A-Za-z_][A-Za-z0-9_]*",
"name": "entity.name.type.midas"
},
{
"begin": "\\[",
"beginCaptures": {
"0": {
"name": "punctuation.section.brackets.begin.midas"
}
},
"end": "\\]",
"endCaptures": {
"0": {
"name": "punctuation.section.brackets.end.midas"
}
},
"patterns": [
{
"include": "#comments"
},
{
"include": "#type-params"
}
]
}
]
},
"extend-body": {
"begin": "\\{", "begin": "\\{",
"end": "\\}",
"beginCaptures": { "beginCaptures": {
"0": { "0": {
"name": "punctuation.definition.type-body.begin.midas" "name": "punctuation.section.block.begin.midas"
} }
}, },
"end": "\\}",
"endCaptures": { "endCaptures": {
"0": { "0": {
"name": "punctuation.definition.type-body.end.midas" "name": "punctuation.section.block.end.midas"
} }
}, },
"patterns": [ "patterns": [
{"include": "#type-prop"}, {
{"include": "#comment"} "include": "#comments"
},
{
"include": "#member-stmt"
}
] ]
}, },
"type-prop": { "member-stmt": {
"match": "([a-zA-Z_][a-zA-Z_\\d]*)(:)\\s*([a-zA-Z_][a-zA-Z_\\d]*)", "patterns": [
"captures": { {
"1": { "include": "#comments"
"name": "variable.name"
}, },
"2": { {
"name": "punctuation.separator.annotation.midas" "begin": "\\b(prop|def)\\b",
}, "beginCaptures": {
"3": { "1": {
"name": "meta.type.name" "name": "keyword.other.midas"
}
},
"end": "$",
"patterns": [
{
"include": "#comments"
},
{
"match": "[A-Za-z_][A-Za-z0-9_]*",
"name": "variable.other.member.midas"
},
{
"begin": ":",
"beginCaptures": {
"0": {
"name": "punctuation.separator.annotation.midas"
}
},
"end": "$",
"patterns": [
{
"include": "#type-expr"
}
]
}
]
} }
} ]
}, },
"extend-def": { "predicate-stmt": {
"begin": "\\b(extend)\\s*([a-zA-Z_][a-zA-Z_\\d]*)\\s+(\\{)", "begin": "\\b(predicate)\\b",
"end": "\\}",
"beginCaptures": { "beginCaptures": {
"1": { "1": {
"name": "keyword.control.extend.midas" "name": "keyword.declaration.midas"
},
"2": {
"name": "variable.name"
},
"3": {
"name": "punctuation.definition.extend-body.begin.midas"
} }
}, },
"endCaptures": {
"0": {
"name": "punctuation.definition.extend-body.end.midas"
}
},
"patterns": [
{"include": "#op-def"},
{"include": "#comment"}
]
},
"op-def": {
"match": "\\b(op)\\s+(\\S+)\\s*\\(\\s*([a-zA-Z_][a-zA-Z_\\d]*)\\s*\\)\\s*(->)\\s*([a-zA-Z_][a-zA-Z_\\d]*)",
"captures": {
"1": {
"name": "keyword.control.op.midas"
},
"2": {
"name" : "keyword.operator"
},
"3": {
"name" : "variable.name"
},
"4": {
"name" : "keyword.operator.assignment"
},
"5": {
"name" : "variable.name"
}
}
},
"pred-def": {
"begin": "(predicate)\\s+([a-zA-Z_][a-zA-Z_\\d]*)\\(([a-zA-Z_][a-zA-Z_\\d]*):\\s*([a-zA-Z_][a-zA-Z_\\d]*)\\)\\s*(=)",
"end": "$", "end": "$",
"beginCaptures": { "name": "meta.declaration.predicate.midas",
"1": {
"name": "keyword.control.pred.midas"
},
"2": {
"name": "variable.name"
},
"3": {
"name": "variable.name"
},
"4": {
"name": "variable.name"
},
"5": {
"name": "keyword.operator.assignment"
}
},
"patterns": [ "patterns": [
{ "include": "source.python" } {
"include": "#comments"
},
{
"match": "[A-Za-z_][A-Za-z0-9_]*",
"name": "entity.name.function.midas"
},
{
"begin": "\\(",
"beginCaptures": {
"0": {
"name": "punctuation.section.group.begin.midas"
}
},
"end": "\\)",
"endCaptures": {
"0": {
"name": "punctuation.section.group.end.midas"
}
},
"patterns": [
{
"include": "#predicate-params"
}
]
},
{
"begin": "=",
"beginCaptures": {
"0": {
"name": "keyword.operator.equal.midas"
}
},
"end": "$",
"patterns": [
{
"include": "#constraint"
}
]
}
] ]
}, },
"statement": { "predicate-params": {
"patterns": [ "patterns": [
{ "include": "#comment" }, {
{ "include": "#type-def" }, "include": "#comments"
{ "include": "#extend-def" }, },
{ "include": "#pred-def" } {
"begin": "([A-Za-z_][A-Za-z0-9_]*)(:)",
"beginCaptures": {
"1": {
"name": "variable.parameter.midas"
},
"2": {
"name": "punctuation.separator.annotation.midas"
}
},
"end": "(?=,)|(?=\\))",
"patterns": [
{
"include": "#type-expr"
}
]
},
{
"match": ",",
"name": "punctuation.separator.midas"
}
]
},
"type-expr": {
"patterns": [
{
"include": "#comments"
},
{
"begin": "\\b(fn)\\s*(\\()",
"beginCaptures": {
"1": {
"name": "keyword.other.midas"
},
"2": {
"name": "punctuation.section.group.begin.midas"
}
},
"end": "\\)",
"endCaptures": {
"0": {
"name": "punctuation.section.group.end.midas"
}
},
"patterns": [
{
"include": "#fn-params"
}
]
},
{
"match": "->",
"name": "keyword.operator.arrow.midas"
},
{
"begin": "\\b(where)\\b",
"beginCaptures": {
"1": {
"name": "keyword.other.midas"
}
},
"end": "$",
"patterns": [
{
"include": "#constraint"
}
]
},
{
"begin": "(\\bFrame\\b)(\\s*)(\\[)",
"beginCaptures": {
"1": {
"name": "entity.name.type.midas"
},
"3": {
"name": "punctuation.section.brackets.begin.midas"
}
},
"end": "\\]",
"endCaptures": {
"0": {
"name": "punctuation.section.brackets.end.midas"
}
},
"patterns": [
{
"include": "#frame-schema"
}
]
},
{
"match": "\\bFrame\\b",
"name": "entity.name.type.midas"
},
{
"match": "[A-Za-z_][A-Za-z0-9_]*",
"name": "entity.name.type.midas"
},
{
"begin": "\\[",
"beginCaptures": {
"0": {
"name": "punctuation.section.brackets.begin.midas"
}
},
"end": "\\]",
"endCaptures": {
"0": {
"name": "punctuation.section.brackets.end.midas"
}
},
"patterns": [
{
"include": "#comments"
},
{
"include": "#type-expr"
},
{
"match": ",",
"name": "punctuation.separator.midas"
}
]
}
]
},
"fn-params": {
"patterns": [
{
"include": "#comments"
},
{
"begin": "([A-Za-z_][A-Za-z0-9_]*)(:)",
"beginCaptures": {
"1": {
"name": "variable.parameter.midas"
},
"2": {
"name": "punctuation.separator.annotation.midas"
}
},
"end": "(?=,)|(?=\\))",
"patterns": [
{
"include": "#type-expr"
},
{
"match": "\\?",
"name": "keyword.operator.qmark.midas"
}
]
},
{
"match": ",",
"name": "punctuation.separator.midas"
},
{
"include": "#type-expr"
}
]
},
"constraint": {
"patterns": [
{
"include": "#comments"
},
{
"match": "\\d+(\\.\\d+)?",
"name": "constant.numeric.midas"
},
{
"match": "\\b(true|false|none)\\b",
"name": "constant.language.midas"
},
{
"include": "#string"
},
{
"match": "(<=|>=|<|>|==|!=|&)",
"name": "keyword.operator.midas"
},
{
"match": "_",
"name": "variable.language.midas"
},
{
"match": "[A-Za-z_][A-Za-z0-9_]*(?=\\s*\\()",
"name": "variable.function.midas"
},
{
"match": "[A-Za-z_][A-Za-z0-9_]*",
"name": "variable.other.readwrite.midas"
}
]
},
"frame-schema": {
"patterns": [
{
"include": "#comments"
},
{
"match": "[A-Za-z_][A-Za-z0-9_]*",
"name": "variable.other.member.midas"
},
{
"begin": ":",
"beginCaptures": {
"0": {
"name": "punctuation.separator.annotation.midas"
}
},
"end": "(?=,)|(?=\\])",
"patterns": [
{
"include": "#type-expr"
}
]
},
{
"match": ",",
"name": "punctuation.separator.midas"
}
] ]
} }
} }