File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ def stmt(self) -> Node | None:
108
108
# TODO: switch, case, default, label
109
109
if kind == lx .SEMI :
110
110
return self .empty_stmt ()
111
- if decl := self .declaration ():
111
+ if decl := self .decl_stmt ():
112
112
return decl
113
113
return self .expr_stmt ()
114
114
@@ -126,7 +126,7 @@ def block(self):
126
126
def for_stmt (self ):
127
127
if self .expect (lx .FOR ):
128
128
self .require (lx .LPAREN )
129
- init = self .expr ()
129
+ init = self .decl () or self . expr ()
130
130
self .require (lx .SEMI )
131
131
cond = self .expr ()
132
132
self .require (lx .SEMI )
@@ -180,7 +180,13 @@ def expr_stmt(self):
180
180
return expr
181
181
182
182
@contextual
183
- def declaration (self ):
183
+ def decl_stmt (self ):
184
+ if decl := self .decl ():
185
+ if self .expect (lx .SEMI ):
186
+ return decl
187
+
188
+ @contextual
189
+ def decl (self ):
184
190
if not (type := self .type_name ()):
185
191
return None
186
192
stars = 0
@@ -191,11 +197,8 @@ def declaration(self):
191
197
init = self .expr ()
192
198
if not init :
193
199
raise self .make_syntax_error ("Expected initialization expression" )
194
- self .require (lx .SEMI )
195
200
else :
196
201
init = None
197
- if not (self .expect (lx .SEMI )):
198
- return None
199
202
return VarDecl (type , name , init )
200
203
201
204
You can’t perform that action at this time.
0 commit comments