chiark / gitweb /
src/parser/: Allow parsers to commit to a parse while peeking.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 26 May 2016 08:26:09 +0000 (09:26 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 29 May 2016 14:08:43 +0000 (15:08 +0100)
commit2b8759bf0239b0a98ac830952ed69572580826c1
treedf69e115b0e0d92c654b57dc363e31898527deae
parente07fb83cca55921ef64b73880276277fee9107a8
src/parser/: Allow parsers to commit to a parse while peeking.

There is a new parser macro `commit' which may be used lexically within
the body of `peek' to commit to the current parse: if a failure is
encountered once the parse is committed, then the entire `peek' fails
having consumed input, rather than rewinding to the start.  This allows
parsers to limit the amount of lookahead they use once the ambiguity is
resolved.

Technically, the changes are as follows.

  * The `peek' parser macro introduces a new lexically-scoped macro into
    its body which releases its captured place and sets the
    corresponding variable to `nil'.

  * The `with-parser-place' and `with-scanner-place' macros don't try to
    release their captured places on unwind if they've been set to
    `nil'.  (It's not necessary to have changed `with-scanner-place'
    here, but it improves symmetry.)

  * There's a new `commit' parser macro which just invokes the magic
    macro introduced by `peek' and succeeds.

  * There's a top-level function with the same name as the local macro,
    to report errors in a slightly less confusing way.
doc/SYMBOLS
doc/parsing.tex
src/parser/parser-proto.lisp
src/parser/scanner-proto.lisp