Commit Graph

86 Commits

Author SHA1 Message Date
82d398cbb3 parser: reorder tests to match upstream file order
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:20 +00:00
3c83549f77 parser: port enum/union/catch/switch/for/if declaration tests
Port tests:
- "enum declaration"
- "union declaration"
- "catch"
- "switch"
- "for if", "if for", "while if", "if while", "while for", "for while"
- "if"

Fix in parser.c:
- parsePtrPayload: handle multi-capture |a, *b|
- parseWhileStatement/parseForStatement: separate statement-context
  body parsing (block or assign expr + semicolon)

Deferred tests (need further work):
- "while" (full test) - var decl in while body context
- "for" (full test) - capture parsing edge case

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:20 +00:00
7aa68ebbdb parser: port precedence, prefix, functions, values, indexing tests
Port tests:
- "precedence"
- "prefix operators"
- "functions"
- "multiline string"
- "multiline string with CRLF line endings"
- "values"
- "indexing"
- "struct declaration"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:19 +00:00
97c9fb6378 parser: implement asm parsing, port formatting tests
Implement in parser.c:
- parseAsmExpr: asm_simple and asm nodes with outputs, inputs,
  clobbers (including legacy string clobber format)
- parseAsmOutputItem, parseAsmInputItem helper functions

Port tests:
- "preserve spacing"
- "return types"
- "imports"
- "global declarations"
- "extern declaration"
- "function attributes"
- "nested pointers with ** tokens"
- "test declaration"
- "top-level for/while loop"
- Various error set, switch prong, comment tests

Note: asm test cases that require asm_legacy AST node (not yet in
ast.h) are deferred.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:19 +00:00
a1fef56b95 parser: port formatting, declaration, fn attribute tests
Port tests:
- "preserve spacing"
- "return types"
- "imports"
- "global declarations"
- "extern declaration"
- "function attributes"
- "nested pointers with ** tokens"
- "test declaration"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:19 +00:00
37ae8b01d1 parser: implement for loops, port for/while loop test
Implement in parser.c:
- forPrefix: parse for input expressions and capture variables
- parseForExpr: for_simple and for AST nodes with optional else
- Handle for and while in parsePrimaryTypeExpr for top-level usage

Remove stale cppcheck knownConditionTrueFalse suppression.

Port test "top-level for/while loop".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:18 +00:00
40b7c19848 parser: port error set, suspend, switch prong comment tests
Port tests:
- "error set declaration"
- "union(enum(u32)) with assigned enum values"
- "resume from suspend block"
- "comments before error set decl"
- "comments before switch prong"
- "array literal with 1 item on 1 line"
- "comments in statements"

Implement in parser.c:
- suspend statement in expectStatement
- Fix error set decl to store lbrace token (not 0)
- Fix comptime statement to wrap inner expression

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:18 +00:00
d9ae83d1f6 parser: port comment, switch, error value tests batch
Port tests:
- "comment after if before another if"
- "line comment between if block and else keyword"
- "same line comments in expression"
- "add comma on last switch prong"
- "same-line comment after a statement"
- "same-line comment after var decl in struct"
- "same-line comment after field decl"
- "same-line comment after switch prong"
- "same-line comment after non-block if expression"
- "same-line comment on comptime expression"
- "switch with empty body"
- "line comments in struct initializer"
- "first line comment in struct initializer"
- "doc comments before struct field"

Implement in parser.c:
- error.Value and error{...} in parsePrimaryTypeExpr
- TOKEN_PERIOD_ASTERISK (deref) in parseSuffixOp
- Fix comptime statement to wrap inner expression in comptime node

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:17 +00:00
50ea349da4 parser: port switch, slice, array literal, formatting tests
Port tests:
- "switch cases trailing comma"
- "slice align"
- "add trailing comma to array literal"
- "first thing in file is line comment"
- "line comment after doc comment"
- "bit field alignment"
- "nested switch"
- "float literal with exponent"
- "if-else end of comptime"
- "nested blocks"
- "statements with comment between"
- "statements with empty line between"
- "ptr deref operator and unwrap optional operator"

Fix in parser.c:
- switch_case SubRange stored via addExtra (not inline)
- Switch case body uses parseAssignExpr (not expectExpr)
- TOKEN_PERIOD_ASTERISK for deref in parseSuffixOp

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:17 +00:00
64ce9659de parser: port array literal hint and vertical alignment tests
Port tests:
- "array literal with hint"
- "array literal vertical column alignment"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:17 +00:00
70cbee78e4 parser: port test "struct literal containing a multiline expression"
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:16 +00:00
fe86388d1e parser: implement switch, port switch comment tests
Implement parseSwitchExpr in parser.c:
- switch(expr) { cases... } with case items, ranges, else
- switch_case_one and switch_case node types
- Proper scratch management for nested case items

