docs: update Midas EBNF
This commit is contained in:
@@ -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)
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -7,20 +7,21 @@ 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 = ```
|
||||||
@@ -152,7 +153,7 @@ svg.railroad .terminal rect {
|
|||||||
```
|
```
|
||||||
|
|
||||||
#let rules = (
|
#let rules = (
|
||||||
value: value,
|
literal: literal,
|
||||||
grouping: grouping,
|
grouping: grouping,
|
||||||
primary: primary,
|
primary: primary,
|
||||||
reference: reference,
|
reference: reference,
|
||||||
@@ -190,7 +191,7 @@ svg.railroad .terminal rect {
|
|||||||
|
|
||||||
#let inline = (
|
#let inline = (
|
||||||
"grouping",
|
"grouping",
|
||||||
"value",
|
"literal",
|
||||||
"template-param",
|
"template-param",
|
||||||
"template",
|
"template",
|
||||||
"type-property",
|
"type-property",
|
||||||
|
|||||||
Reference in New Issue
Block a user