There is now a syntax converter to convert legacy JavaCC (and some things in JavaCC 21) to the approved CongoCC syntax.
You can execute it as:
java -jar javacc-full.jar convert filename
That will spit it out to stdout. More likely you want something more like:
java -jar javacc-full.jar convert filename > outputfilename
The converter converts most of the gnarly things in legacy JavaCC. All those obligatory (in legacy JavaCC, but not in JavaCC 21) empty braces get eliminated. The pointless empty parentheses all over the place get eliminated as well. The legacy LOOKAHEAD
construct is replaced by SCAN
. Since JavaCC 21 (and Congo of course) do not require any void
return type for a production, those get eliminated.
The converter also handles PARSER_CODE_DECLS
and TOKEN_MGR_DECLS
, converting them to INJECT
statements. It converts things that existed in JavaCC 21 but may not exist in Congo, such as
=> Foo Bar Baz
now gets changed to:
Foo Bar Baz =>||
The conversion of LOOKAHEAD
to SCAN
is not perfect. It converts:
LOOKAHEAD(Foo()) Foo()
to:
SCAN Foo => Foo
but it should really convert it to:
Foo =>||
Likewise, it converts:
LOOKAHEAD(Foo() Bar()) Foo() Bar() Baz()
to:
SCAN Foo Bar => Foo Bar Baz
but it should really convert it to:
Foo Bar =>|| Baz
(I'll get that going at some point.)
I tried it on some various legacy JavaCC grammars in the wild and it basically seems to work. So, there it is. All feedback is welcome.