Port tests:
- "switch comment before prong"
- "switch comment after prong"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:16 +00:00
2dc5993a29 parser: port if-condition-wraps tests, implement catch payload
Port tests:
- "if condition has line break but must not wrap"
- "if condition has line break but must not wrap (no fn call comma)"

Implement catch payload (|err|) parsing in parseExprPrecedence.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:15 +00:00
6356c15c70 parser: port test "if condition wraps"
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:15 +00:00
a8bca43940 parser: implement while loops, port while test
Implement in parser.c:
- parseWhileExpr: while (cond) body, with optional payload,
  continue expression, and else clause
- while_simple, while_cont, while AST nodes

Port test "while else err prong with no block".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:15 +00:00
26c73c4f87 parser: port test "2nd arg multiline string many args"
Split "2nd arg multiline string" to match upstream structure
(separate test for "many args" variant) and add missing
testTransform sub-case.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:14 +00:00
14fb82109b parser: port zig fmt on/off in middle of code tests
Port tests:
- "'zig fmt: (off|on)' works in the middle of code"
- "'zig fmt: on' indentation is unchanged"

Handle block-terminated expressions (if, while) that don't need
semicolons by checking if previous token was '}'.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:14 +00:00
2b48992a2f parser: port test "whitespace fixes"
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:14 +00:00
854f1157c4 parser: port test "rewrite callconv(.@\"inline\") to the inline keyword"
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:13 +00:00
ebda1c03bd parser: reorder tests to match upstream file order
Reorder all test blocks in parser_test.zig to match the order
they appear in the upstream zig/lib/std/zig/parser_test.zig.
Tests not in upstream ("Ast header smoke test", "my function")
are placed at the end.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:13 +00:00
ee955c8522 parser: port alignment and zig fmt whitespace tests
Port tests:
- "alignment in anonymous literal"
- "'zig fmt: (off|on)' can be surrounded by arbitrary whitespace"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:13 +00:00
5d4e50075a parser: port zig fmt on/off, defer, block slice tests
Port tests:
- "line and doc comment following 'zig fmt: off'"
- "doc and line comment following 'zig fmt: off'"
- "line comment following 'zig fmt: on'"
- "doc comment following 'zig fmt: on'"
- "line and doc comment following 'zig fmt: on'"
- "doc and line comment following 'zig fmt: on'"
- "block in slice expression"
- "defer"

Fix defer node data: body goes in lhs (not rhs) to match .node
union variant.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:12 +00:00
26725d687a parser: port fn param and container initializer tests
Port tests:
- "doc comments on param decl"
- "pointer of unknown length"
- "call expression"
- "anytype type"
- "container initializers"

Handle anytype keyword in function parameter lists.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:12 +00:00
ed6d91f2f0 parser: port misc formatting tests batch
Port tests:
- "alignment"
- "C main"
- "return"
- "arrays"
- "blocks"
- "container doc comments"
- "comments before global variables"
- "comments before test decl"
- "decimal float literals with underscore separators"
- "comptime"
- "comptime block in container"
- "comments before var decl in struct"
- "block with same line comment after end brace"
- "comment after empty comment"
- "comment after params"

Fix trailing flag for comptime blocks in parseContainerMembers.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:11 +00:00
f45c71fc04 parser: port threadlocal, linksection, addrspace tests
Port tests:
- "threadlocal"
- "linksection"
- "addrspace"

Implement full var decl proto with aligned_var_decl, local_var_decl,
and global_var_decl node types for align/addrspace/linksection.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:11 +00:00
a4d9e12498 parser: port pointer modifier tests
Port tests:
- "pointer-to-one with modifiers"
- "pointer-to-many with modifiers"
- "sentinel pointer with modifiers"
- "c pointer with modifiers"
- "slice with modifiers"
- "sentinel slice with modifiers"
- "allowzero pointer"

Implement in parser.c:
- parsePtrModifiersAndType: shared pointer modifier parsing with
  align(expr:expr:expr) bit-range, addrspace, sentinel support
- ptr_type, ptr_type_bit_range nodes with proper OptionalIndex
  encoding via global OPT() macro
