What is the current status of Antlr3's Javascript target? I attempted to generate a parser for a simple grammar, but encountered numerous compiler errors in the generated code. After investigating the website, I downloaded the latest antlr3.5-snapshot code and compiled antlr from the source using Maven. However, the issues persist. Is there a specific version that I should be using, or is the Javascript target simply broken? (I found discussions about the target being broken in versions 3.1 and 3.2, working fine in 3.3, but no information on versions 3.4 and 3.5)
// public class variables
var = ,
= ,
= ,
...
= ,
= ;
The generated lexer and parser files contain more snippets of problematic Javascript code.
Any advice or guidance would be greatly appreciated.
Below is a basic test grammar that I utilized to experiment with Javascript code generation. Most of it was automatically generated by Antlrworks. I included the target language and the "prog" rule. (Please refrain from spending excessive time trying to modify this grammar to function correctly. Antlrworks validated the grammar and Java code generation works properly. Therefore, Javascript code generation should theoretically work without major modifications. Thanks once again for your assistance.
grammar TestgrammarV001;
options {
language=JavaScript;
}
prog : ID | INT;
ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
;
INT : '0'..'9'+
;
FLOAT
: ('0'..'9')+ '.' ('0'..'9')* EXPONENT?
| '.' ('0'..'9')+ EXPONENT?
| ('0'..'9')+ EXPONENT
;
COMMENT
: '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}
| '/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;}
;
WS : ( ' '
| '\t'
| '\r'
| '\n'
) {$channel=HIDDEN;}
;
STRING
: '"' ( ESC_SEQ | ~('\\'|'"') )* '"'
;
CHAR: '\'' ( ESC_SEQ | ~('\''|'\\') ) '\''
;
fragment
EXPONENT : ('e'|'E') ('+'|'-')? ('0'..'9')+ ;
fragment
HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;
fragment
ESC_SEQ
: '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
| UNICODE_ESC
| OCTAL_ESC
;
fragment
OCTAL_ESC
: '\\' ('0'..'3') ('0'..'7') ('0'..'7')
| '\\' ('0'..'7') ('0'..'7')
| '\\' ('0'..'7')
;
fragment
UNICODE_ESC
: '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
;