Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse error when using skip field for lookahead #1586

Closed
bbannier opened this issue Nov 6, 2023 · 0 comments · Fixed by #1720
Closed

Parse error when using skip field for lookahead #1586

bbannier opened this issue Nov 6, 2023 · 0 comments · Fixed by #1720
Assignees
Labels
Bug Something isn't working

Comments

@bbannier
Copy link
Member

bbannier commented Nov 6, 2023

I would expect that the skip in the following unit makes no difference to the parsing behavior:

module foo;

public type X = unit {
    xs: uint8[];
    : skip b".";
};

However including it leads to a parse error:

$ printf '\x01\x02\x03.' | spicy-dump foo.spicy
[fatal error] terminating with uncaught exception of type spicy::rt::ParseError: expecting '.' (foo.spicy:5:12)

Dropping the skip makes this parse.

Looking at the generated grammar the only difference seems to be skip introduces an additional indirection,

[debug/grammar] === Grammar foo::X
[debug/grammar]         Epsilon: <epsilon> -> ()
[debug/grammar]            Skip: anon_2 -> skip:       Ctor: anon -> b"." (bytes)
[debug/grammar]  (*)       Unit: foo_X -> xs anon_2
[debug/grammar]        Variable: uintx308 -> uint<8> (container 'xs') [field: xs] [item-type: vector<uint<8>>] [parse-type: vector<uint<8>>]
[debug/grammar]           While: xs  -> while(<look-ahead-found>): uintx308 [field: xs (*)] [item-type: vector<uint<8>>] [parse-type: vector<uint<8>>]
[debug/grammar]       LookAhead: xs_l1 -> {skip:       Ctor: anon -> b"." (bytes) (not a literal)}: <epsilon> | {uint<8> (not a literal)}: xs_l2
[debug/grammar]        Sequence: xs_l2 -> uintx308 xs_l1
[debug/grammar] 
[debug/grammar]   -- Epsilon:
[debug/grammar]      foo_X = false
[debug/grammar]      xs = true
[debug/grammar]      xs_l1 = true
[debug/grammar]      xs_l2 = false
[debug/grammar] 
[debug/grammar]   -- First_1:
[debug/grammar]      foo_X = { anon_2, uintx308 }
[debug/grammar]      xs = { uintx308 }
[debug/grammar]      xs_l1 = { uintx308 }
[debug/grammar]      xs_l2 = { uintx308 }
[debug/grammar] 
[debug/grammar]   -- Follow:
[debug/grammar]      foo_X = {  }
[debug/grammar]      xs = { anon_2 }
[debug/grammar]      xs_l1 = { anon_2 }
[debug/grammar]      xs_l2 = { anon_2 }

vs.

[debug/grammar] === Grammar foo::X
[debug/grammar]         Epsilon: <epsilon> -> ()
[debug/grammar]            Ctor: anon -> b"." (bytes) [field: anon (*)] [item-type: bytes] [parse-type: bytes]
[debug/grammar]  (*)       Unit: foo_X -> xs anon
[debug/grammar]        Variable: uintx308 -> uint<8> (container 'xs') [field: xs] [item-type: vector<uint<8>>] [parse-type: vector<uint<8>>]
[debug/grammar]           While: xs  -> while(<look-ahead-found>): uintx308 [field: xs (*)] [item-type: vector<uint<8>>] [parse-type: vector<uint<8>>]
[debug/grammar]       LookAhead: xs_l1 -> {b"." (bytes) (id 1)}: <epsilon> | {uint<8> (not a literal)}: xs_l2
[debug/grammar]        Sequence: xs_l2 -> uintx308 xs_l1
[debug/grammar] 
[debug/grammar]   -- Epsilon:
[debug/grammar]      foo_X = false
[debug/grammar]      xs = true
[debug/grammar]      xs_l1 = true
[debug/grammar]      xs_l2 = false
[debug/grammar] 
[debug/grammar]   -- First_1:
[debug/grammar]      foo_X = { anon, uintx308 }
[debug/grammar]      xs = { uintx308 }
[debug/grammar]      xs_l1 = { uintx308 }
[debug/grammar]      xs_l2 = { uintx308 }
[debug/grammar] 
[debug/grammar]   -- Follow:
[debug/grammar]      foo_X = {  }
[debug/grammar]      xs = { anon }
[debug/grammar]      xs_l1 = { anon }
[debug/grammar]      xs_l2 = { anon }
@bbannier bbannier added the Bug Something isn't working label Nov 6, 2023
@rsmmr rsmmr self-assigned this Mar 28, 2024
@rsmmr rsmmr closed this as completed in ebe214a Apr 18, 2024
rsmmr added a commit that referenced this issue Apr 18, 2024
* origin/topic/robin/gh-1586-skip-lahead:
  Make skip productions behave like the production they are wrapping.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants