3333 nullcoal @right,
3434 ternary @right,
3535 params,
36+ anonMethod,
37+ topLevelLocalFunc,
3638 arrow @right,
3739 assign @right,
3840 throw @left,
198200 | pp_conditional
199201 | pp_line
200202 | pp_diagnostic
203+ | pp_ignored
201204 | pp_region
205+ | pp_shebang
202206 | pp_pragma
203207 | pp_load
204208 | pp_nullable
223227 | 'warning' (whitespace+ ![\n]+)?
224228 }
225229
230+ pp_ignored {
231+ ':' ![\n]+
232+ }
226233
227234 pp_region {
228235 'region' (whitespace+ ![\n]+)?
229236 | 'endregion' (whitespace+ ![\n]+)?
230237 }
231238
239+ pp_shebang {
240+ '!' ![\n]*
241+ }
242+
232243 pp_line { 'line' whitespace+ ![\n]+ }
233244
234245 pp_pragma { 'pragma' (whitespace+ ![\n]+)? }
@@ -303,7 +314,7 @@ namespaceOrTypeName {
303314
304315
305316type {
306- (typeName | SimpleType | tupleType) (!typeUnary2 ~elementAccess rankSpecifier+ nullOrPtr? | nullOrPtr)
317+ (typeName | SimpleType | tupleType) (!typeUnary2 ~elementAccess rankSpecifier+ nullOrPtr? | nullOrPtr)?
307318}
308319
309320nonArrayType {
@@ -312,8 +323,7 @@ nonArrayType {
312323
313324nullOrPtr {
314325 !typeUnary '*'+
315- |
316- !typeUnary '?'
326+ | !typeUnary '?'
317327}
318328
319329arrayType { nonArrayType !typeUnary2 rankSpecifier+ }
@@ -721,7 +731,7 @@ LambdaExpr[@dynamicPrecedence=1] {
721731}
722732
723733anonMethodExpr {
724- kw<"async">? kw<"delegate"> explicitAnonFuncSignature? block
734+ kw<"async">? !anonMethod kw<"delegate"> explicitAnonFuncSignature? block
725735}
726736
727737anonFuncSignature {
@@ -913,6 +923,12 @@ stmt {
913923 | embeddedStmt
914924}
915925
926+ topLevelStmt {
927+ topLevelLabeledStmt
928+ | topLevelDeclStmt
929+ | embeddedStmt
930+ }
931+
916932embeddedStmt {
917933 block
918934 | emptyStmt
@@ -950,6 +966,8 @@ emptyStmt { ';' }
950966
951967labeledStmt { identifier ':' stmt }
952968
969+ topLevelLabeledStmt { identifier ':' topLevelStmt }
970+
953971
954972// Declaration statement
955973
@@ -959,6 +977,12 @@ declStmt {
959977 | LocalFuncDecl
960978}
961979
980+ topLevelDeclStmt {
981+ TopLevelVarDecl
982+ | LocalConstDecl
983+ | TopLevelLocalFuncDecl
984+ }
985+
962986
963987// Local variable declaration
964988
@@ -972,6 +996,12 @@ LocalVarDecl {
972996 | type !varDecl csep1<varDeclarator>
973997}
974998
999+ TopLevelVarDecl {
1000+ kw<"var"> varDesignation !assign '=' expr
1001+ | kw<"var"> csep1<varDeclarator>
1002+ | type !varDecl csep1<varDeclarator>
1003+ }
1004+
9751005varRefModifier {
9761006 scoped refReadonly?
9771007 | refReadonly
@@ -1023,6 +1053,33 @@ localFuncBody {
10231053 | '=>' ref? expr ';'
10241054}
10251055
1056+ TopLevelLocalFuncDecl { attrs? topLevelLocalFuncHeader localFuncBody }
1057+
1058+ topLevelLocalFuncHeader {
1059+ topLevelLocalFuncModifiers?
1060+ (ref ~ref)? type MethodName
1061+ (!typeParams typeParamList)? !params formalParams
1062+ typeParamConstraintsClause*
1063+ }
1064+
1065+ topLevelLocalFuncModifiers {
1066+ topLevelLocalFuncModifierHead topLevelLocalFuncModifier*
1067+ }
1068+
1069+ topLevelLocalFuncModifierHead {
1070+ kw<"async"> !topLevelLocalFunc
1071+ | kw<"unsafe"> !topLevelLocalFunc
1072+ | kw<"static"> !topLevelLocalFunc
1073+ | kw<"extern"> !topLevelLocalFunc
1074+ }
1075+
1076+ topLevelLocalFuncModifier {
1077+ kw<"async">
1078+ | kw<"unsafe">
1079+ | kw<"static">
1080+ | kw<"extern">
1081+ }
1082+
10261083
10271084// Expression statement
10281085
@@ -1211,7 +1268,7 @@ fixedPtrDeclarator { identifier '=' expr }
12111268// Compilation unit
12121269
12131270compilationUnit {
1214- externAliasDirective* usingDirective* /* globalAttrs?*/ block * namespaceMemberDecl*
1271+ externAliasDirective* usingDirective* globalAttrs? topLevelStmt * namespaceMemberDecl*
12151272}
12161273
12171274
@@ -1761,15 +1818,15 @@ fixedSizeBufferDeclarator { identifier delim<'[' expr ']'> }
17611818
17621819// Attributes
17631820
1764- /* globalAttrs { globalAttrSection+ }
1821+ globalAttrs { globalAttrSection+ }
17651822
17661823globalAttrSection {
1767- '[' globalAttrTargetSpecifier csep1<attr> ','? ']'
1824+ delim< '[' globalAttrTargetSpecifier csep1<attr> ','? ']'>
17681825}
17691826
17701827globalAttrTargetSpecifier { globalAttrTarget ':' }
17711828
1772- globalAttrTarget { identifier }*/
1829+ globalAttrTarget { kw<"assembly"> | kw<"module"> }
17731830
17741831attrs { attrSection+ }
17751832
0 commit comments