From bfcee63e75d6feb21cafbdf3887e0efd508b6b2e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 16:52:08 +0200 Subject: Work on expressions grammar --- xtask/src/codegen/rust.ungram | 330 ++++++++++++++++++++++-------------------- 1 file changed, 173 insertions(+), 157 deletions(-) (limited to 'xtask/src/codegen/rust.ungram') diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram index 17de36d7a..93195befe 100644 --- a/xtask/src/codegen/rust.ungram +++ b/xtask/src/codegen/rust.ungram @@ -115,8 +115,8 @@ Union = RecordFieldList AdtDef = - Struct -| Enum + Enum +| Struct | Union Const = @@ -136,10 +136,10 @@ AssocItemList = '{' Attr* AssocItem* '}' AssocItem = - Fn -| TypeAlias -| Const + Const +| Fn | MacroCall +| TypeAlias Impl = Attr* Visibility? @@ -162,9 +162,9 @@ GenericParamList = '<' (GenericParam (',' GenericParam)* ','?)? '>' GenericParam = - LifetimeParam + ConstParam +| LifetimeParam | TypeParam -| ConstParam TypeParam = Attr* Name (':' TypeBoundList?)? @@ -195,9 +195,9 @@ Attr = '#' '!'? '[' Path ('=' Literal | TokenTree)? ']' Stmt = - LetStmt -| ExprStmt + ExprStmt | Item +| LetStmt LetStmt = Attr* 'let' Pat (':' Type)? @@ -206,189 +206,238 @@ LetStmt = ExprStmt = Attr* Expr ';'? -Type = - ParenType -| TupleType -| NeverType -| PathType -| PointerType -| ArrayType -| SliceType -| ReferenceType -| InferType -| FnPointerType -| ForType -| ImplTraitType -| DynTraitType +Expr = + ArrayExpr +| AwaitExpr +| BinExpr +| BlockExpr +| BoxExpr +| BreakExpr +| CallExpr +| CastExpr +| ContinueExpr +| EffectExpr +| FieldExpr +| ForExpr +| IfExpr +| IndexExpr +| Label +| LambdaExpr +| Literal +| LoopExpr +| MacroCall +| MatchExpr +| MethodCallExpr +| ParenExpr +| PathExpr +| PrefixExpr +| RangeExpr +| RecordExpr +| RefExpr +| ReturnExpr +| TryExpr +| TupleExpr +| WhileExpr -ParenType = - '(' Type ')' +Literal = + Attr* 'int_number' -NeverType = - '!' +PathExpr = + Attr* Path -PathType = - Path +BlockExpr = + '{' + Attr* + statements:Stmt* + Expr? + '}' -TupleType = - '(' fields:(Type (',' Type)* ','?)? ')' +RefExpr = + Attr* '&' ('raw' |'mut' | 'const') Expr -PointerType = - '*' ('const' | 'mut') Type +TryExpr = + Attr* Expr '?' -ReferenceType = - '&' 'lifetime'? 'mut'? Type +EffectExpr = + Attr* Label? ('try' | 'unsafe' | 'async') BlockExpr -ArrayType = - '[' Type ';' Expr ']' +PrefixExpr = + Attr* op:('-' | '!' | '*') Expr -SliceType = - '[' Type ']' +BinExpr = + Attr* + Expr + op:( + '||' | '&&' + | '==' | '!=' | '<=' | '>=' | '<' | '>' + | '+' | '*' | '-' | '/' | '%' | '<<' | '>>' | '^' | '|' | '&' + | '=' | '+=' | '/=' | '*=' | '%=' | '>>=' | '<<=' | '-=' | '|=' | '&=' | '^=' + ) + Expr -InferType = - '_' +CastExpr = + Attr* Expr 'as' Type -FnPointerType = - 'const'? 'async'? 'unsafe'? Abi? 'fn' ParamList RetType? +ParenExpr = + Attr* '(' Attr* Expr ')' -ForType = - 'for' GenericParamList Type +ArrayExpr = + Attr* '[' Attr* ( + (Expr (',' Expr)* ','?)? + | Expr ';' Expr + ) ']' -ImplTraitType = - 'impl' TypeBoundList +IndexExpr = + Attr* Expr '[' Expr ']' -DynTraitType = - 'dyn' TypeBoundList +TupleExpr = + Attr* '(' Attr* (Expr (',' Expr)* ','?)? ')' -TypeBoundList = - bounds:(TypeBound ('+' TypeBound)* '+'?) +RecordExpr = + Path RecordExprFieldList -TypeBound = - 'lifetime' -| '?'? Type +RecordExprFieldList = + '{' + Attr* + fields:(RecordExprField (',' RecordExprField)* ','?) + ('..' spread:Expr)? + '}' -TupleExpr = - Attr* '(' Expr* ')' +RecordExprField = + Attr* NameRef (':' Expr)? -ArrayExpr = - Attr* '[' (Expr* | Expr ';' Expr) ']' +CallExpr = + Attr* Expr ArgList -ParenExpr = - Attr* '(' Expr ')' +ArgList = + '(' args:(Expr (',' Expr)* ','?)? ')' -PathExpr = - Path +MethodCallExpr = + Attr* Expr '.' NameRef TypeArgList? ArgList + +FieldExpr = + Attr* Expr '.' NameRef LambdaExpr = Attr* 'static'? 'async'? 'move'? ParamList RetType? body:Expr IfExpr = - Attr* 'if' Condition + Attr* 'if' Condition BlockExpr + ('else' (IfExpr | BlockExpr))? Condition = 'let' Pat '=' Expr | Expr -EffectExpr = - Attr* Label? ('try' | 'unsafe' | 'async') BlockExpr - LoopExpr = Attr* Label? 'loop' - loop_body:BlockExpr? + loop_body:BlockExpr ForExpr = Attr* Label? 'for' Pat 'in' iterable:Expr - loop_body:BlockExpr? + loop_body:BlockExpr WhileExpr = Attr* Label? 'while' Condition loop_body:BlockExpr? -ContinueExpr = - Attr* 'continue' 'lifetime'? +Label = + 'lifetime' BreakExpr = Attr* 'break' 'lifetime'? Expr? -Label = - 'lifetime' - -BlockExpr = - Attr* Label - '{' - statements:Stmt* - Expr? - '}' +ContinueExpr = + Attr* 'continue' 'lifetime'? -ReturnExpr = - Attr* 'return' Expr +RangeExpr = + Attr* Expr? op:('..' | '..=') Expr? -CallExpr = - Attr* Expr ArgList +MatchExpr = + Attr* 'match' Expr MatchArmList -MethodCallExpr = - Attr* Expr '.' NameRef TypeArgList? ArgList +MatchArmList = + '{' + Attr* + arms:MatchArm* + '}' -ArgList = - '(' args:Expr* ')' +MatchArm = + Attr* Pat guard:MatchGuard? '=>' Expr ','? -FieldExpr = - Attr* Expr '.' NameRef +MatchGuard = + 'if' Expr -IndexExpr = - Attr* '[' ']' +ReturnExpr = + Attr* 'return' Expr? AwaitExpr = Attr* Expr '.' 'await' -TryExpr = - Attr* Expr '?' +BoxExpr = + Attr* 'box' Expr -CastExpr = - Attr* Expr 'as' Type +Type = + ArrayType +| DynTraitType +| FnPointerType +| ForType +| ImplTraitType +| InferType +| NeverType +| ParenType +| PathType +| PointerType +| ReferenceType +| SliceType +| TupleType -RefExpr = - Attr* '&' ('raw' | 'mut' | 'const') Expr +ParenType = + '(' Type ')' -PrefixExpr = - Attr* Expr +NeverType = + '!' -BoxExpr = - Attr* 'box' Expr +PathType = + Path -RangeExpr = - Attr* +TupleType = + '(' fields:(Type (',' Type)* ','?)? ')' -BinExpr = - Attr* +PointerType = + '*' ('const' | 'mut') Type -Literal = - 'int_number' +ReferenceType = + '&' 'lifetime'? 'mut'? Type -MatchExpr = - Attr* 'match' Expr MatchArmList +ArrayType = + '[' Type ';' Expr ']' -MatchArmList = - '{' arms:MatchArm* '}' +SliceType = + '[' Type ']' -MatchArm = - Attr* Pat guard:MatchGuard? '=>' Expr +InferType = + '_' -MatchGuard = - 'if' Expr +FnPointerType = + 'const'? 'async'? 'unsafe'? Abi? 'fn' ParamList RetType? -RecordExpr = - Path RecordExprFieldList +ForType = + 'for' GenericParamList Type -RecordExprFieldList = - '{' - fields:RecordExprField* - ('..' spread:Expr)? - '}' +ImplTraitType = + 'impl' TypeBoundList -RecordExprField = - Attr* NameRef (':' Expr)? +DynTraitType = + 'dyn' TypeBoundList + +TypeBoundList = + bounds:(TypeBound ('+' TypeBound)* '+'?) + +TypeBound = + 'lifetime' +| '?'? Type OrPat = Pat* @@ -510,36 +559,3 @@ Pat = | RangePat | LiteralPat | MacroPat - -Expr = - TupleExpr -| ArrayExpr -| ParenExpr -| PathExpr -| LambdaExpr -| IfExpr -| LoopExpr -| ForExpr -| WhileExpr -| ContinueExpr -| BreakExpr -| Label -| BlockExpr -| ReturnExpr -| MatchExpr -| RecordExpr -| CallExpr -| IndexExpr -| MethodCallExpr -| FieldExpr -| AwaitExpr -| TryExpr -| EffectExpr -| CastExpr -| RefExpr -| PrefixExpr -| RangeExpr -| BinExpr -| Literal -| MacroCall -| BoxExpr -- cgit v1.2.3 From 633aace41108b74fe6c93c5ab04272067db033f9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 17:08:58 +0200 Subject: Rename LambdaExpr -> ClosureExpr --- xtask/src/codegen/rust.ungram | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'xtask/src/codegen/rust.ungram') diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram index 93195befe..aef07cb1e 100644 --- a/xtask/src/codegen/rust.ungram +++ b/xtask/src/codegen/rust.ungram @@ -222,7 +222,7 @@ Expr = | IfExpr | IndexExpr | Label -| LambdaExpr +| ClosureExpr | Literal | LoopExpr | MacroCall @@ -266,14 +266,14 @@ PrefixExpr = BinExpr = Attr* - Expr + lhs:Expr op:( '||' | '&&' | '==' | '!=' | '<=' | '>=' | '<' | '>' | '+' | '*' | '-' | '/' | '%' | '<<' | '>>' | '^' | '|' | '&' | '=' | '+=' | '/=' | '*=' | '%=' | '>>=' | '<<=' | '-=' | '|=' | '&=' | '^=' ) - Expr + rhs:Expr CastExpr = Attr* Expr 'as' Type @@ -288,7 +288,7 @@ ArrayExpr = ) ']' IndexExpr = - Attr* Expr '[' Expr ']' + Attr* base:Expr '[' index:Expr ']' TupleExpr = Attr* '(' Attr* (Expr (',' Expr)* ','?)? ')' @@ -318,13 +318,13 @@ MethodCallExpr = FieldExpr = Attr* Expr '.' NameRef -LambdaExpr = +ClosureExpr = Attr* 'static'? 'async'? 'move'? ParamList RetType? body:Expr IfExpr = - Attr* 'if' Condition BlockExpr - ('else' (IfExpr | BlockExpr))? + Attr* 'if' Condition then_branch:BlockExpr + ('else' else_branch:(IfExpr | BlockExpr))? Condition = 'let' Pat '=' Expr @@ -352,7 +352,7 @@ ContinueExpr = Attr* 'continue' 'lifetime'? RangeExpr = - Attr* Expr? op:('..' | '..=') Expr? + Attr* start:Expr? op:('..' | '..=') end:Expr? MatchExpr = Attr* 'match' Expr MatchArmList -- cgit v1.2.3