grammar.ebnf: Clean up grammar

- TODO: Member access is totally broken lmao
This commit is contained in:
John 2024-04-06 01:02:31 -05:00
parent a036ce260d
commit a31d285d99

View File

@ -1,38 +1,38 @@
(* Conlang Expression Grammar *) (* Conlang Expression Grammar *)
Start = File ; Start = File EOI ;
Mutability = "mut"? ; Mutability = "mut"? ;
Visibility = "pub"? ; Visibility = "pub"? ;
File = Item* EOI ; File = Item* ;
Attrs = ('#' '[' (Meta ',') Meta? ']')* ; Attrs = ('#' '[' (Meta ',')* Meta? ']')* ;
Meta = Identifier ('=' Literal | '(' (Literal ',')* Literal? ')')? ; Meta = Identifier ('=' Literal | '(' (Literal ',')* Literal? ')')? ;
Item = Attrs* Visibility ItemKind ; Item = Attrs Visibility ItemKind ;
ItemKind = Const | Static | Module ItemKind = Const | Static | Module
| Function | Struct | Enum | Function | Struct | Enum
| Alias | Impl ; | Alias | Impl ;
(* item *) (* item *)
Const = "const" Identifier ':' Type = Expr ';' ; Const = "const" Identifier ':' Ty '=' Expr ';' ;
Static = "static" Mutability Identifier ':' Type = Expr ';' ; Static = "static" Mutability Identifier ':' Ty '=' Expr ';' ;
Module = "mod" Identifier ModuleKind ; Module = "mod" Identifier ModuleKind ;
ModuleKind = '{' Item* '}' | ';' ; ModuleKind = '{' Item* '}' | ';' ;
Function = "fn" Identifier '(' (Param ',')* Param? ')' ('->' Type)? Block? ; Function = "fn" Identifier '(' (Param ',')* Param? ')' ('->' Ty)? Block? ;
Param = Mutability Identifier ':' Type ; Param = Mutability Identifier ':' Ty ;
Struct = "struct" Identifier (StructTuple | StructBody)?; Struct = "struct" Identifier (StructTuple | StructBody)?;
StructBody = '{' (StructMember ',')* StructMember? '}' ; StructBody = '{' (StructMember ',')* StructMember? '}' ;
StructTuple = TyTuple ; StructTuple = TyTuple ;
StructMember = Visibility Identifier ':' Type ; StructMember = Visibility Identifier ':' Ty ;
Enum = "enum" Identifier '{' (Variant ',')* Variant? '}' ; Enum = "enum" Identifier '{' (Variant ',')* Variant? '}' ;
Variant = Identifier (VarStruct | VarTuple | VarCLike)? ; Variant = Identifier (VarStruct | VarTuple | VarCLike)? ;
@ -40,7 +40,7 @@ VarStruct = '{' (StructMember ',')* StructMember? '}' ;
VarTuple = TyTuple ; VarTuple = TyTuple ;
VarCLike = '=' INTEGER ; VarCLike = '=' INTEGER ;
Alias = "type" Ty ('=' Ty)? ';' ; Alias = "type" Identifier ('=' Ty)? ';' ;
Impl = "impl" Path '{' Item* '}' ; Impl = "impl" Path '{' Item* '}' ;
(* TODO: Impl Trait for Target*) (* TODO: Impl Trait for Target*)
@ -52,7 +52,7 @@ Never = '!' ;
Empty = '(' ')' ; Empty = '(' ')' ;
TyTuple = '(' (Ty ',')* Ty? ')' ; TyTuple = '(' (Ty ',')* Ty? ')' ;
TyRef = ('&' | '&&')* Path ; TyRef = ('&' | '&&')* Path ;
TyFn = "fn" TyTuple (-> Ty)? ; TyFn = "fn" TyTuple ('->' Ty)? ;
(* path *) (* path *)
@ -73,12 +73,7 @@ Let = "let" Mutability Identifier (':' Ty)? ('=' Expr)? ;
Bool = "true" | "false" ; Bool = "true" | "false" ;
(* expr *) /* expr */
ExprKind = Assign | Compare | Range | Logic | Bitwise | Shift
| Factor | Term | Unary | Member | Call | Index
| Path | Literal | Array | ArrayRep | AddrOf
| Block | Group
| While | If | For | Break | Return | Continue ;
Expr = Assign ; Expr = Assign ;
@ -91,7 +86,7 @@ Logic = Bitwise (LogicOp Bitwise)* ;
Bitwise = Shift (BitwiseOp Shift )* ; Bitwise = Shift (BitwiseOp Shift )* ;
Shift = Factor (ShiftOp Factor )* ; Shift = Factor (ShiftOp Factor )* ;
Factor = Term (FactorOp Term )* ; Factor = Term (FactorOp Term )* ;
Term = Unary (FactorOp Unary )* ; Term = Unary (TermOp Unary )* ;
Unary = (UnaryKind)* Member ; Unary = (UnaryKind)* Member ;
@ -111,7 +106,7 @@ Literal = STRING | CHARACTER | FLOAT | INTEGER | Bool ;
Array = '[' (Expr ',')* Expr? ']' ; Array = '[' (Expr ',')* Expr? ']' ;
ArrayRep = '[' Expr ';' Expr ']' ; ArrayRep = '[' Expr ';' Expr ']' ;
AddrOf = ('&' | '&&')* Mutability? Expr ; AddrOf = ('&' | '&&')* Mutability Expr ;
Block = '{' Stmt* '}'; Block = '{' Stmt* '}';
@ -127,11 +122,8 @@ Break = "break" Expr ;
Return = "return" Expr ; Return = "return" Expr ;
Continue = "continue" ; Continue = "continue" ;
AssignKind = '=' | '+=' | '-=' | '*=' | '/=' | AssignKind = '=' | '+=' | '-=' | '*=' | '/=' | '&=' | '|=' | '^=' |'<<=' |'>>=' ;
'&=' | '|=' | '^=' |'<<=' |'>>=' ;
BinaryKind = CompareOp | RangeOp | LogicOp | BitwiseOp
| ShiftOp | TermOp | FactorOp ;
CompareOp = '<' | '<=' | '==' | '!=' | '>=' | '>' ; CompareOp = '<' | '<=' | '==' | '!=' | '>=' | '>' ;
RangeOp = '..' | '..=' ; RangeOp = '..' | '..=' ;
LogicOp = '&&' | '||' | '^^' ; LogicOp = '&&' | '||' | '^^' ;