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

Add parser backtracking #25

Closed
2 tasks
bbannier opened this issue Apr 6, 2020 · 3 comments
Closed
2 tasks

Add parser backtracking #25

bbannier opened this issue Apr 6, 2020 · 3 comments
Assignees
Labels
Port V1 Functionality that still needs to ported from the the old Spicy research prototype

Comments

@bbannier
Copy link
Member

bbannier commented Apr 6, 2020

  • Spicy:
    • Parse attributes:

      • &try
    • Unit methods

      • backtrack

Note: Make sure backtracking from an %error hook continues parsing.

Old tests in backtrack* in https://github.com/rsmmr/hilti/tree/master/tests/spicy/unit

@bbannier bbannier added Port V1 Functionality that still needs to ported from the the old Spicy research prototype Spicy labels Apr 6, 2020
@bbannier
Copy link
Member Author

bbannier commented Apr 6, 2020

closed

@bbannier
Copy link
Member Author

bbannier commented Apr 6, 2020

reopened

@bbannier
Copy link
Member Author

bbannier commented Apr 6, 2020

marked this issue as related to #118

@rsmmr rsmmr removed Spicy labels Apr 24, 2020
@rsmmr rsmmr self-assigned this Dec 2, 2020
rsmmr added a commit that referenced this issue Dec 2, 2020
If a field is marked with ``&try``, a later call to ``self.backtrack()``
anywhere down in the parse tree will return to that position and
continue there. (This is ported over the old prototype).

Example:

    export type test = unit {
        a: bytes &length=4;
        foo: Foo &try;
        bar: Bar;
        b: bytes &length=6;

        on %done { print self; }
    };

    type Foo = unit {
        a: int8 { print "Foo.a", self; }
        b: int8 { print "Backtracking"; self.backtrack(); }
        c: int8 { print "Foo.c", self; }
    };

    type Bar = unit {
        a: int8 { print "Bar.a", self; }
        b: int8 { print "Bar.b", self; }
        c: int8 { print "Bar.c", self; }
    };

    # printf '1234\001\002\003567890' | pac-driver backtrack.pac2
    Foo.a <a=1, b=(not set), c=(not set)>
    Backtracking
    Bar.a <a=1, b=(not set), c=(not set)>
    Bar.b <a=1, b=2, c=(not set)>
    Bar.c <a=1, b=2, c=3>
    <a=1234, foo=(Null), bar=<a=1, b=2, c=3>, b=567890>

Closes #25.
rsmmr added a commit that referenced this issue Dec 8, 2020
If a field is marked with ``&try``, a later call to ``self.backtrack()``
anywhere down in the parse tree will return to that position and
continue there. (This is ported over the old prototype).

Example:

    export type test = unit {
        a: bytes &length=4;
        foo: Foo &try;
        bar: Bar;
        b: bytes &length=6;

        on %done { print self; }
    };

    type Foo = unit {
        a: int8 { print "Foo.a", self; }
        b: int8 { print "Backtracking"; self.backtrack(); }
        c: int8 { print "Foo.c", self; }
    };

    type Bar = unit {
        a: int8 { print "Bar.a", self; }
        b: int8 { print "Bar.b", self; }
        c: int8 { print "Bar.c", self; }
    };

    # printf '1234\001\002\003567890' | pac-driver backtrack.pac2
    Foo.a <a=1, b=(not set), c=(not set)>
    Backtracking
    Bar.a <a=1, b=(not set), c=(not set)>
    Bar.b <a=1, b=2, c=(not set)>
    Bar.c <a=1, b=2, c=3>
    <a=1234, foo=(Null), bar=<a=1, b=2, c=3>, b=567890>

Closes #25.
@rsmmr rsmmr closed this as completed in ab761b8 Dec 10, 2020
rsmmr added a commit that referenced this issue Dec 10, 2020
* origin/topic/robin/gh-25-backtrack:
  Fix Sphinx helper script that emits command lines.
  Add support for manual backtracking to Spicy.
  Support &eod for vector parsing.
rsmmr added a commit that referenced this issue Dec 10, 2020
* origin/topic/robin/gh-25-backtrack:
  Fix Sphinx helper script that emits command lines.
  Add support for manual backtracking to Spicy.
  Support &eod for vector parsing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Port V1 Functionality that still needs to ported from the the old Spicy research prototype
Projects
None yet
Development

No branches or pull requests

2 participants