- Refactor * and [*] pointer type parsing to use shared code

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:11 +00:00
508a94dd33 parser: port array/slice literal and pointer type tests
- "sentinel array literal 1 element"
- "anon literal in array"
- "Unicode code point literal larger than u8"
- "slices with spaces in bounds"
- "C pointers"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:11 +00:00
19c36c5dcb parser: port test "sentinel-terminated array type"
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:10 +00:00
83c463f6a7 parser: port test "sentinel-terminated slice type"
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:10 +00:00
592638502a parser: port test "c pointer type"
Implement [*], [*c], and [*:s] pointer type parsing in parseTypeExpr.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:09 +00:00
74d6a66a2d parser: port test "nosuspend block"
Implement nosuspend statement in expectStatement.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:09 +00:00
2279ac85a0 parser: port test "errdefer with payload"
Implement in parser.c:
- defer and errdefer statements with expectBlockExprStatement
- parseAssignExpr for assignment expressions (expr op= expr)
- expectBlockExprStatement: block or assign expr + semicolon
- assignOpTag: map all assignment operator tokens to AST tags

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:08 +00:00
cd5ebdb904 parser: port test "top-level bare asterisk+asterisk+identifier"
Implement ** (double pointer) type parsing in parseTypeExpr.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:08 +00:00
fcfa3f3b4a parser: port test "top-level bare asterisk+identifier"
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:08 +00:00
6743d5dd2f parser: port test "top-level tuple function call type"
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:07 +00:00
bfc5846c4d parser: add multiline string, fn call, struct, if-else tests
Port tests from upstream parser_test.zig:
- "multiline string with backslash at end of line"
- "multiline string parameter in fn call with trailing comma"
- "trailing comma on fn call"
- "multi line arguments without last comma"
- "empty block with only comment"
- "trailing commas on struct decl"
- "extra newlines at the end"
- "nested struct literal with one item"
- "if-else with comment before else"

Fix parseSuffixExpr: continue suffix loop after call parsing
instead of returning, enabling method chains like a.b().c().

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:07 +00:00
bf632b9d6b parser: add if expression and statement tests
Port tests from upstream parser_test.zig:
- "if statement"
- "respect line breaks in if-else"
- "if nested"
- "remove empty lines at start/end of block"

Implement in parser.c:
- parseIfExpr: if/else expression parsing with payloads
- parsePtrPayload, parsePayload: |value| and |*value| handling
- Handle block-terminated expressions without semicolons in
  expectVarDeclExprStatement

Fix zigData in parser_test.zig:
- if, while, while_cont use node_and_extra (not node_and_node)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:07 +00:00
9f77f5a234 parser: add infix, fn trailing comma, enum, struct literal tests
Port tests from upstream parser_test.zig:
- "respect line breaks after infix operators"
- "fn decl with trailing comma"
- "enum decl with no trailing comma"
- "struct literal no trailing comma"
- "2nd arg multiline string"
- "final arg multiline string"
- "function call with multiline argument"

No new parser.c changes needed — all features already implemented.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:06 +00:00
c67c54c3fb parser: add zig fmt on/off and slice operator tests
Port tests from upstream parser_test.zig:
- "comment to disable/enable zig fmt"
- "line comment following 'zig fmt: off'"
- "doc comment following 'zig fmt: off'"
- "alternating 'zig fmt: off' and 'zig fmt: on'"
- "spaces around slice operator"

Fix parsePrimaryTypeExpr: don't reject identifier followed by colon;
the colon may be part of slice sentinel syntax, not a label.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:06 +00:00
1a8bb5ac10 parser: add fn params, return, call args, enum literal tests
Port tests from upstream parser_test.zig:
- "trailing comma in fn parameter list" (all combinations)
- "enum literal inside array literal"
- "builtin call with trailing comma"

Implement in parser.c:
- parseParamDeclList: full parameter parsing with names, comptime,
  noalias, doc comments, varargs
- parseFnProto: fn_proto_multi, fn_proto_one, fn_proto with
  align/addrspace/section/callconv
- parseSuffixExpr: function call with arguments
- parsePrimaryExpr: return, comptime, nosuspend, resume expressions
- parseAddrSpace, parseLinkSection, parseCallconv: full parsing
- Use OPT() macro for OptionalIndex encoding in extra data

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:05 +00:00
cb4be73acb parser: add enum, union, literal, struct doc comment tests
Port tests from upstream parser_test.zig:
- "empty enum decls" (with extern/packed modifiers)
- "empty union decls" (with extern/packed/enum modifiers)
- "enum literal"
- "character literal larger than u8"
- "infix operator and then multiline string literal" (2 tests)
- "correctly space struct fields with doc comments"
- "aligned struct field"
- "comment to disable/enable zig fmt first"

Implement in parser.c:
- extern/packed modifiers before struct/union/enum in
  parsePrimaryTypeExpr

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:05 +00:00
b2b1d8f188 parser: add slicing and tagged union tests
Port tests from upstream parser_test.zig:
- "slices" (open, closed, sentinel-terminated)
- "tagged union with enum values"
- "tagged union enum tag last token"

Implement in parser.c:
- Slice expressions in parseSuffixOp: slice_open, slice,
  slice_sentinel
