fix(parser): complete EBNF and railroad diagrams
This commit is contained in:
@@ -1,34 +1,35 @@
|
|||||||
// W3C EBNF syntax definition for Midas
|
// W3C EBNF syntax definition for Midas
|
||||||
Identifier ::= [a-zA-Z] [a-zA-Z_]*
|
Identifier ::= [a-zA-Z_] [a-zA-Z_0-9]*
|
||||||
OpIdentifier ::= Identifier | "__" Identifier "__"
|
|
||||||
|
|
||||||
Integer ::= '\d+'
|
Integer ::= '\d+'
|
||||||
Number ::= "-"? Integer ("." Integer)?
|
Number ::= "-"? Integer ("." Integer)?
|
||||||
Boolean ::= "False" | "True"
|
Boolean ::= "False" | "True"
|
||||||
None ::= "None"
|
None ::= "None"
|
||||||
|
|
||||||
Variable ::= Identifier ("." Identifier)*
|
|
||||||
Value ::= Number | Boolean | None
|
Value ::= Number | Boolean | None
|
||||||
LambdaValue ::= "_" | Value | Variable
|
|
||||||
LambdaOperator ::= ">" | "<" | ">=" | "<=" | "==" | "!="
|
ComparisonOp ::= ">" | "<" | ">=" | "<="
|
||||||
Lambda ::= LambdaValue (LambdaOperator LambdaValue)+
|
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 "?"?
|
SimpleType ::= Identifier "?"?
|
||||||
Template ::= "[" SimpleType "]"
|
Template ::= "[" Type "]"
|
||||||
Type ::= Identifier Template? "?"?
|
Type ::= Identifier Template? "?"?
|
||||||
Constraint ::= Identifier | Lambda
|
|
||||||
|
|
||||||
SimpleTypeBase ::= "(" Type ")"
|
|
||||||
WrappedConstraint ::= Constraint | "(" Constraint ")"
|
|
||||||
Constraints ::= WrappedConstraint ("&" WrappedConstraint)*
|
|
||||||
|
|
||||||
TypeProperty ::= Identifier ":" Type ("where" Constraints)?
|
TypeProperty ::= Identifier ":" Type ("where" Constraints)?
|
||||||
ComplexTypeBody ::= "{" TypeProperty* "}"
|
ComplexTypeBody ::= "{" TypeProperty* "}"
|
||||||
OpDefinition ::= "op" OpIdentifier "(" Type ")" "->" Type
|
OpDefinition ::= "op" Identifier "(" Type ")" "->" Type
|
||||||
ExtendBody ::= "{" OpDefinition* "}"
|
ExtendBody ::= "{" OpDefinition* "}"
|
||||||
|
|
||||||
TypeStatement ::= "type" Identifier Template? (SimpleTypeBase ("where" Constraints)? | ComplexTypeBody)
|
TypeStatement ::= "type" Identifier Template? ("(" Type ")" ("where" Constraint)? | ComplexTypeBody)
|
||||||
ExtendStatement ::= "extend" Type ExtendBody
|
ExtendStatement ::= "extend" Type ExtendBody
|
||||||
PredicateStatement ::= "predicate" Identifier "(" Identifier ":" Type ")" "=" Constraints
|
PredicateStatement ::= "predicate" Identifier "(" Identifier ":" Type ")" "=" Constraint
|
||||||
|
|
||||||
Statement ::= TypeStatement | ExtendStatement | PredicateStatement
|
Statement ::= TypeStatement | ExtendStatement | PredicateStatement
|
||||||
|
|||||||
@@ -7,10 +7,6 @@ svg.railroad .terminal rect {
|
|||||||
```
|
```
|
||||||
#let css = default-css() + bytes(extra-css.text)
|
#let css = default-css() + bytes(extra-css.text)
|
||||||
|
|
||||||
#let variable = ```
|
|
||||||
{[`variable` 'identifier'*"."]}
|
|
||||||
```
|
|
||||||
|
|
||||||
#let value = ```
|
#let value = ```
|
||||||
{[`value` <
|
{[`value` <
|
||||||
[`number` 'digit' * ! <!, ["." 'digit' * !]>],
|
[`number` 'digit' * ! <!, ["." 'digit' * !]>],
|
||||||
@@ -19,16 +15,32 @@ svg.railroad .terminal rect {
|
|||||||
>]}
|
>]}
|
||||||
```
|
```
|
||||||
|
|
||||||
#let lambda-value = ```
|
#let grouping = ```
|
||||||
{[`lambda-value` <"_", 'value', 'variable'>]}
|
{[`grouping` "(" 'constraint' ")"]}
|
||||||
```
|
```
|
||||||
|
|
||||||
#let lambda-operator = ```
|
#let primary = ```
|
||||||
{[`lambda-operator` <">", "<", ">=", "<=", "==", "!=">]}
|
{[`primary` <"_", 'value', 'identifier', 'grouping'>]}
|
||||||
```
|
```
|
||||||
|
|
||||||
#let lambda = ```
|
#let reference = ```
|
||||||
{[`lambda` 'lambda-value' ['lambda-operator' 'lambda-value']*!]}
|
{[`reference` 'primary' <!, ["." 'identifier']*!>]}
|
||||||
|
```
|
||||||
|
|
||||||
|
#let unary = ```
|
||||||
|
{[`unary` <[<!, "-"> 'unary'], 'reference'>]}
|
||||||
|
```
|
||||||
|
|
||||||
|
#let comparison = ```
|
||||||
|
{[`comparison` 'unary'*<">", "<", ">=", "<=">]}
|
||||||
|
```
|
||||||
|
|
||||||
|
#let equality = ```
|
||||||
|
{[`equality` 'comparison'*<"==", "!=">]}
|
||||||
|
```
|
||||||
|
|
||||||
|
#let constraint = ```
|
||||||
|
{[`constraint` 'equality'*"&"]}
|
||||||
```
|
```
|
||||||
|
|
||||||
#let simple-type = ```
|
#let simple-type = ```
|
||||||
@@ -36,27 +48,15 @@ svg.railroad .terminal rect {
|
|||||||
```
|
```
|
||||||
|
|
||||||
#let template = ```
|
#let template = ```
|
||||||
{[`template` "[" 'simple-type' "]"]}
|
{[`template` "[" 'type' "]"]}
|
||||||
```
|
```
|
||||||
|
|
||||||
#let type = ```
|
#let type = ```
|
||||||
{[`type` 'identifier' <!, 'template'> <!, "?">]}
|
{[`type` 'identifier' <!, 'template'> <!, "?">]}
|
||||||
```
|
```
|
||||||
|
|
||||||
#let constraint = ```
|
|
||||||
{[`constraint` <'identifier', 'lambda'>]}
|
|
||||||
```
|
|
||||||
|
|
||||||
#let wrapped-constraint = ```
|
|
||||||
{[`wrapped-constraint` <'constraint', ["(" 'constraint' ")"]>]}
|
|
||||||
```
|
|
||||||
|
|
||||||
#let constraints = ```
|
|
||||||
{[`constraints` 'wrapped-constraint'*"&"]}
|
|
||||||
```
|
|
||||||
|
|
||||||
#let type-property = ```
|
#let type-property = ```
|
||||||
{[`type-property` 'identifier' ":" 'type' <!, ["where" 'constraints']>]}
|
{[`type-property` 'identifier' ":" 'type' <!, ["where" 'constraint']>]}
|
||||||
```
|
```
|
||||||
|
|
||||||
#let type-body = ```
|
#let type-body = ```
|
||||||
@@ -64,11 +64,11 @@ svg.railroad .terminal rect {
|
|||||||
```
|
```
|
||||||
|
|
||||||
#let type-statement = ```
|
#let type-statement = ```
|
||||||
{[`type-statement` "type" 'identifier' <!, 'template'> <[["(" 'type' ")"] <!, ["where" 'constraints']>], 'type-body'>]}
|
{[`type-statement` "type" 'identifier' <!, 'template'> <[["(" 'type' ")"] <!, ["where" 'constraint']>], 'type-body'>]}
|
||||||
```
|
```
|
||||||
|
|
||||||
#let op-definition = ```
|
#let op-definition = ```
|
||||||
{[`op-definition` "op" <'identifier', ["__" 'identifier' "__"]> "(" 'type' ")" "->" 'type']}
|
{[`op-definition` "op" 'identifier' "(" 'type' ")" "->" 'type']}
|
||||||
```
|
```
|
||||||
|
|
||||||
#let extend-statement = ```
|
#let extend-statement = ```
|
||||||
@@ -76,7 +76,7 @@ svg.railroad .terminal rect {
|
|||||||
```
|
```
|
||||||
|
|
||||||
#let predicate-statement = ```
|
#let predicate-statement = ```
|
||||||
{[`predicate-statement` "predicate" 'identifier' "(" 'identifier' ":" 'type' ")" "=" 'constraints']}
|
{[`predicate-statement` "predicate" 'identifier' "(" 'identifier' ":" 'type' ")" "=" 'constraint']}
|
||||||
```
|
```
|
||||||
|
|
||||||
#let statement = ```
|
#let statement = ```
|
||||||
@@ -84,17 +84,17 @@ svg.railroad .terminal rect {
|
|||||||
```
|
```
|
||||||
|
|
||||||
#let rules = (
|
#let rules = (
|
||||||
variable: variable,
|
|
||||||
value: value,
|
value: value,
|
||||||
lambda-value: lambda-value,
|
grouping: grouping,
|
||||||
lambda-operator: lambda-operator,
|
primary: primary,
|
||||||
lambda: lambda,
|
reference: reference,
|
||||||
|
unary: unary,
|
||||||
|
comparison: comparison,
|
||||||
|
equality: equality,
|
||||||
|
constraint: constraint,
|
||||||
simple-type: simple-type,
|
simple-type: simple-type,
|
||||||
template: template,
|
template: template,
|
||||||
type: type,
|
type: type,
|
||||||
constraint: constraint,
|
|
||||||
wrapped-constraint: wrapped-constraint,
|
|
||||||
constraints: constraints,
|
|
||||||
type-property: type-property,
|
type-property: type-property,
|
||||||
type-body: type-body,
|
type-body: type-body,
|
||||||
type-statement: type-statement,
|
type-statement: type-statement,
|
||||||
@@ -105,13 +105,10 @@ svg.railroad .terminal rect {
|
|||||||
)
|
)
|
||||||
|
|
||||||
#let inline = (
|
#let inline = (
|
||||||
|
"grouping",
|
||||||
"value",
|
"value",
|
||||||
"variable",
|
|
||||||
"lambda-operator",
|
|
||||||
"template",
|
"template",
|
||||||
"lambda",
|
|
||||||
"simple-type",
|
"simple-type",
|
||||||
"wrapped-constraint",
|
|
||||||
"type-property",
|
"type-property",
|
||||||
"type-body",
|
"type-body",
|
||||||
"op-definition",
|
"op-definition",
|
||||||
@@ -131,7 +128,7 @@ svg.railroad .terminal rect {
|
|||||||
2,
|
2,
|
||||||
outline(title: none),
|
outline(title: none),
|
||||||
),
|
),
|
||||||
height: 8cm,
|
height: 9cm,
|
||||||
stroke: 1pt,
|
stroke: 1pt,
|
||||||
inset: 1em,
|
inset: 1em,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user