grammar.ebnf: Sync changes with AST

This commit is contained in:
John 2024-02-26 16:02:36 -06:00
parent 9bde97942c
commit 66deb41301

View File

@ -8,11 +8,10 @@ Visibility = "pub"? ;
File = Item* EOI ; File = Item* EOI ;
Item = Visibility ( Item = Visibility ItemKind ;
Const | Static | Module ItemKind = Const | Static | Module
| Function | Struct | Enum | Function | Struct | Enum
| Impl | Impl ;
) ;
(* item *) (* item *)
@ -21,28 +20,28 @@ Const = "const" Identifier ':' Type = Expr ';' ;
Static = "static" Mutability Identifier ':' Type = Expr ';' ; Static = "static" Mutability Identifier ':' Type = Expr ';' ;
Module = "mod" Identifier '{' (Item)* '}' ; Module = "mod" Identifier '{' (Item)* '}' ;
ModuleKind = (Item+)? ;
Function = "fn" Identifier '(' (Param ',')* Param? ')' ( '->' Type) Block ; Function = "fn" Identifier '(' (Param ',')* Param? ')' ('->' Type)? Block? ;
Param = Identifier ':' Type ; Param = Mutability Identifier ':' Type ;
Struct = "struct" Identifier (TupleStruct | StructStruct)?; Struct = "struct" Identifier (StructTuple | StructBody)?;
StructStruct= '{' (Identifier ':' Type),* '}' ; StructBody = '{' (StructMember ',')* StructMember? '}' ;
TupleStruct = TyTuple ; StructTuple = TyTuple ;
StructMember = Visibility Identifier ':' Type ;
Enum = "enum" Identifier (TupleEnum | StructEnum)? ; Enum = "enum" Identifier '{' (Variant ',')* Variant? '}' ;
TupleEnum = TyTuple; Variant = Identifier (VarStruct | VarTuple | VarCLike)? ;
StructEnum = '{' (Identifier ':' Type)* '}' ; VarStruct = '{' (StructMember ',')* StructMember? '}' ;
VarTuple = TyTuple ;
VarCLike = '=' INTEGER ;
Impl = "impl" Path '{' Item* '}' ;
(* statement *) (* TODO: Impl Trait for Target*)
Stmt = ';' | (Let | Item | Expr ';'?) ;
Let = "let" Mutability Identifier (':' Ty)? ('=' Expr)? ;
(* TODO: Closure syntax *)
Closure = "cl" '(' Param* ')' Block ;
(* type *) (* type *)
Ty = Never | Empty | TyTuple | Path | TyRef | TyFn ; Ty = Never | Empty | Path | TyTuple | TyRef | TyFn ;
Never = '!' ; Never = '!' ;
Empty = '(' ')' ; Empty = '(' ')' ;
TyTuple = '(' (Ty ',')* Ty? ')' ; TyTuple = '(' (Ty ',')* Ty? ')' ;
@ -56,6 +55,14 @@ PathPart = "super" | "self" | Identifier ;
Identifier = IDENTIFIER ; Identifier = IDENTIFIER ;
(* statement *)
Stmt = ';' | (Let | Item | Expr) Semi ;
Semi = ';'? ;
Let = "let" Mutability Identifier (':' Ty)? ('=' Expr)? ;
(* TODO: Closure syntax *)
(* Closure = "cl" '(' Param* ')' Block ; *)
(* literal *) (* literal *)
Bool = "true" | "false" ; Bool = "true" | "false" ;
@ -69,7 +76,7 @@ ExprKind = Assign | Compare | Range | Logic | Bitwise | Shift
Expr = Assign ; Expr = Assign ;
Assign = Path (AssignOp Assign ) | Compare ; Assign = Path (AssignKind Assign ) | Compare ;
Binary = Compare | Range | Logic | Bitwise | Shift | Factor | Term ; Binary = Compare | Range | Logic | Bitwise | Shift | Factor | Term ;
Compare = Range (CompareOp Range )* ; Compare = Range (CompareOp Range )* ;
@ -80,7 +87,7 @@ Shift = Factor (ShiftOp Factor )* ;
Factor = Term (FactorOp Term )* ; Factor = Term (FactorOp Term )* ;
Term = Unary (FactorOp Unary )* ; Term = Unary (FactorOp Unary )* ;
Unary = (UnaryOp)* Member ; Unary = (UnaryKind)* Member ;
Member = Call ('.' Call)* ; Member = Call ('.' Call)* ;
@ -98,7 +105,7 @@ Literal = STRING | CHARACTER | FLOAT | INTEGER | Bool ;
Array = '[' (Expr ',')* Expr? ']' ; Array = '[' (Expr ',')* Expr? ']' ;
ArrayRep = '[' Expr ';' Expr ']' ; ArrayRep = '[' Expr ';' Expr ']' ;
AddrOf = ('&' | '&&')* Expr ; AddrOf = ('&' | '&&')* Mutability? Expr ;
Block = '{' Stmt* '}'; Block = '{' Stmt* '}';
@ -106,10 +113,10 @@ Group = '(' (Empty | Expr | Tuple) ')' ;
Tuple = (Expr ',')* Expr? ; Tuple = (Expr ',')* Expr? ;
Empty = ; Empty = ;
While = "while" Expr Block Else? ; While = "while" Expr Block Else ;
If = "if" Expr Block Else? ; If = "if" Expr Block Else ;
For = "for" Identifier "in" Expr Block Else? ; For = "for" Identifier "in" Expr Block Else ;
Else = "else" Expr ; Else = ("else" Expr)? ;
Break = "break" Expr ; Break = "break" Expr ;
Return = "return" Expr ; Return = "return" Expr ;
Continue = "continue" ; Continue = "continue" ;
@ -127,4 +134,4 @@ ShiftOp = '<<' | '>>';
TermOp = '+' | '-' ; TermOp = '+' | '-' ;
FactorOp = '*' | '/' | '%' ; FactorOp = '*' | '/' | '%' ;
UnaryKind = '*' | '-' | '!' | '@' | '#' | '~' ; UnaryKind = '*' | '-' | '!' | '@' | '~' ;