0

I have a skip

SKIP :
{
  " "
| "\t"
| "\n"
| "\r"
| "\f"
}

But I would like to define

TOKEN :
{
  < END_EXP: (";"|"\n") >
}

I don't want to remove "\n" from SKIP as I want it to be ignored for everything except when I'm expecting an END_EXP. How do I get javacc to skip "\n" only some of the time?

Ava
  • 2,038
  • 3
  • 23
  • 45
  • 1
    Can you define exactly which newlines should be skipped and which should not? Ideally you want some criteria that depends only on what has previously been lexed. For example, you might have a rule that says that all newlines are to be skipped apart from the ones that follow an identifier, literal, or right parenthesis. If you can't phrase the rule in purely lexical terms, you might want to solve your problem at the grammatical level. See, for example, http://stackoverflow.com/questions/26782747/how-to-implement-javascript-ecmascript-no-lineterminator-here-rule-in-javacc – Theodore Norvell Jun 16 '15 at 11:46
  • ... and see http://stackoverflow.com/questions/27069755/how-to-implement-javascript-automatic-semicolon-insertion-in-javacc?lq=1 – Theodore Norvell Jun 16 '15 at 11:47
  • Thank you, that was very helpful. – Ava Jun 16 '15 at 17:45

0 Answers0