diff --git a/midas/parser/midas.py b/midas/parser/midas.py index 146ef54..6678dbc 100644 --- a/midas/parser/midas.py +++ b/midas/parser/midas.py @@ -632,7 +632,7 @@ class MidasParser(Parser[list[Stmt]]): return WildcardExpr(location=token.get_location(), token=token) if self.match(TokenType.LEFT_PAREN): - expr: Expr = self.constraint() + expr: Expr = self.expression() right: Token = self.consume(TokenType.RIGHT_PAREN, "Unclosed parenthesis") return GroupingExpr(location=token.location_to(right), expr=expr) diff --git a/syntax/midas.ebnf b/syntax/midas.ebnf index 4626412..a2bf9de 100644 --- a/syntax/midas.ebnf +++ b/syntax/midas.ebnf @@ -4,40 +4,87 @@ Identifier ::= [a-zA-Z_] [a-zA-Z_0-9]* Integer ::= '\d+' Number ::= "-"? Integer ("." Integer)? Boolean ::= "False" | "True" +String ::= '(".*?")|(\'.*?\')' None ::= "None" -Value ::= Number | Boolean | None +Literal ::= Number | Boolean | String | None +UnaryOp ::= "+" | "-" | "!" +FactorOp ::= "*" | "/" +TermOp ::= "+" | "-" ComparisonOp ::= ">" | "<" | ">=" | "<=" EqualityOp ::= "==" | "!=" -Grouping ::= "(" Constraint ")" -Primary ::= "_" | Value | Identifier | Grouping +PosArg ::= Expression +KwArg ::= Identifier "=" Expression + +PosArgs ::= PosArg ("," PosArg)* +KwArgs ::= KwArg ("," KwArg)* +Args ::= ( + PosArgs + | KwArgs + | PosArgs "," KwArgs +) + +Grouping ::= "(" Expression ")" +Primary ::= "_" | Literal | Identifier | Grouping Reference ::= Primary ("." Identifier)* -Unary ::= "-"? Unary | Reference -Comparison ::= Unary (ComparisonOp Unary)* +CallArgs ::= "(" Args ")" +Call ::= Reference CallArgs* +Unary ::= UnaryOp Unary | Call +Factor ::= Unary (FactorOp Unary)* +Term ::= Factor (TermOp Factor)* +Comparison ::= Term (ComparisonOp Term)* Equality ::= Comparison (EqualityOp Comparison)* -Constraint ::= Equality ("&" Equality)* +Expression ::= Equality ("&" Equality)* +Constraint ::= Expression TemplateParam ::= Identifier ("<:" Type)? 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 ComplexType ::= "{" TypeProperty* "}" NamedType ::= Identifier -TypeParams ::= "[" (Type ("," Type)*)? "]" -GenericType ::= NamedType TypeParams? +TypeArgs ::= "[" (Type ("," Type)*)? "]" +FrameColumn ::= TOKEN ":" Type +FrameSchema ::= "[" (FrameColumn ("," FrameColumn)*)? "]" +GenericType ::= "Frame" FrameSchema | NamedType TypeArgs? GroupedType ::= "(" Type ")" BaseType ::= GroupedType | ComplexType | GenericType ConstraintType ::= BaseType ("where" Constraint)? +FuncType ::= "fn" ParamSpec "->" Type Type ::= ConstraintType -OpDefinition ::= "op" Identifier "(" Type ")" "->" Type -ExtendBody ::= "{" OpDefinition* "}" +MemberStatement ::= ("prop" | "def") Identifier ":" Type +ExtendBody ::= "{" MemberStatement* "}" +AliasStatement ::= "alias" Identifier "=" Type TypeStatement ::= "type" Identifier Template? "=" Type ExtendStatement ::= "extend" Type ExtendBody -PredicateStatement ::= "predicate" Identifier "(" Identifier ":" Type ")" "=" Constraint +PredicateStatement ::= "predicate" Identifier ParamSpec* "=" Constraint -Statement ::= TypeStatement | ExtendStatement | PredicateStatement +Statement ::= AliasStatement | TypeStatement | ExtendStatement | PredicateStatement diff --git a/syntax/midas.typ b/syntax/midas.typ index b05c2a5..736d0a3 100644 --- a/syntax/midas.typ +++ b/syntax/midas.typ @@ -7,20 +7,21 @@ svg.railroad .terminal rect { ``` #let css = default-css() + bytes(extra-css.text) -#let value = ``` -{[`value` < +#let literal = ``` +{[`literal` < [`number` 'digit' * ! ], [`boolean` <"False", "True">], + [`string` <["\"" 'char'*! "\""], ["'" 'char'*! "'"]>], [`none` "None"] >]} ``` #let grouping = ``` -{[`grouping` "(" 'constraint' ")"]} +{[`grouping` "(" 'expression' ")"]} ``` #let primary = ``` -{[`primary` <"_", 'value', 'identifier', 'grouping'>]} +{[`primary` <"_", 'literal', 'identifier', 'grouping'>]} ``` #let reference = ``` @@ -152,7 +153,7 @@ svg.railroad .terminal rect { ``` #let rules = ( - value: value, + literal: literal, grouping: grouping, primary: primary, reference: reference, @@ -190,7 +191,7 @@ svg.railroad .terminal rect { #let inline = ( "grouping", - "value", + "literal", "template-param", "template", "type-property",