[antlr-interest] [newbie] Quoted identifiers vs. string literals
Charles Daniels
cjdaniels4 at gmail.com
Sun Mar 18 08:22:00 PDT 2012
I am very new to ANTLR and I having trouble properly defining part of a
grammar that I am constructing to recognize a specialized configuration
file syntax (already defined, so I cannot change it).
The trouble I am having is recognizing the following type of entry in the
config file:
"name" type "value"
where the following rules apply:
1. The double quotes are a required part of the syntax, both for the
name and the value.
2. A "name" is essentially a Java identifier
3. A "value" is a string literal
I have the following grammar so far:
triplet : IDENTIFIER type STRINGLITERAL ;
type : 'Boolean' | 'Integer' | 'String' ;
STRINGLITERAL : (copied from Java.g)
IDENTIFIER : '"' IdentifierStart IdentifierPart* '"' ;
IdentifierStart : (copied from Java.g)
IdentifierPart : (copied from Java.g)
When I compile this grammar, ANTLR hangs. When I remove the double quotes
from IDENTIFIER, it compiles successfully. I am guessing that when I
include the double quotes in IDENTIFIER they are somehow causing the
compilation to hang due to the double quotes that are also in STRINGLITERAL.
Does anybody have any suggestions on how to define this so that I can use
double quotes around names and values and the compiler doesn't hang?
Thanks,
Chuck
More information about the antlr-interest
mailing list