@@ -177,6 +177,8 @@ pub const Parser = struct {
177
177
FieldInitListItemOrEnd : ListSave (& ast .NodeFieldInitializer ),
178
178
FieldInitListCommaOrEnd : ListSave (& ast .NodeFieldInitializer ),
179
179
FieldListCommaOrEnd : & ast.NodeContainerDecl ,
180
+ IdentifierListItemOrEnd : ListSave (& ast .NodeIdentifier ),
181
+ IdentifierListCommaOrEnd : ListSave (& ast .NodeIdentifier ),
180
182
SwitchCaseOrEnd : ListSave (& ast .NodeSwitchCase ),
181
183
SuspendBody : & ast.NodeSuspend ,
182
184
AsyncEnd : AsyncEndCtx ,
@@ -1683,11 +1685,8 @@ pub const Parser = struct {
1683
1685
1684
1686
},
1685
1687
Token .Id .Keyword_error = > {
1686
- const next = self .getNextToken ();
1687
-
1688
- if (next .id != Token .Id .LBrace ) {
1688
+ if (self .eatToken (Token .Id .LBrace ) == null ) {
1689
1689
dest_ptr .store (&(try self .createLiteral (arena , ast .NodeErrorType , token )).base );
1690
- self .putBackToken (next );
1691
1690
continue ;
1692
1691
}
1693
1692
@@ -1700,43 +1699,12 @@ pub const Parser = struct {
1700
1699
}
1701
1700
);
1702
1701
1703
- while (true ) {
1704
- const t = self .getNextToken ();
1705
- switch (t .id ) {
1706
- Token .Id .RBrace = > {
1707
- node .rbrace_token = t ;
1708
- break ;
1709
- },
1710
- Token .Id .Identifier = > {
1711
- try node .decls .append (
1712
- try self .createLiteral (arena , ast .NodeIdentifier , t )
1713
- );
1714
- },
1715
- else = > {
1716
- try self .parseError (& stack , token , "expected {} or {}, found {}" ,
1717
- @tagName (Token .Id .RBrace ),
1718
- @tagName (Token .Id .Identifier ),
1719
- @tagName (token .id ));
1720
- continue ;
1721
- }
1722
- }
1723
-
1724
- const t2 = self .getNextToken ();
1725
- switch (t2 .id ) {
1726
- Token .Id .RBrace = > {
1727
- node .rbrace_token = t ;
1728
- break ;
1729
- },
1730
- Token .Id .Comma = > continue ,
1731
- else = > {
1732
- try self .parseError (& stack , token , "expected {} or {}, found {}" ,
1733
- @tagName (Token .Id .RBrace ),
1734
- @tagName (Token .Id .Comma ),
1735
- @tagName (token .id ));
1736
- continue ;
1737
- }
1702
+ stack .append (State {
1703
+ .IdentifierListItemOrEnd = ListSave (& ast .NodeIdentifier ) {
1704
+ .list = & node .decls ,
1705
+ .ptr = & node .rbrace_token ,
1738
1706
}
1739
- }
1707
+ }) catch unreachable ;
1740
1708
continue ;
1741
1709
},
1742
1710
Token .Id .Keyword_packed = > {
@@ -2082,6 +2050,24 @@ pub const Parser = struct {
2082
2050
});
2083
2051
},
2084
2052
2053
+ State .IdentifierListItemOrEnd = > | list_state | {
2054
+ if (self .eatToken (Token .Id .RBrace )) | rbrace | {
2055
+ * list_state .ptr = rbrace ;
2056
+ continue ;
2057
+ }
2058
+
2059
+ const node = try self .createLiteral (arena , ast .NodeIdentifier , Token (undefined ));
2060
+ try list_state .list .append (node );
2061
+
2062
+ stack .append (State { .IdentifierListCommaOrEnd = list_state }) catch unreachable ;
2063
+ try stack .append (State {
2064
+ .ExpectTokenSave = ExpectTokenSave {
2065
+ .id = Token .Id .Identifier ,
2066
+ .ptr = & node .token ,
2067
+ }
2068
+ });
2069
+ },
2070
+
2085
2071
State .SwitchCaseOrEnd = > | list_state | {
2086
2072
if (self .eatToken (Token .Id .RBrace )) | rbrace | {
2087
2073
* list_state .ptr = rbrace ;
@@ -2139,6 +2125,11 @@ pub const Parser = struct {
2139
2125
continue ;
2140
2126
},
2141
2127
2128
+ State .IdentifierListCommaOrEnd = > | list_state | {
2129
+ try self .commaOrEnd (& stack , Token .Id .RBrace , list_state .ptr , State { .IdentifierListItemOrEnd = list_state });
2130
+ continue ;
2131
+ },
2132
+
2142
2133
State .SwitchCaseCommaOrEnd = > | list_state | {
2143
2134
try self .commaOrEnd (& stack , Token .Id .RBrace , list_state .ptr , State { .SwitchCaseOrEnd = list_state });
2144
2135
continue ;
0 commit comments