Reputation: 2963
I am trying to match ***
, but I find that javacc matches ***
anywhere in the line. How do I make sure that it only matches ***
when there are no other characters other than spaces or tabs before ***
? This is what I currently have
< HORIZONTAL_RULE: <ZERO_OR_MORE_OF_TAB_OR_SPACE> ("**")("*")+>
| <#ZERO_OR_MORE_OF_TAB_OR_SPACE: (" " | "\t")*>
But again, this matches any ***
prepended by zero or more spaces.
Upvotes: 0
Views: 212
Reputation: 16221
Use lexical states. Use the DEFAULT state for the start of a line.
// Note that states do not apply to private regular expression definitions.
TOKEN: <#ZERO_OR_MORE_OF_TAB_OR_SPACE: (" " | "\t")*>
<DEFAULT> TOKEN: {
<HORIZONTAL_RULE: <ZERO_OR_MORE_OF_TAB_OR_SPACE> ("**")("*")+ > : MIDLINE
}
<DEFAULT, MIDLINE> SKIP { <OTHERCHAR: ~["\n","\r"]> : MIDLINE }
<DEFAULT, MIDLINE> SKIP { <NEWLINE: "\n" | "\n\r" | "\r" | "\r\n"> : DEFAULT }
Upvotes: 1