Skip to content

Commit c2092a0

Browse files
authored
Merge pull request #6 from sjinks/issue-3
Support for parentheses in `for` loops
2 parents ec88f07 + cdf64af commit c2092a0

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

parser/parser.php5.lemon

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,30 @@ xx_for_statement(R) ::= FOR IDENTIFIER(K) COMMA IDENTIFIER(V) IN REVERSE xx_comm
12301230
R = xx_ret_for_statement(E, K, V, 1, L, status->scanner_state);
12311231
}
12321232

1233+
xx_for_statement(R) ::= FOR PARENTHESES_OPEN IDENTIFIER(V) IN xx_common_expr(E) PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list(L) BRACKET_CLOSE . {
1234+
R = xx_ret_for_statement(E, NULL, V, 0, L, status->scanner_state);
1235+
}
1236+
1237+
xx_for_statement(R) ::= FOR PARENTHESES_OPEN IDENTIFIER(V) IN xx_common_expr(E) PARENTHESES_CLOSE BRACKET_OPEN BRACKET_CLOSE . {
1238+
R = xx_ret_for_statement(E, NULL, V, 0, NULL, status->scanner_state);
1239+
}
1240+
1241+
xx_for_statement(R) ::= FOR PARENTHESES_OPEN IDENTIFIER(V) IN REVERSE xx_common_expr(E) PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list(L) BRACKET_CLOSE . {
1242+
R = xx_ret_for_statement(E, NULL, V, 1, L, status->scanner_state);
1243+
}
1244+
1245+
xx_for_statement(R) ::= FOR PARENTHESES_OPEN IDENTIFIER(K) COMMA IDENTIFIER(V) IN xx_common_expr(E) PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list(L) BRACKET_CLOSE . {
1246+
R = xx_ret_for_statement(E, K, V, 0, L, status->scanner_state);
1247+
}
1248+
1249+
xx_for_statement(R) ::= FOR PARENTHESES_OPEN IDENTIFIER(K) COMMA IDENTIFIER(V) IN xx_common_expr(E) PARENTHESES_CLOSE BRACKET_OPEN BRACKET_CLOSE . {
1250+
R = xx_ret_for_statement(E, K, V, 0, NULL, status->scanner_state);
1251+
}
1252+
1253+
xx_for_statement(R) ::= FOR PARENTHESES_OPEN IDENTIFIER(K) COMMA IDENTIFIER(V) IN REVERSE xx_common_expr(E) PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list(L) BRACKET_CLOSE . {
1254+
R = xx_ret_for_statement(E, K, V, 1, L, status->scanner_state);
1255+
}
1256+
12331257
xx_let_statement(R) ::= LET xx_let_assignments(A) DOTCOMMA . {
12341258
R = xx_ret_let_statement(A, status->scanner_state);
12351259
}

parser/parser.php7.lemon

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,30 @@ xx_for_statement(R) ::= FOR IDENTIFIER(K) COMMA IDENTIFIER(V) IN REVERSE xx_comm
12531253
xx_ret_for_statement(&R, &E, K, V, 1, &L, status->scanner_state);
12541254
}
12551255

1256+
xx_for_statement(R) ::= FOR PARENTHESES_OPEN IDENTIFIER(V) IN xx_common_expr(E) PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list(L) BRACKET_CLOSE . {
1257+
xx_ret_for_statement(&R, &E, NULL, V, 0, &L, status->scanner_state);
1258+
}
1259+
1260+
xx_for_statement(R) ::= FOR PARENTHESES_OPEN IDENTIFIER(V) IN xx_common_expr(E) PARENTHESES_CLOSE BRACKET_OPEN BRACKET_CLOSE . {
1261+
xx_ret_for_statement(&R, &E, NULL, V, 0, NULL, status->scanner_state);
1262+
}
1263+
1264+
xx_for_statement(R) ::= FOR PARENTHESES_OPEN IDENTIFIER(V) IN REVERSE xx_common_expr(E) PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list(L) BRACKET_CLOSE . {
1265+
xx_ret_for_statement(&R, &E, NULL, V, 1, &L, status->scanner_state);
1266+
}
1267+
1268+
xx_for_statement(R) ::= FOR PARENTHESES_OPEN IDENTIFIER(K) COMMA IDENTIFIER(V) IN xx_common_expr(E) PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list(L) BRACKET_CLOSE . {
1269+
xx_ret_for_statement(&R, &E, K, V, 0, &L, status->scanner_state);
1270+
}
1271+
1272+
xx_for_statement(R) ::= FOR PARENTHESES_OPEN IDENTIFIER(K) COMMA IDENTIFIER(V) IN xx_common_expr(E) PARENTHESES_CLOSE BRACKET_OPEN BRACKET_CLOSE . {
1273+
xx_ret_for_statement(&R, &E, K, V, 0, NULL, status->scanner_state);
1274+
}
1275+
1276+
xx_for_statement(R) ::= FOR PARENTHESES_OPEN IDENTIFIER(K) COMMA IDENTIFIER(V) IN REVERSE xx_common_expr(E) PARENTHESES_CLOSE BRACKET_OPEN xx_statement_list(L) BRACKET_CLOSE . {
1277+
xx_ret_for_statement(&R, &E, K, V, 1, &L, status->scanner_state);
1278+
}
1279+
12561280
xx_let_statement(R) ::= LET xx_let_assignments(A) DOTCOMMA . {
12571281
xx_ret_let_statement(&R, &A, status->scanner_state);
12581282
}

0 commit comments

Comments
 (0)