soasme / PeppaPEG

PEG Parser in ANSI C
https://soasme.com/PeppaPEG
MIT License
55 stars 7 forks source link

Example fails with MatchError: line 1:1, expect value #154

Open Jomy10 opened 1 year ago

Jomy10 commented 1 year ago

Describe the bug In the example on the readme, it fails with the message MatchError: line 1:1, expect value.

To Reproduce

❯ cat json.peg
@lifted entry = &. value !.;
@lifted value = object / array / string / number / true / false / null;

object = "{" (item ("," item)*)? "}";
item = string ":" value;

array = "[" (value ("," value)*)? "]";

@tight string = "\"" ([\u0020-\u0021] / [\u0023-\u005b] / [\u005d-\U0010ffff] / escape )* "\"";

true = "true";
false = "false";
null = "null";

@tight @squashed
number = minus? integral fractional? exponent?;

@tight @squashed @lifted
escape = "\\" ("\"" / "/" / "\\" / "b" / "f" / "n" / "r" / "t" / unicode);

@tight @squashed
unicode = "u" ([0-9] / [a-f] / [A-F]){4};

minus = "-";
plus = "+";

@squashed @tight
integral = "0" / [1-9] [0-9]*;

@squashed @tight
fractional = "." [0-9]+;

@tight
exponent = i"e" (plus / minus)? [0-9]+;

@spaced @lifted
whitespace = " " / "\r" / "\n" / "\t";

❯ cat data.json
[{"numbers": [1,,2.0,3e1]},[true,false,null],"xyz"]

❯ ./peppa parse -G json.peg -e entry data.json
data.json:
MatchError: line 1:1, expect value

Expected behavior A successful parse

Desktop (please complete the following information):

Additional context