Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>.+?</code> at the end of a lexer rule will always match a single character. But <code>.+</code> will consume as much as possible, which was illegal at the end of a rule in ANTLR v3 (v4 probably as well).</p> <p>What you can do is just match a single char, and "glue" these together in the parser:</p> <pre><code>unknowns : Unknown+ ; ... Unknown : . ; </code></pre> <h2>EDIT</h2> <blockquote> <p>... but I only have a lexer, no parsers ...</p> </blockquote> <p>Ah, I see. Then you could override the <code>nextToken()</code> method:</p> <pre class="lang-java prettyprint-override"><code>lexer grammar Lex; @members { public static void main(String[] args) { Lex lex = new Lex(new ANTLRInputStream("foo, bar...\n")); for(Token t : lex.getAllTokens()) { System.out.printf("%-15s '%s'\n", tokenNames[t.getType()], t.getText()); } } private java.util.Queue&lt;Token&gt; queue = new java.util.LinkedList&lt;Token&gt;(); @Override public Token nextToken() { if(!queue.isEmpty()) { return queue.poll(); } Token next = super.nextToken(); if(next.getType() != Unknown) { return next; } StringBuilder builder = new StringBuilder(); while(next.getType() == Unknown) { builder.append(next.getText()); next = super.nextToken(); } // The `next` will _not_ be an Unknown-token, store it in // the queue to return the next time! queue.offer(next); return new CommonToken(Unknown, builder.toString()); } } Whitespace : [ \t\n\r]+ -&gt; skip ; Punctuation : [.,:;?!] ; Unknown : . ; </code></pre> <p>Running it:</p> <pre>java -cp antlr-4.0-complete.jar org.antlr.v4.Tool Lex.g4 javac -cp antlr-4.0-complete.jar *.java java -cp .:antlr-4.0-complete.jar Lex</pre> <p>will print:</p> <pre>Unknown 'foo' Punctuation ',' Unknown 'bar' Punctuation '.' Punctuation '.' Punctuation '.'</pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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