Skip to content

Official json5.org example results in 'InvalidIdentifier' error #4

@Synthasmagoria

Description

@Synthasmagoria

Zig version 0.14.1
OS: Ubuntu 24.04 LTS
Hi, tried out your library for a project and dropped in the json5 example on json5.org:

const json5 = @import("json5.zig");
const std = @import("std");

const JSON5 =
\\{
\\  // comments
\\  unquoted: 'and you can quote me on that',
\\  singleQuotes: 'I can use "double quotes" here',
\\  lineBreaks: "Look, Mom! \
\\No \\n's!",
\\  hexadecimal: 0xdecaf,
\\  leadingDecimalPoint: .8675309, andTrailing: 8675309.,
\\  positiveSign: +1,
\\  trailingComma: 'in objects', andIn: ['arrays',],
\\  "backwardsCompatible": "with JSON",
\\}
;

pub fn main() !void {
    const a = std.heap.page_allocator;
    var parser = json5.Parser.init(a, false);
    defer parser.deinit();
    var tree = try parser.parse(JSON5);
    defer tree.deinit();
}

And got the following error

error: InvalidIdentifier
/home/synthas/programming/zig-gamemaker-filename-corrector/src/json5.zig:741:25: 0x10f41e5 in transition (zig_gamemaker_filename_corrector)
                        return error.InvalidIdentifier;
                        ^
/home/synthas/programming/zig-gamemaker-filename-corrector/src/json5.zig:335:13: 0x10f0189 in feed (zig_gamemaker_filename_corrector)
        if (try p.transition(c, token1)) {
            ^
/home/synthas/programming/zig-gamemaker-filename-corrector/src/json5.zig:1262:13: 0x10eed28 in next (zig_gamemaker_filename_corrector)
            try self.parser.feed(self.slice[self.i], &t1, &t2);
            ^
/home/synthas/programming/zig-gamemaker-filename-corrector/src/json5.zig:1961:16: 0x10ee71d in parse (zig_gamemaker_filename_corrector)
        while (try s.next()) |token| {
               ^
/home/synthas/programming/zig-gamemaker-filename-corrector/src/main.zig:41:16: 0x10ef0a1 in main (zig_gamemaker_filename_corrector)
    var tree = try parser.parse(JSON5);
               ^
run
└─ run zig_gamemaker_filename_corrector failure
error: the following command exited with error code 1:
/home/synthas/programming/zig-gamemaker-filename-corrector/zig-out/bin/zig_gamemaker_filename_corrector

I don't know much about parsing myself.
Hopefully the code is good enough for the issue to be identified.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions