| author | |
| committer | |
| log | af9a9a13747b1e7007e29ff4f76e700f5bd7f7cf |
| tree | 8eafad5d7280bea42b2c09568d71c3b47bafd978 |
| parent | 547e3684bea1fce9b14ffd40be18dcc88479d5a0 |
4 files changed, 21 insertions(+), 7 deletions(-)
doc/langref.html.in+5-3| ... | @@ -12094,7 +12094,9 @@ FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? AddrSpa | ... | @@ -12094,7 +12094,9 @@ FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? AddrSpa |
| 12094 | 12094 | ||
| 12095 | VarDecl <- (KEYWORD_const / KEYWORD_var) IDENTIFIER (COLON TypeExpr)? ByteAlign? AddrSpace? LinkSection? (EQUAL Expr)? SEMICOLON | 12095 | VarDecl <- (KEYWORD_const / KEYWORD_var) IDENTIFIER (COLON TypeExpr)? ByteAlign? AddrSpace? LinkSection? (EQUAL Expr)? SEMICOLON |
| 12096 | 12096 | ||
| 12097 | ContainerField <- doc_comment? KEYWORD_comptime? IDENTIFIER (COLON TypeExpr ByteAlign?)? (EQUAL Expr)? | 12097 | ContainerField |
| 12098 | <- doc_comment? KEYWORD_comptime? IDENTIFIER (COLON TypeExpr ByteAlign?)? (EQUAL Expr)? | ||
| 12099 | / doc_comment? KEYWORD_comptime? (IDENTIFIER COLON)? !KEYWORD_fn TypeExpr ByteAlign? (EQUAL Expr)? | ||
| 12098 | 12100 | ||
| 12099 | # *** Block Level *** | 12101 | # *** Block Level *** |
| 12100 | Statement | 12102 | Statement |
| ... | @@ -12479,8 +12481,8 @@ string_char | ... | @@ -12479,8 +12481,8 @@ string_char |
| 12479 | <- char_escape | 12481 | <- char_escape |
| 12480 | / [^\\"\n] | 12482 | / [^\\"\n] |
| 12481 | 12483 | ||
| 12482 | container_doc_comment <- ('//!' [^\n]* [ \n]*)+ | 12484 | container_doc_comment <- ('//!' [^\n]* [ \n]* skip)+ |
| 12483 | doc_comment <- ('///' [^\n]* [ \n]*)+ skip | 12485 | doc_comment <- ('///' [^\n]* [ \n]* skip)+ |
| 12484 | line_comment <- '//' ![!/][^\n]* / '////' [^\n]* | 12486 | line_comment <- '//' ![!/][^\n]* / '////' [^\n]* |
| 12485 | line_string <- ("\\\\" [^\n]* [ \n]*)+ | 12487 | line_string <- ("\\\\" [^\n]* [ \n]*)+ |
| 12486 | skip <- ([ \n] / line_comment)* | 12488 | skip <- ([ \n] / line_comment)* |
lib/std/zig/Ast.zig+1-2| ... | @@ -559,8 +559,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -559,8 +559,7 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { |
| 559 | .container_field, | 559 | .container_field, |
| 560 | => { | 560 | => { |
| 561 | const name_token = main_tokens[n]; | 561 | const name_token = main_tokens[n]; |
| 562 | if (token_tags[name_token + 1] != .colon) return name_token - end_offset; | 562 | if (token_tags[name_token] != .keyword_comptime and name_token > 0 and token_tags[name_token - 1] == .keyword_comptime) { |
| 563 | if (name_token > 0 and token_tags[name_token - 1] == .keyword_comptime) { | ||
| 564 | end_offset += 1; | 563 | end_offset += 1; |
| 565 | } | 564 | } |
| 566 | return name_token - end_offset; | 565 | return name_token - end_offset; |
lib/std/zig/parse.zig-1| ... | @@ -313,7 +313,6 @@ const Parser = struct { | ... | @@ -313,7 +313,6 @@ const Parser = struct { |
| 313 | trailing = false; | 313 | trailing = false; |
| 314 | }, | 314 | }, |
| 315 | else => { | 315 | else => { |
| 316 | p.tok_i += 1; | ||
| 317 | const identifier = p.tok_i; | 316 | const identifier = p.tok_i; |
| 318 | defer last_field = identifier; | 317 | defer last_field = identifier; |
| 319 | const container_field = p.expectContainerField() catch |err| switch (err) { | 318 | const container_field = p.expectContainerField() catch |err| switch (err) { |
lib/std/zig/parser_test.zig+15-1| ... | @@ -1,7 +1,9 @@ | ... | @@ -1,7 +1,9 @@ |
| 1 | test "zig fmt: tuple struct" { | 1 | test "zig fmt: tuple struct" { |
| 2 | try testCanonical( | 2 | try testCanonical( |
| 3 | \\const T = struct { | 3 | \\const T = struct { |
| 4 | \\ comptime u32, | 4 | \\ /// doc comment on tuple field |
| 5 | \\ comptime comptime u32, | ||
| 6 | \\ /// another doc comment on tuple field | ||
| 5 | \\ *u32 = 1, | 7 | \\ *u32 = 1, |
| 6 | \\ // needs to be wrapped in parentheses to not be parsed as a function decl | 8 | \\ // needs to be wrapped in parentheses to not be parsed as a function decl |
| 7 | \\ (fn () void) align(1), | 9 | \\ (fn () void) align(1), |
| ... | @@ -4238,6 +4240,18 @@ test "zig fmt: remove newlines surrounding doc comment within container decl" { | ... | @@ -4238,6 +4240,18 @@ test "zig fmt: remove newlines surrounding doc comment within container decl" { |
| 4238 | ); | 4240 | ); |
| 4239 | } | 4241 | } |
| 4240 | 4242 | ||
| 4243 | test "zig fmt: comptime before comptime field" { | ||
| 4244 | try testError( | ||
| 4245 | \\const Foo = struct { | ||
| 4246 | \\ a: i32, | ||
| 4247 | \\ comptime comptime b: i32 = 1234, | ||
| 4248 | \\}; | ||
| 4249 | \\ | ||
| 4250 | , &[_]Error{ | ||
| 4251 | .expected_comma_after_field, | ||
| 4252 | }); | ||
| 4253 | } | ||
| 4254 | |||
| 4241 | test "zig fmt: invalid else branch statement" { | 4255 | test "zig fmt: invalid else branch statement" { |
| 4242 | try testError( | 4256 | try testError( |
| 4243 | \\/// This is a doc comment for a comptime block. | 4257 | \\/// This is a doc comment for a comptime block. |