Search code examples
javaeljavaccparser-generator

javacc (ph-javacc-maven-plugin) generates java switch with case `\`


I'm a newly to javacc. I tried to parse an existing javacc grammar (its the JSR341, EL 3.0 Grammar). It generates (almost) correct java. However, the generated code contains an illegal switch statement. I'm using the ph-javacc-maven-plugin.

private int jjMoveStringLiteralDfa0_0(){
   switch(curChar)
   {
      case '#':
         return jjMoveStringLiteralDfa1_0(0x8L);
      case '$':
         return jjMoveStringLiteralDfa1_0(0x4L);
      case '\': // should be '\\'
         return jjStartNfaWithStates_0(0, 4, 2);
      default :
         return jjMoveNfa_0(7, 0);
   }
}

This is the offending grammar section from JS341 (although I'm not sure its the grammar itself) that's causing the problem:

<DEFAULT> TOKEN :
{
< LITERAL_EXPRESSION:
((~["\\", "$", "#"])
| ("\\" ("\\" | "$" | "#"))
| ("$" ~["{", "$"])
| ("#" ~["{", "#"])
)+
| "$"
| "#"
>
|
< START_DYNAMIC_EXPRESSION: "${" > {stack.push(DEFAULT);}:
IN_EXPRESSION
|
< START_DEFERRED_EXPRESSION: "#{" > {stack.push(DEFAULT);}:
IN_EXPRESSION
}
<DEFAULT> SKIP : { "\\" }

I played around with the options (JAVA_UNICODE_ESCAPE, UNICODE_INPUT) and grammar. But without result.

Question: how do I make javacc generate valid Java switch statement, i.e., with '\\' instead of '\'?


Solution

  • The observed behaviour is an issue and will be solved in parser-generator-cc 1.1.0.