diff --git a/syntax/midas.ebnf b/syntax/midas.ebnf index a227fc7..526e122 100644 --- a/syntax/midas.ebnf +++ b/syntax/midas.ebnf @@ -1,34 +1,35 @@ // W3C EBNF syntax definition for Midas -Identifier ::= [a-zA-Z] [a-zA-Z_]* -OpIdentifier ::= Identifier | "__" Identifier "__" +Identifier ::= [a-zA-Z_] [a-zA-Z_0-9]* Integer ::= '\d+' Number ::= "-"? Integer ("." Integer)? Boolean ::= "False" | "True" None ::= "None" -Variable ::= Identifier ("." Identifier)* Value ::= Number | Boolean | None -LambdaValue ::= "_" | Value | Variable -LambdaOperator ::= ">" | "<" | ">=" | "<=" | "==" | "!=" -Lambda ::= LambdaValue (LambdaOperator LambdaValue)+ + +ComparisonOp ::= ">" | "<" | ">=" | "<=" +EqualityOp ::= "==" | "!=" + +Grouping ::= "(" Constraint ")" +Primary ::= "_" | Value | Identifier | Grouping +Reference ::= Primary ("." Identifier)* +Unary ::= "-"? Unary | Reference +Comparison ::= Unary (ComparisonOp Unary)* +Equality ::= Comparison (EqualityOp Comparison)* +Constraint ::= Equality ("&" Equality)* SimpleType ::= Identifier "?"? -Template ::= "[" SimpleType "]" +Template ::= "[" Type "]" Type ::= Identifier Template? "?"? -Constraint ::= Identifier | Lambda - -SimpleTypeBase ::= "(" Type ")" -WrappedConstraint ::= Constraint | "(" Constraint ")" -Constraints ::= WrappedConstraint ("&" WrappedConstraint)* TypeProperty ::= Identifier ":" Type ("where" Constraints)? ComplexTypeBody ::= "{" TypeProperty* "}" -OpDefinition ::= "op" OpIdentifier "(" Type ")" "->" Type +OpDefinition ::= "op" Identifier "(" Type ")" "->" Type ExtendBody ::= "{" OpDefinition* "}" -TypeStatement ::= "type" Identifier Template? (SimpleTypeBase ("where" Constraints)? | ComplexTypeBody) +TypeStatement ::= "type" Identifier Template? ("(" Type ")" ("where" Constraint)? | ComplexTypeBody) ExtendStatement ::= "extend" Type ExtendBody -PredicateStatement ::= "predicate" Identifier "(" Identifier ":" Type ")" "=" Constraints +PredicateStatement ::= "predicate" Identifier "(" Identifier ":" Type ")" "=" Constraint Statement ::= TypeStatement | ExtendStatement | PredicateStatement diff --git a/syntax/midas.typ b/syntax/midas.typ index 56d2884..3e16f19 100644 --- a/syntax/midas.typ +++ b/syntax/midas.typ @@ -7,10 +7,6 @@ svg.railroad .terminal rect { ``` #let css = default-css() + bytes(extra-css.text) -#let variable = ``` -{[`variable` 'identifier'*"."]} -``` - #let value = ``` {[`value` < [`number` 'digit' * ! ], @@ -19,16 +15,32 @@ svg.railroad .terminal rect { >]} ``` -#let lambda-value = ``` -{[`lambda-value` <"_", 'value', 'variable'>]} +#let grouping = ``` +{[`grouping` "(" 'constraint' ")"]} ``` -#let lambda-operator = ``` -{[`lambda-operator` <">", "<", ">=", "<=", "==", "!=">]} +#let primary = ``` +{[`primary` <"_", 'value', 'identifier', 'grouping'>]} ``` -#let lambda = ``` -{[`lambda` 'lambda-value' ['lambda-operator' 'lambda-value']*!]} +#let reference = ``` +{[`reference` 'primary' ]} +``` + +#let unary = ``` +{[`unary` <[ 'unary'], 'reference'>]} +``` + +#let comparison = ``` +{[`comparison` 'unary'*<">", "<", ">=", "<=">]} +``` + +#let equality = ``` +{[`equality` 'comparison'*<"==", "!=">]} +``` + +#let constraint = ``` +{[`constraint` 'equality'*"&"]} ``` #let simple-type = ``` @@ -36,27 +48,15 @@ svg.railroad .terminal rect { ``` #let template = ``` -{[`template` "[" 'simple-type' "]"]} +{[`template` "[" 'type' "]"]} ``` #let type = ``` {[`type` 'identifier' ]} ``` -#let constraint = ``` -{[`constraint` <'identifier', 'lambda'>]} -``` - -#let wrapped-constraint = ``` -{[`wrapped-constraint` <'constraint', ["(" 'constraint' ")"]>]} -``` - -#let constraints = ``` -{[`constraints` 'wrapped-constraint'*"&"]} -``` - #let type-property = ``` -{[`type-property` 'identifier' ":" 'type' ]} +{[`type-property` 'identifier' ":" 'type' ]} ``` #let type-body = ``` @@ -64,11 +64,11 @@ svg.railroad .terminal rect { ``` #let type-statement = ``` -{[`type-statement` "type" 'identifier' <[["(" 'type' ")"] ], 'type-body'>]} +{[`type-statement` "type" 'identifier' <[["(" 'type' ")"] ], 'type-body'>]} ``` #let op-definition = ``` -{[`op-definition` "op" <'identifier', ["__" 'identifier' "__"]> "(" 'type' ")" "->" 'type']} +{[`op-definition` "op" 'identifier' "(" 'type' ")" "->" 'type']} ``` #let extend-statement = ``` @@ -76,7 +76,7 @@ svg.railroad .terminal rect { ``` #let predicate-statement = ``` -{[`predicate-statement` "predicate" 'identifier' "(" 'identifier' ":" 'type' ")" "=" 'constraints']} +{[`predicate-statement` "predicate" 'identifier' "(" 'identifier' ":" 'type' ")" "=" 'constraint']} ``` #let statement = ``` @@ -84,17 +84,17 @@ svg.railroad .terminal rect { ``` #let rules = ( - variable: variable, value: value, - lambda-value: lambda-value, - lambda-operator: lambda-operator, - lambda: lambda, + grouping: grouping, + primary: primary, + reference: reference, + unary: unary, + comparison: comparison, + equality: equality, + constraint: constraint, simple-type: simple-type, template: template, type: type, - constraint: constraint, - wrapped-constraint: wrapped-constraint, - constraints: constraints, type-property: type-property, type-body: type-body, type-statement: type-statement, @@ -105,13 +105,10 @@ svg.railroad .terminal rect { ) #let inline = ( + "grouping", "value", - "variable", - "lambda-operator", "template", - "lambda", "simple-type", - "wrapped-constraint", "type-property", "type-body", "op-definition", @@ -131,7 +128,7 @@ svg.railroad .terminal rect { 2, outline(title: none), ), - height: 8cm, + height: 9cm, stroke: 1pt, inset: 1em, )