Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using "~[]" token with lexical states

Tags:

javacc

I'm trying to write a javacc-based parser that involves the following tokens / lexical states:

TOKEN :
{
  <"{"> : FIRST
}
<FIRST, DEFAULT> TOKEN :
{
  <"~[]"> : DEFAULT
}

Trying to parse "{;}" results in the lexical error

Encountered: ";" (59), after : ""

which I don't understand. I can avoid the error in two ways:

  • by replacing the "~[]" pattern by an explicit ";" literal
  • by removing the FIRST lexical state

However, I do need both of these (as you can guess, the above is just a minimal test case), so this isn't a suitable workaround. Any idea what is wrong with the above token definition ?

Thanks !

like image 626
Stefan Seefeld Avatar asked Nov 09 '22 14:11

Stefan Seefeld


1 Answers

Too many quote marks. What you want is

TOKEN :
{
  <"{"> : FIRST
}
<FIRST, DEFAULT> TOKEN :
{
  <~[]> : DEFAULT
}
like image 184
Theodore Norvell Avatar answered Jan 04 '23 01:01

Theodore Norvell