zeek / spicy

C++ parser generator for dissecting protocols & files.
https://docs.zeek.org/projects/spicy
Other
243 stars 37 forks source link

Parse failure after successful synchronizaiton with `%synchronize-at` #1774

Closed bbannier closed 1 month ago

bbannier commented 1 month ago

Using %synchronize-at with regexp to sync a unit which expects to parse a bytes literal synchronizes successfully, but the unit still fails to parse. If I instead use a bytes literal for %synchronize-at the unit can continue parsing. I see this since about 57debb2d3abb3a89690d10991b1ddfd5e3198e14.

module foo;

type A = unit {
    # %synchronize-at = b"A";
    %synchronize-at = /A/;

    a: b"A";
};

public type X = unit {
    : (A &synchronize)[] foreach {
        print $$;
    }

    on %synced {
        print "synced";
        confirm;
    }
};

$ printf 'ABBAA' | HILTI_DEBUG=spicy-verbose spicy-driver -d foo.spicy
[spicy-verbose] - state: type=foo::X input="ABBAA" stream=0x600003404218 offsets=0/0/0/5 chunks=1 frozen=yes mode=default trim=yes lah=n/a lah_token="n/a" recovering=no
[spicy-verbose] - parsing production: Unit: foo__X -> _anon_2
[spicy-verbose]   - state: type=foo::X input="ABBAA" stream=0x600003404218 offsets=0/0/0/5 chunks=1 frozen=yes mode=default trim=yes lah=n/a lah_token="n/a" recovering=no
[spicy-verbose]   - parsing production: While: _anon_2 -> while(<look-ahead-found>): Resolved_3
[spicy-verbose]     - state: type=foo::X input="ABBAA" stream=0x600003404218 offsets=0/0/0/5 chunks=1 frozen=yes mode=default trim=yes lah=1 lah_token="A" recovering=no
[spicy-verbose]     - parsing production: Unit: foo__A_2 -> a_2 (container '_anon_2')
[spicy-verbose]       - state: type=foo::A input="ABBAA" stream=0x600003404218 offsets=0/0/0/5 chunks=1 frozen=yes mode=default trim=yes lah=1 lah_token="A" recovering=no
[spicy-verbose]       - parsing production: Ctor: a   -> b"A" (const bytes)
[spicy-verbose]         - consuming look-ahead token
[spicy-verbose]         - trimming input
[spicy-verbose]         - trimming input
[spicy-verbose]       - setting field 'a' to 'A'
[spicy-verbose]     - got container item
[$a=b"A"]
[spicy-verbose]     failed to parse list element, will try to synchronize at next possible element
[spicy-verbose]     - trimming input
[spicy-verbose]     - state: type=foo::X input="BAA" stream=0x600003404218 offsets=2/0/2/5 chunks=1 frozen=yes mode=default trim=yes lah=n/a lah_token="n/a" recovering=yes
[spicy-verbose]     - state: type=foo::X input="BAA" stream=0x600003404218 offsets=2/0/2/5 chunks=1 frozen=yes mode=default trim=yes lah=n/a lah_token="n/a" recovering=yes
[spicy-verbose]     - trimming input
[spicy-verbose]     - state: type=foo::X input="AA" stream=0x600003404218 offsets=3/0/3/5 chunks=1 frozen=yes mode=default trim=yes lah=2 lah_token="A" recovering=yes
[spicy-verbose]     successfully synchronized
synced
[spicy-verbose]     failed to parse list element, will try to synchronize at next possible element
[spicy-verbose]     - trimming input
[spicy-verbose]     - state: type=foo::X input="A" stream=0x600003404218 offsets=4/0/4/5 chunks=1 frozen=yes mode=default trim=yes lah=2 lah_token="A" recovering=yes
[spicy-verbose]     successfully synchronized
synced
[spicy-verbose]     failed to parse list element, will try to synchronize at next possible element
[spicy-verbose]     - trimming input
[error] terminating with uncaught exception of type spicy::rt::ParseError: failed to synchronize: no expected look-ahead token found (foo.spicy:11:5-13:5)