2929 disable_item ,
3030 error ,
3131 font ,
32+ for_ ,
3233 general ,
3334 grf ,
3435 item ,
4748)
4849
4950
51+
5052class NMLParser :
5153 """
5254 @ivar lexer: Scanner providing tokens.
@@ -145,7 +147,8 @@ def p_main_block(self, t):
145147 | engine_override
146148 | sort_vehicles
147149 | basecost
148- | constant"""
150+ | constant
151+ | for"""
149152 t [0 ] = t [1 ]
150153
151154 #
@@ -389,7 +392,9 @@ def p_property_assignment(self, t):
389392 """property_assignment : ID COLON expression SEMICOLON
390393 | ID COLON expression UNIT SEMICOLON
391394 | NUMBER COLON expression SEMICOLON
392- | NUMBER COLON expression UNIT SEMICOLON"""
395+ | NUMBER COLON expression UNIT SEMICOLON
396+ | ID COLON for SEMICOLON
397+ | NUMBER COLON for SEMICOLON"""
393398 name = t [1 ]
394399 unit_value = None if len (t ) == 5 else unit .get_unit (t [4 ])
395400 t [0 ] = item .Property (name , t [3 ], unit_value , t .lineno (1 ))
@@ -835,3 +840,11 @@ def p_tilelayout_item_prop(self, t):
835840 def p_constant (self , t ):
836841 "constant : CONST expression EQ expression SEMICOLON"
837842 t [0 ] = constant .Constant (t [2 ], t [4 ])
843+
844+ def p_for (self , t ):
845+ """for : FOR ID LPAREN id_list RPAREN LBRACE layout_sprite_list RBRACE
846+ | LBRACKET non_empty_expression_list FOR ID IN expression RBRACKET"""
847+ if t [1 ] == '[' :
848+ t [0 ] = for_ .For (" " , t [3 ], t [5 ])
849+ else :
850+ t [0 ] = for_ .For (t [2 ], t [4 ], t [7 ])
0 commit comments