Note that there are some explanatory texts on larger screens.

plurals
  1. POANTLR fuzzy parsing
    primarykey
    data
    text
    <p>I'm building a kind of pre-processor in ANTLRv3, which of course only works with fuzzy parsing. At the moment I'm trying to parse include statements and replace them with the corresponding file content. I used this example:</p> <p><a href="https://stackoverflow.com/questions/13347997/antlr-removing-clutter">ANTLR: removing clutter</a></p> <p>Based on this example, I wrote the following code:</p> <pre><code>grammar preprocessor; options { language='Java'; } @lexer::header { package antlr_try_1; } @parser::header { package antlr_try_1; } parse : (t=. {System.out.print($t.text);})* EOF ; INCLUDE_STAT : 'include' (' ' | '\r' | '\t' | '\n')+ ('A'..'Z' | 'a'..'z' | '_' | '-' | '.')+ { setText("Include statement found!"); } ; Any : . // fall through rule, matches any character ; </code></pre> <p>This grammar does only for printing the text and replacing the include statements with the "Include statement found!" string. The example text to be parsed looks like this:</p> <pre><code>some random input some random input some random input include some_file.txt some random input some random input some random input </code></pre> <p>The output of the result looks in the following way:</p> <pre><code>C:\Users\andriyn\Documents\SandBox\text_files\asd.txt line 1:14 mismatched character 'p' expecting 'c' C:\Users\andriyn\Documents\SandBox\text_files\asd.txt line 2:14 mismatched character 'p' expecting 'c' C:\Users\andriyn\Documents\SandBox\text_files\asd.txt line 3:14 mismatched character 'p' expecting 'c' C:\Users\andriyn\Documents\SandBox\text_files\asd.txt line 7:14 mismatched character 'p' expecting 'c' C:\Users\andriyn\Documents\SandBox\text_files\asd.txt line 8:14 mismatched character 'p' expecting 'c' C:\Users\andriyn\Documents\SandBox\text_files\asd.txt line 9:14 mismatched character 'p' expecting 'c' some random ut some random ut some random ut Include statement found! some random ut some random ut some random ut </code></pre> <p>As far as I can judge, it is confused by the "in" in the word "input", because it "thinks" it would be the INCLUDE_STAT token.</p> <p>Is there a better way to do it? The filter option I cannot use, since I need not only the include statements, but also the rest of the code. I've tried several other things, but couldn't find a proper solution.</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