| author | |
| committer | |
| log | 4339d555626197f4b8c9598b602f098b76488c2d |
| tree | 2773f3dbace6d3603f7fddaddee8f2683b645d37 |
| parent | 4208435f662030abf24929c90a4bb8c7fb0d2908 |
it matches more closely the %% binary operator syntax
See #518 files changed, 26 insertions(+), 20 deletions(-)
doc/langref.md+1-1| ... | ... | @@ -85,7 +85,7 @@ SwitchItem = Expression | (Expression "..." Expression) |
| 85 | 85 | |
| 86 | 86 | WhileExpression = "while" "(" Expression ")" Expression |
| 87 | 87 | |
| 88 | ForExpression = "for" "(" "Symbol" "," Expression option("," "Symbol") ")" Expression | |
| 88 | ForExpression = "for" "(" Expression ")" option("|" "Symbol" option("," "Symbol") "|") Expression | |
| 89 | 89 | |
| 90 | 90 | BoolOrExpression = BoolAndExpression "||" BoolOrExpression | BoolAndExpression |
| 91 | 91 |
src/parser.cpp+14-8| ... | ... | @@ -1797,7 +1797,7 @@ static AstNode *ast_parse_symbol(ParseContext *pc, int *token_index) { |
| 1797 | 1797 | } |
| 1798 | 1798 | |
| 1799 | 1799 | /* |
| 1800 | ForExpression : token(For) token(LParen) Symbol token(Comma) Expression option(token(Comma) token(Symbol)) token(RParen) Expression | |
| 1800 | ForExpression = "for" "(" Expression ")" option("|" "Symbol" option("," "Symbol") "|") Expression | |
| 1801 | 1801 | */ |
| 1802 | 1802 | static AstNode *ast_parse_for_expr(ParseContext *pc, int *token_index, bool mandatory) { |
| 1803 | 1803 | Token *token = &pc->tokens->at(*token_index); |
| ... | ... | @@ -1814,17 +1814,23 @@ static AstNode *ast_parse_for_expr(ParseContext *pc, int *token_index, bool mand |
| 1814 | 1814 | AstNode *node = ast_create_node(pc, NodeTypeForExpr, token); |
| 1815 | 1815 | |
| 1816 | 1816 | ast_eat_token(pc, token_index, TokenIdLParen); |
| 1817 | node->data.for_expr.elem_node = ast_parse_symbol(pc, token_index); | |
| 1818 | ast_eat_token(pc, token_index, TokenIdComma); | |
| 1819 | 1817 | node->data.for_expr.array_expr = ast_parse_expression(pc, token_index, true); |
| 1818 | ast_eat_token(pc, token_index, TokenIdRParen); | |
| 1820 | 1819 | |
| 1821 | Token *comma = &pc->tokens->at(*token_index); | |
| 1822 | if (comma->id == TokenIdComma) { | |
| 1820 | Token *maybe_bar = &pc->tokens->at(*token_index); | |
| 1821 | if (maybe_bar->id == TokenIdBinOr) { | |
| 1823 | 1822 | *token_index += 1; |
| 1824 | node->data.for_expr.index_node = ast_parse_symbol(pc, token_index); | |
| 1825 | } | |
| 1823 | node->data.for_expr.elem_node = ast_parse_symbol(pc, token_index); | |
| 1826 | 1824 | |
| 1827 | ast_eat_token(pc, token_index, TokenIdRParen); | |
| 1825 | Token *maybe_comma = &pc->tokens->at(*token_index); | |
| 1826 | if (maybe_comma->id == TokenIdComma) { | |
| 1827 | *token_index += 1; | |
| 1828 | ||
| 1829 | node->data.for_expr.index_node = ast_parse_symbol(pc, token_index); | |
| 1830 | } | |
| 1831 | ||
| 1832 | ast_eat_token(pc, token_index, TokenIdBinOr); | |
| 1833 | } | |
| 1828 | 1834 | |
| 1829 | 1835 | node->data.for_expr.body = ast_parse_expression(pc, token_index, true); |
| 1830 | 1836 |
std/bootstrap.zig+1-1| ... | ... | @@ -25,7 +25,7 @@ fn strlen(ptr: &const u8) -> isize { |
| 25 | 25 | |
| 26 | 26 | fn call_main() -> unreachable { |
| 27 | 27 | var args: [argc][]u8 = undefined; |
| 28 | for (arg, args, i) { | |
| 28 | for (args) |arg, i| { | |
| 29 | 29 | const ptr = argv[i]; |
| 30 | 30 | args[i] = ptr[0...strlen(ptr)]; |
| 31 | 31 | } |
std/rand.zig+1-1| ... | ... | @@ -59,7 +59,7 @@ pub struct Rand { |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | fn generate_numbers(r: &Rand) { |
| 62 | for (item, r.array, i) { | |
| 62 | for (r.array) |item, i| { | |
| 63 | 63 | const y : u32 = (item & 0x80000000) + (r.array[(i + 1) % ARRAY_SIZE] & 0x7fffffff); |
| 64 | 64 | const untempered : u32 = r.array[(i + 397) % ARRAY_SIZE] ^ (y >> 1); |
| 65 | 65 | r.array[i] = if ((y % 2) == 0) { |
std/std.zig+1-1| ... | ... | @@ -173,7 +173,7 @@ pub error Overflow; |
| 173 | 173 | pub fn parse_u64(buf: []u8, radix: u8) -> %u64 { |
| 174 | 174 | var x : u64 = 0; |
| 175 | 175 | |
| 176 | for (c, buf) { | |
| 176 | for (buf) |c| { | |
| 177 | 177 | const digit = char_to_digit(c); |
| 178 | 178 | |
| 179 | 179 | if (digit > radix) { |
std/test_runner.zig+1-1| ... | ... | @@ -8,7 +8,7 @@ struct TestFn { |
| 8 | 8 | extern var zig_test_fn_list: []TestFn; |
| 9 | 9 | |
| 10 | 10 | pub fn run_tests() -> %void { |
| 11 | for (test_fn, zig_test_fn_list, i) { | |
| 11 | for (zig_test_fn_list) |test_fn, i| { | |
| 12 | 12 | %%stderr.print_str("Test "); |
| 13 | 13 | %%stderr.print_i64(i + 1); |
| 14 | 14 | %%stderr.print_str("/"); |
test/run_tests.cpp+6-6| ... | ... | @@ -1120,20 +1120,20 @@ import "std.zig"; |
| 1120 | 1120 | |
| 1121 | 1121 | pub fn main(args: [][]u8) -> %void { |
| 1122 | 1122 | const array = []u8 {9, 8, 7, 6}; |
| 1123 | for (item, array) { | |
| 1123 | for (array) |item| { | |
| 1124 | 1124 | %%stdout.print_u64(item); |
| 1125 | 1125 | %%stdout.printf("\n"); |
| 1126 | 1126 | } |
| 1127 | for (item, array, index) { | |
| 1127 | for (array) |item, index| { | |
| 1128 | 1128 | %%stdout.print_i64(index); |
| 1129 | 1129 | %%stdout.printf("\n"); |
| 1130 | 1130 | } |
| 1131 | 1131 | const unknown_size: []u8 = array; |
| 1132 | for (item, unknown_size) { | |
| 1132 | for (unknown_size) |item| { | |
| 1133 | 1133 | %%stdout.print_u64(item); |
| 1134 | 1134 | %%stdout.printf("\n"); |
| 1135 | 1135 | } |
| 1136 | for (item, unknown_size, index) { | |
| 1136 | for (unknown_size) |item, index| { | |
| 1137 | 1137 | %%stdout.print_i64(index); |
| 1138 | 1138 | %%stdout.printf("\n"); |
| 1139 | 1139 | } |
| ... | ... | @@ -1145,7 +1145,7 @@ import "std.zig"; |
| 1145 | 1145 | |
| 1146 | 1146 | pub fn main(args: [][]u8) -> %void { |
| 1147 | 1147 | const fns = []@typeof(fn1) { fn1, fn2, fn3, fn4, }; |
| 1148 | for (f, fns) { | |
| 1148 | for (fns) |f| { | |
| 1149 | 1149 | %%stdout.print_u64(f()); |
| 1150 | 1150 | %%stdout.printf("\n"); |
| 1151 | 1151 | } |
| ... | ... | @@ -1434,7 +1434,7 @@ export fn main(args: c_int, argv: &&u8) -> c_int { |
| 1434 | 1434 | |
| 1435 | 1435 | qsort((&c_void)(array.ptr), c_ulong(array.len), @sizeof(i32), compare_fn); |
| 1436 | 1436 | |
| 1437 | for (item, array, i) { | |
| 1437 | for (array) |item, i| { | |
| 1438 | 1438 | if (item != i) { |
| 1439 | 1439 | abort(); |
| 1440 | 1440 | } |
test/self_hosted.zig+1-1| ... | ... | @@ -81,7 +81,7 @@ enum AnEnumWithPayload { |
| 81 | 81 | fn continue_in_for_loop() { |
| 82 | 82 | const array = []i32 {1, 2, 3, 4, 5}; |
| 83 | 83 | var sum : i32 = 0; |
| 84 | for (x, array) { | |
| 84 | for (array) |x| { | |
| 85 | 85 | sum += x; |
| 86 | 86 | if (x < 3) { |
| 87 | 87 | continue; |