Rules priority xtext [message #1735763] |
Wed, 22 June 2016 10:25  |
Eclipse User |
|
|
|
Hi,
I made a grammar that provides functions and variables use. There are 2 types of functions my program will use:
First are functions developed by user in files. My rule for this function call is:
FunctionCall:
functionName=[newFunction|STR] '('(arguments+=[Assignable|STR] ',')* arguments+=[Assignable|STR] ')'
;
"newFunction" is a link to a function declaration rule
Second are functions directly developed in the program by me. The difference with previous rule is that the name is already definded. For example:
BarToPSI:
'BarToPSI('input=[Assignable|STR] ',' output=[Assignable|STR]')'
;
Here, there is no function declaration
Of course, there is a conflict between these 2 rules. Is there a way to define a priority on this ? I mean, how could I say to xtext to choose the second rule if there is a conflict ?
|
|
|
|
Re: Rules priority xtext [message #1735770 is a reply to message #1735765] |
Wed, 22 June 2016 10:54   |
Eclipse User |
|
|
|
Hi Chistian,
here is a minimal version of my grammar:
Script:
instructions+=Instruction*;
Instruction:
statemement=Statement ';' |
call=FunctionCall ';'
Statement:
function=BarToMBar
BarToMBar:
'BarToMBar('input=[Assignable|STR] ',' output=[Assignable|STR]')'
;
FunctionCall:
functionName=[newFunction|STR] '('(arguments+=[Assignable|STR] ',')* arguments+=[Assignable|STR] ')'
;
CalcDeclaration returns newFunction:
'def' name=STR '('inParameters+=InVariable (',' inParameters+=InVariable )* (',' outParameters+=OutVariable)* ')' '{'
instructions+=Instruction*
'}'
;
terminal STR : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'\\')*;
ANTLR returns this to me:
warning(200): ../fr.snecma.saturne.script/src-gen/fr/snecma/saturne/script/parser/antlr/internal/InternalScript.g:1210:1: Decision can match input such as "RULE_STRING" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../fr.snecma.saturne.script/src-gen/fr/snecma/saturne/script/parser/antlr/internal/InternalScript.g:3476:2: Decision can match input such as "'-'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
|
|
|
|
|
|
|
Re: Rules priority xtext [message #1735779 is a reply to message #1735778] |
Wed, 22 June 2016 11:36  |
Eclipse User |
|
|
|
as i said: when i cannot reproduce this i cannot tell
setting
Expression value=ID does not help to make it fail.
did you have a look at the generated antlr file in the lines
1210 and 3476
it is complaining about "-" and the STRING rule which both are not used in what you posted
|
|
|
Powered by
FUDForum. Page generated in 0.11029 seconds