Decision can match input such as "RULE_ID '=' RULE_ID" [message #903916] |
Mon, 27 August 2012 09:05 |
Tu Do Messages: 21 Registered: August 2012 |
Junior Member |
|
|
This is my sample grammar rules:
grammar org.xtext.example.mydsl1.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl ""
START:
{START}
features += (NUM_SYMBOL | STR_SYMBOL | VARIABLE | STRING_VARIABLE | SET)*';'
;
//Declaration
VARIABLE:
'VARIABLE' name=ID ('[' INT ']' ('[' INT ']')* )? '=' content = ID ';'
;
STRING_VARIABLE:
'STRING' name=ID '=' STRING ';'
;
NUM_SYMBOL:
'NUM SYMBOL' ID '=' content = ID ';'
;
STR_SYMBOL:
'SYMBOL' name = ID '=' content = ID ';'
;
//Definition (or assignments, can either be string or number)
SET:
'SET' (VAR_ASSIGNMENT | STRING_ASSIGNMENT) ';'
;
//array assignment works too
VAR_ASSIGNMENT:
name = [VARIABLE] ('[' INT ']' ('[' INT ']')* )? '=' ASSIGNED_VALUE
;
ASSIGNED_VALUE:
{ASSIGNED_VALUE}
INT | name = [NUM_SYMBOL]
;
STRING_ASSIGNMENT:
name = [STRING_VARIABLE] '=' (STRING | ref = STR_SYMB_REF)
;
STR_SYMB_REF:
name = [STR_SYMBOL]
;
It generates warning: warning(200): ../au.com.dektech.plex.ide.ui/src-gen/au/com/dektech/plex/ide/ui/contentassist/antlr/internal/InternalPLEX.g:1159:1: Decision can match input such as "RULE_ID '=' RULE_ID" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
It seems that Xtext can't resolve same rule with different references. However, assignment usually uses the same rule. For example:
/* Declare */
int var1;
String var2;
/* Define */
//This assignment should refer to declared var1 (integer declaration only)
var1 = 10;
//This assignment should refer to declared var2 (string declaration only)
var2 = "Test";
I don't want to merge different types of assignment into one generic assignment rule. How can I fix this?
[Updated on: Mon, 27 August 2012 10:45] Report message to a moderator
|
|
|
|
|
|
Re: Decision can match input such as "RULE_ID '=' RULE_ID" [message #903966 is a reply to message #903942] |
Mon, 27 August 2012 13:04 |
Tu Do Messages: 21 Registered: August 2012 |
Junior Member |
|
|
Tobias Mayer wrote on Mon, 27 August 2012 07:36When I generated the language infrastructure, a further error message appears:
constraint is INVALID for context SET and type VAR_ASSIGNMENT
constraint is INVALID for context VAR_ASSIGNMENT and type VAR_ASSIGNMENT
When I modify your SET rule to:
SET:
'SET' ( => VAR_ASSIGNMENT | STRING_ASSIGNMENT) ';'
;
the error message mentioned by you disappears.
Best Regards,
Tobias
Hi Tobias,
are you sure there's no additional warnings? When I copied back the grammar above and generated the language artifacts, it has the following warnings:
constraint is INVALID for context SET and type VAR_ASSIGNMENT
constraint is INVALID for context VAR_ASSIGNMENT and type VAR_ASSIGNMENT
warning(200): ../org.xtext.example.mydsl/src-gen/org/xtext/example/mydsl/parser/antlr/internal/InternalMyDsl.g:468:1: Decision can match input such as "RULE_ID '=' RULE_ID" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../org.xtext.example.mydsl.ui/src-gen/org/xtext/example/mydsl/ui/contentassist/antlr/internal/InternalMyDsl.g:442:1: Decision can match input such as "RULE_ID '=' RULE_ID" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
However, when I changed the rule according to your suggestion, the "warning(200)" message vanished, but the constraint warnings remained. What exactly does this operator "=>" do? And what is the constraint warnings suggesting?
Thanks.
[Updated on: Mon, 27 August 2012 13:05] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04042 seconds