Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This appears to be a bug in ANTLRWorks 1.4. You could try with ATLRWorks 1.3 (or earlier), perhaps that version works properly (I did a quick check with v1.4 only!).</p> <p>From the console, both your example strings (<code>"abc"</code> and <code>"\nabc"</code>) are being parsed without any problems. Here's my test-rig and the corresponding output:</p> <pre><code>grammar test; start : STRING {System.out.println("parsed :: "+$STRING.text);} EOF ; WS : (' ' | '\t' | '\r' | '\n') {$channel=HIDDEN;} ; STRING : '"' ( ESC_SEQ | ~('\\'|'"') )* '"' ; fragment HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ; fragment ESC_SEQ : '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\') | UNICODE_ESC | OCTAL_ESC ; fragment OCTAL_ESC : '\\' ('0'..'3') ('0'..'7') ('0'..'7') | '\\' ('0'..'7') ('0'..'7') | '\\' ('0'..'7') ; fragment UNICODE_ESC : '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT ; </code></pre> <p>Note that the grammar is the same as yours, only formatted a bit different.</p> <p>And the "main" class:</p> <pre><code>import org.antlr.runtime.*; public class Demo { public static void main(String[] args) throws Exception { ANTLRStringStream in = new ANTLRStringStream(args[0]); testLexer lexer = new testLexer(in); CommonTokenStream tokens = new CommonTokenStream(lexer); testParser parser = new testParser(tokens); parser.start(); } } </code></pre> <p>Now from the console you create a parser and lexer:</p> <pre><code>java -cp antlr-3.2.jar org.antlr.Tool test.g </code></pre> <p>Compile all .java source files:</p> <pre><code>javac -cp antlr-3.2.jar *.java </code></pre> <p>and run the "main" class:</p> <pre><code>java -cp .:antlr-3.2.jar Demo \"\\nabc\" // output: parsed :: "\nabc" java -cp .:antlr-3.2.jar Demo \"abc\" // output: parsed :: "abc" </code></pre> <p><em>(for Windows, replace the <code>:</code> with a <code>;</code> in the commands above)</em></p> <p>Note that the command line parameters above are examples run on Bash, where the <code>"</code> and <code>\</code> need to be escaped: this may be different on your system. But as you can see from the output: both <code>"\nabc"</code> and <code>"abc"</code> get parsed properly.</p> <p>ANTLRWorks is a great tool for editing grammar files, but (in my experience) has quite a bit of such funny bugs in it. That's why I only edit the grammar(s) with it and generate, compile and test the files on the console as I showed you.</p> <p>HTH</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. 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.
    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