I have apparently a mistake in the following language definition :
grammar Hello;
object :
ALL* NAME ALL* '{'
(ALL* | (ALL* NAME ALL* NAME)* | (ALL* object)*)*
'}' ALL*;
ALL :
(~('{' | '}' | '"'))+ -> skip; // All but braces and double quotes
NAME :
'"' ALL* '"';
When I'm trying to read a file or add content directly (with run.bat Hello object -gui
), the parser give me a syntax error :mismatched input '<EOF>' expecting NAME
.
And I just have a tree with a single node : 'object'.
Here is the Java source :
public static void main(String[] args) throws Exception {
HelloLexer lexer = new HelloLexer(new ANTLRFileStream("gamemodes.txt"));
TokenStream tokenStream = new CommonTokenStream(lexer);
HelloParser parser = new HelloParser(tokenStream);
System.out.println(lexer.getAllTokens().size());
parser.setBuildParseTree(true);
// Tree Creation
RuleContext tree = parser.object();
tree.inspect(parser);
}
And finally, the file structure (with some spaces/characters anywhere (without braces and double quotes)) :
...
"objName"
{
...
"innerObjName1"
{
"firstProperty" "firstResult"
...
"secondProp" ""
}
"innerObjName2"
{
"firstProperty" "firstResult"
"secondProp" ""
}
}
...
NOTE : I'm on Windows.
Thanks !
object
rule) with regex. I don't think antlr can handle that. Parser rules possess much simpler mechanics. – Marcelo Zabani