Hi,
I believe there is a bug in the antlr grammar generation code.
Below is my grammar (it is a subset of the Standard ML grammar):
grammar es.afluent.telluride.Ur hidden (WS)
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate ur "http ://www.afluent.es/telluride/Ur"
Prog
: (declarations += Dec ';'?)*
;
Dec
: 'type' (typeBindinds += TypBind) ('and' typeBindinds += TypBind)*
| 'datatype' dataTypeBindings += DatBind ('and' dataTypeBindings += DatBind)*
('withtype' (typeBindinds += TypBind) ('and' typeBindinds += TypBind)*)?
;
TypBind
: ( variables += TypeVariableDeclaration
| '(' variables += TypeVariableDeclaration (',' variables += TypeVariableDeclaration)* ')'
)? name = ID ('=' type = Typ)?
;
TypeVariableDeclaration
: name = VAR
;
Typ
: FunctionType
;
FunctionType returns Typ
: TupleType ('->' {FunctionType.domain = current} codomain = FunctionType)?
;
TupleType returns Typ
: TupleTypeElement ('*' {TupleType.elements += current} elements += TupleTypeElement
('*' elements += TupleTypeElement)*)?
;
TupleTypeElement returns Typ
: RecordType
| TypeConstructorApplication
;
RecordType
: '{' fields += Field (',' fields += Field)* '}'
;
Field
: id = ID ':' type = Typ
;
TypeConstructorApplication returns Typ
: (TypeReference | TypeVariableReference) ({TypeConstructorApplication.arguments += current} constructor = TypeReference)*
| '(' Typ (
')' ({TypeConstructorApplication.arguments += current} constructor = TypeReference)*
| ',' {TypeConstructorApplication.arguments += current} arguments += Typ
(',' arguments += Typ)* ')' constructor = TypeReference
({TypeConstructorApplication.arguments += current} constructor = TypeReference)*
)
;
TypeReference
: type = [TypBind]
;
TypeVariableReference
: variableName = VAR
;
DatBind returns TypBind
: ( variables += TypeVariableDeclaration
| '(' variables += TypeVariableDeclaration (',' variables += TypeVariableDeclaration)* ')'
)? name = ID '=' constructors += ConBind ('|' constructors += ConBind)*
;
ConBind
: name = ID ('of' type = Typ)?
;
terminal VAR
: '\''? '\'' ID_FRAGMENT
;
terminal ID
: ID_FRAGMENT
;
terminal LONG_ID
: ID_FRAGMENT ('.' ID_FRAGMENT)*
;
terminal fragment ID_FRAGMENT
: ('a' .. 'z' | 'A' .. 'Z') ('a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '\'' | '_')*
;
terminal WS
: (' ' | '\t' | '\r' | '\n')+
;
If I change the rule
TypeVariableReference
: variableName = VAR
;
to
TypeVariableReference
: variable = [TypeVariableDeclaration]
;
antlr complains saying
warning(200): ../es.afluent.telluride/src-gen/es/afluent/telluride/parser/antlr/internal/InternalUr.g:802:4: Decision can match input such as "RULE_ID" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
error(201): ../es.afluent.telluride/src-gen/es/afluent/telluride/parser/antlr/internal/InternalUr.g:802:4: The following alternatives can never be matched: 2
It seems that the problem is that when I change the rule, the associated rule in the generated antlr grammar changes from
// Rule TypeVariableReference
ruleTypeVariableReference returns [EObject current=null]
@init {
enterRule();
}
@after {
leaveRule();
}:
(
(
lv_variableName_0_0=RULE_VAR
/* ... */
to
// Rule TypeVariableReference
ruleTypeVariableReference returns [EObject current=null]
@init {
enterRule();
}
@after {
leaveRule();
}:
(
(
{
if ($current==null) {
$current = createModelElement(grammarAccess.getTypeVariableReferenceRule());
}
}
otherlv_0=RULE_ID
/* ... */
i.e., rather than referencing RULE_VAR, it is referencing RULE_ID.
Is this really a bug? Is there a way to work around it?
PS: I am sending this message again because I could not find the first one in the forum. Sorry for duplicates!
Any help would be very appreciated,
Saulo