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

Backtracking support through &try/backtrack() #606

Merged
merged 3 commits into from
Dec 10, 2020

Commits on Dec 8, 2020

  1. Support &eod for vector parsing.

    That tells a vector explicitly to parse until it hits the end of the
    input, without having to use the look-ahead machinery to figure out when
    to stop.
    rsmmr committed Dec 8, 2020
    Configuration menu
    Copy the full SHA
    5a5c180 View commit details
    Browse the repository at this point in the history

Commits on Dec 9, 2020

  1. Add support for manual backtracking to Spicy.

    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 committed Dec 9, 2020
    Configuration menu
    Copy the full SHA
    ab761b8 View commit details
    Browse the repository at this point in the history
  2. Fix Sphinx helper script that emits command lines.

    When an example contained multiple commands separated by semicolons,
    we'd execute them separately but still include all of them into each of
    the command lines emitted into the docs.
    
    (Couple of doc outputs show slightly changed content, including updates
    into this commit.)
    rsmmr committed Dec 9, 2020
    Configuration menu
    Copy the full SHA
    2038055 View commit details
    Browse the repository at this point in the history