Multiple antlr alternatives
I have this simple grammar for C # type syntax. I cannot find a way to separate fields and methods. All the examples I have seen for parsing C # combine fields and methods in the same rule. I would like to separate them as my syntax is pretty simple.
grammar test;
options
{
language =CSharp2;
k = 3;
output = AST;
}
SEMI : ';' ;
LCURLY : '{' ;
RCURLY : '}' ;
LPAREN : '(' ;
RPAREN : ')' ;
DOT :'.';
IDENTIFIER
: ( 'a'..'z' | 'A'..'Z' | '_' )
( 'a'..'z' | 'A'..'Z' | '_' | '0'..'9' )*
;
namespaceName
: IDENTIFIER (DOT IDENTIFIER)*
;
classDecl
: 'class' IDENTIFIER LCURLY (fieldDecl | methodDecl)* RCURLY
;
fieldDecl
: namespaceName IDENTIFIER SEMI;
methodDecl
: namespaceName IDENTIFIER LPAREN RPAREN SEMI;
I always end this warning
Decision can match input such as "IDENTIFIER DOT IDENTIFIER" using multiple alternatives: 1, 2
+2
a source to share