lexer - Token for odd number of spaces -


i'm trying create token odd number of spaces. have

token : { < space: " " >  | < oddspace: <space> ((<space>)(<space>))* > }  void start() : {} {       <oddspace> } 

this fine 3, 5, 7...etc spaces, fails when try using once space. ideas why happening?

see question 3.3 of javacc faq. http://www.engr.mun.ca/~theo/javacc-faq/javacc-faq-moz.htm#tth_sec3.3

there 3 golden rules picking regular expression use identify next token:

  1. the regular expression must describe prefix of remaining input stream.
  2. if more 1 regular expression describes prefix, regular expression describes longest prefix of input stream used. (this called "maximal munch rule".)
  3. if more 1 regular expression describes longest possible prefix, regular expression comes first in .jj file used.

in case rule 3 applied. can rewrite start as

void start() : {} {       <oddspace> | <space>  } 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -