Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You must realize that the lexer does <em>not</em> produce tokens based on what the parser tries to match. So, in your case, the input <code>"5"</code> will always be tokenized as a <code>RANGE1_VALUES</code> and never as a <code>RANGE2_VALUES</code> because both <code>RANGE1_VALUES</code> and <code>RANGE2_VALUES</code> can match this input but <code>RANGE1_VALUES</code> comes first (so <code>RANGE1_VALUES</code> takes precedence over <code>RANGE2_VALUES</code>).</p> <p>A possible fix would be to remove both <code>RANGE1_VALUES</code> and <code>RANGE2_VALUES</code> rules and replace them with the following lexer rules:</p> <pre><code>D0_4 : '0'..'4' ; D5 : '5' ; D6_50 : '6'..'9' // 6-9 | '1'..'4' '0'..'9' // 10-49 | '50' // 50 ; A_B_C : ('a'|'A') | ('b'|'B') | ('c'|'C') ; </code></pre> <p>and the introduce these new parser rules:</p> <pre><code>range1_values : D0_4 | D5 | D6_50 ; range2_values : A_B_C | D5 ; </code></pre> <p>and change all <code>RANGE1_VALUES</code> and <code>RANGE2_VALUES</code> calls in your parser rules with <code>range1_values</code> and <code>range2_values</code> respectively.</p> <h2>EDIT</h2> <p>Instead of trying to solve this at the <em>lexer-level</em>, you might simply match any integer value and check inside the parser rule if the value is the correct one (or correct range) using a <em><a href="https://stackoverflow.com/questions/3056441/what-is-a-semantic-predicate-in-antlr">semantic predicate</a></em>:</p> <pre><code>range1_values : INT {Integer.valueOf($INT.text) &lt;= 50}? ; range2_values : A_B_C | INT {Integer.valueOf($INT.text) == 5}? ; INT : '0'..'9'+ ; A_B_C : 'a'..'c' | 'A'..'C' ; </code></pre>
 

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