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

Synchronizing a vector with a constant value for lookahead #1464

Closed
J-Gras opened this issue Jun 21, 2023 · 2 comments · Fixed by #1470
Closed

Synchronizing a vector with a constant value for lookahead #1464

J-Gras opened this issue Jun 21, 2023 · 2 comments · Fixed by #1470
Assignees
Labels
Bug Something isn't working

Comments

@J-Gras
Copy link
Contributor

J-Gras commented Jun 21, 2023

I was pulling my hair out when trying to get something like the following to work:

type X = unit {
    a: b"begin-of-X";
    b: bytes &size=10;
};

type Foo = unit {}
    xs: (X &synchronize)[];

    on %synced { confirm; }
};

I just couldn't get the parser to synchronize. Then, @Mohan-Dhawan suggested to use a regex for a. To my surprise that worked! However, given that the above is taken from the docs, requiring a regex feels like a bug.

@bbannier bbannier added the Bug Something isn't working label Jun 21, 2023
@bbannier
Copy link
Member

bbannier commented Jun 22, 2023

Do you have an example input which shows this problem? I tried the following and it seems to work (successful synchronization shown in log, two final vector elements present):

# @TEST-EXEC: spicyc -dj %INPUT -o foo.hlto
# @TEST-EXEC: printf 'begin-of-X1234567890JUNKbegin-of-X1234567890' | HILTI_DEBUG=spicy:spicy-verbose spicy-driver foo.hlto

module foo;

type X = unit {
    a: b"begin-of-X";
    b: bytes &size=10;
};

public type Foo = unit {
    xs: (X &synchronize)[];

    on %synced { confirm; }
};

@bbannier
Copy link
Member

bbannier commented Jun 23, 2023

Reproducer:

# @TEST-EXEC: spicyc -dj %INPUT -o foo.hlto
# @TEST-EXEC: HILTI_DEBUG=spicy:spicy-verbose spicy-driver foo.hlto -F test.dat

module foo;

type X = unit {
    # a: /A/; # WORKS.
    a: b"A";  # FAILS.
};

# type Foo = unit {
public type Foo = unit {
    %port = 80/tcp;

    xs: (X &synchronize)[];

    on %synced { confirm; }
};

# @TEST-START-FILE test.dat
!spicy-batch v2
@begin-flow id1 stream 80/tcp
@gap id1 1024
@data id1 1
A
@end-flow id1
# @TEST-END-FILE

Verbose logging shows A as lookahead token in the case of regexp parsing, but n/a for the bytes literal.

@bbannier bbannier self-assigned this Jun 23, 2023
bbannier added a commit that referenced this issue Jun 26, 2023
In 7c18597 for #1231 we added code to
handle advance failures in trial mode when synchronizing on regexps, but
missed adding the same support for literals. This patch adds that
missing part.

Closes #1464.

(cherry picked from commit 30903c8)
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