- Handle OptionalIndex encoding for absent slice end expr

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:05 +00:00
8705fd0197 parser: add struct/array literal tests (2/3 element variants)
Port tests from upstream parser_test.zig:
- "struct literal 2/3 element" (with and without comma)
- "anon list literal 1/2/3 element" (with and without comma)
- "array literal 0/1/2/3 element" (with and without comma)

All 17 new tests pass without parser changes — the init list
implementation from the previous commit handles all cases.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:04 +00:00
cd93f7cffd parser: add struct/array init literal tests
Port tests from upstream parser_test.zig:
- "anon struct literal 0/1/2/3 element" (with and without comma)
- "struct literal 0/1 element"

Implement in parser.c:
- parseFieldInit: parse .field = expr field initializers
- parseInitList: full struct/array init list parsing
- parseCurlySuffixExpr: use parseInitList for X{...} syntax
- parsePrimaryTypeExpr: handle .{...} anonymous init and .ident
  enum literals
- Empty X{} produces struct_init_one (matching upstream behavior)

Fix zigData in parser_test.zig:
- array_init_one uses node_and_node (not node_and_opt_node)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:04 +00:00
a61bf83a11 parser: add block, break, grouped expression, array type tests
Port tests from upstream parser_test.zig:
- "allow empty line before comment at start of block"
- "comptime struct field"
- "break from block"
- "grouped expressions (parentheses)"
- "array types last token"

Fix bugs in parser.c:
- parseBreakLabel: use null_token instead of null_node
- test decl: use null_token for unnamed tests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:04 +00:00
b186471328 parser: add container declaration and test decl tests
Port tests from upstream parser_test.zig:
- "container declaration, one item, multi line trailing comma"
- "container declaration, no trailing comma on separate line"
- "container declaration, line break, no trailing comma"
- "container declaration, transform trailing comma"
- "container declaration, comment, add trailing comma"
- "container declaration, multiline string, add trailing comma"
- "container declaration, doc comment on member, add trailing comma"
- "remove empty lines at start/end of container decl"

Implement in parser.c:
- Test declarations in parseContainerMembers
- Comptime block/var statements in expectStatement
- Variable declaration with initializer in expectVarDeclExprStatement
- Regular assignment expressions

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:03 +00:00
8d193346e8 parser: add multiline string, empty file, field, container tests
Port tests from upstream parser_test.zig:
- "multiline string mixed with comments"
- "empty file"
- "file ends in comment"
- "file ends in multi line comment"
- "file ends in comment after var decl"
- "top-level fields"
- "container declaration, single line"

Implement in parser.c:
- parseSuffixOp: array access, field access, deref, unwrap optional
- Slice/array type parsing in parseTypeExpr
- Multiline string literal parsing

Fix zigData mapping in parser_test.zig:
- optional_type uses .node (not .opt_node)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:03 +00:00
298b347cf7 parser: add function, comptime, var declaration tests
Port tests from upstream parser_test.zig:
- "respect line breaks before functions"
- "simple top level comptime block"
- "two spaced line comments before decl"
- "respect line breaks after var declarations"

Implement in parser.c:
- parseSuffixOp: array access (a[i]), field access (a.b),
  deref (a.*), unwrap optional (a.?)
- Multiline string literal parsing
- Slice types ([]T, [:s]T) and array types ([N]T, [N:s]T)
- Fix comptime block main_token in parseContainerMembers

Fix zigData mapping in parser_test.zig:
- field_access, unwrap_optional use node_and_token (not node_and_node)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:03 +00:00
0433771b3e parser: add struct field value declaration test
Port "zig fmt: respect line breaks in struct field value declaration"
test from upstream parser_test.zig.

Implement in parser.c:
- Slice types ([]T, [:s]T) in parseTypeExpr
- Array types ([N]T, [N:s]T) in parseTypeExpr
- Multiline string literals in parsePrimaryTypeExpr
- Add comments explaining why const/volatile/allowzero pointer
  modifiers are consumed (not stored in AST; renderer re-derives
  them from token positions)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:03 +00:00
1bb921b8ca parser: add tuple struct test and container decl support
Port "zig fmt: tuple struct" test from upstream parser_test.zig.

Implement in parser.c:
- parseContainerDeclAuto: struct/enum/union/opaque declarations
- parseGlobalVarDecl: const/var with initializer
- parseByteAlign: align(expr) parsing
- parseTypeExpr: pointer types (*T), optional types (?T)
- parsePrimaryTypeExpr: number_literal, char_literal,
  unreachable_literal, fn proto, grouped expressions,
  container decl, comptime prefix
- expectContainerField: default values (= expr)
- parseContainerMembers: comptime block/field handling
- Fix parseFnProto: use null_token instead of null_node

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-11 14:40:02 +00:00