Note that there are some explanatory texts on larger screens.

plurals
  1. POExcluding certain elements from a specified set in Parsing Expressive Grammar (PEG.js)?
    primarykey
    data
    text
    <p>I am writing a lexer for Haskell using JavaScript and Parsing Expression Grammar, the implementation I use being <a href="http://pegjs.majda.cz/" rel="nofollow">PEG.js</a>.<br> I have a problem with making it work for reserved words, as demonstrated in a simplified form here:</p> <pre><code>program = ( word / " " )+ word = ( reserved / id ) id = ( "a" / "b" )+ reserved = ( "aa" ) </code></pre> <p>The point here is to get a series of tokens that are either arbitrary sequences of a:s and/or b:s or the sequence "aa", and they are separated by spaces.<br> What I really get is either that <em>every</em> token that is not a space is recognized as <code>id</code> or that a token that should be recognised as <code>id</code> has all initial pairs of a:s eaten up as <code>reserved</code>, e.g.<br> "aab" gets recognized as <code>reserved "aa"</code> followed by <code>id "b"</code>.</p> <p>The way the Haskell lexical specification solves this ambiguity is to specify id like this: </p> <pre><code>id = ( "a" / "b" )+[BUT NOT reserved] </code></pre> <p>I have tried replicating this using various combinations of the PEG ! and &amp; -operators to acheive the same effect, but have not found a way to get this to work properly.<br> The solution:</p> <pre><code>id = !reserved ( "a" / "b" )+ </code></pre> <p>that I've seen suggested in several places does not work.<br> Is this a limitation in the particular PEG-implementation, PEG in itself or (hopefully) my methods?</p> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload