-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.This issue is limited in scope and/or knowledge of Zig internals.enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
Milestone
Description
Extracted from #14523.
When the following function is used, compile errors should be detected when any syntax that is not legal in ZON is used.
Lines 180 to 204 in 60935de
| /// Parse in ZON mode. Subset of the language. | |
| /// TODO: set a flag in Parse struct, and honor that flag | |
| /// by emitting compilation errors when non-zon nodes are encountered. | |
| pub fn parseZon(p: *Parse) !void { | |
| // We must use index 0 so that 0 can be used as null elsewhere. | |
| p.nodes.appendAssumeCapacity(.{ | |
| .tag = .root, | |
| .main_token = 0, | |
| .data = undefined, | |
| }); | |
| const node_index = p.expectExpr() catch |err| switch (err) { | |
| error.ParseError => { | |
| assert(p.errors.items.len > 0); | |
| return; | |
| }, | |
| else => |e| return e, | |
| }; | |
| if (p.token_tags[p.tok_i] != .eof) { | |
| try p.warnExpected(.eof); | |
| } | |
| p.nodes.items(.data)[0] = .{ | |
| .lhs = node_index, | |
| .rhs = undefined, | |
| }; | |
| } |
ZON is only allowed to use a subset of the Zig language:
- string literal
- boolean literal
- integer literal
- float literal
- null literal
- undefined literal
- anonymous struct literal
- tuple literal
- anonymous enum literal
Anything else, such as functions, control flow logic, mathematical operations, etc., should be rejected by the parser.
Be careful with negative numbers, which are certainly allowed in ZON.
For testing, look into augmenting lib/std/zig/parser_test.zig.
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.This issue is limited in scope and/or knowledge of Zig internals.enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.