Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Rules priority xtext
Rules priority xtext [message #1735763] Wed, 22 June 2016 10:25 Go to next message
Eclipse UserFriend
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 #1735765 is a reply to message #1735763] Wed, 22 June 2016 10:36 Go to previous messageGo to next message
Eclipse UserFriend
actually there is no conflict

at least not with deeper knowlege of STR rule

can you give a complete minimal grammar illustrating your problem
Re: Rules priority xtext [message #1735770 is a reply to message #1735765] Wed, 22 June 2016 10:54 Go to previous messageGo to next message
Eclipse UserFriend
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 #1735772 is a reply to message #1735770] Wed, 22 June 2016 11:11 Go to previous messageGo to next message
Eclipse UserFriend
the grammar is not complete.

CalcDeclaration is uncalled. Assignable is undefined, same for InVariable and OutVariable

e.g.

InVariable and OutVariable

look likely to cause this (depending on the grammar)
Re: Rules priority xtext [message #1735773 is a reply to message #1735772] Wed, 22 June 2016 11:15 Go to previous messageGo to next message
Eclipse UserFriend
I forgot to copy this:

Script:
instructions+=Instruction*;

Instruction:
statemement=Statement ';' |
CalcDeclaration |
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*
'}'
;

VariableDeclaration returns newVariable:
InternVariable | ExternVariable
;

InternVariable:
'var' name=STR '=' (value=Expression)?
;

ExternVariable:
'ext var' name=STR '=' (value=Expression)?
;

Argument returns newArgument:
InVariable | OutVariable
;

InVariable:
'in var' name=STR ('=' value=Expression)?
;

OutVariable:
'out var' name=STR ('=' value=Expression)?
;

Assignable:
VariableDeclaration | Argument
;

terminal STR : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'\\')*;


I think there is all rules about variables and functions Wink
Re: Rules priority xtext [message #1735775 is a reply to message #1735773] Wed, 22 June 2016 11:23 Go to previous messageGo to next message
Eclipse UserFriend
first one tipp: never use spaces in keyword 'a b' => 'a' 'b'

then there is expression missing in your grammar.

so can you create a new project and try the grammar there to get a minimal reproducing example
Re: Rules priority xtext [message #1735778 is a reply to message #1735775] Wed, 22 June 2016 11:31 Go to previous messageGo to next message
Eclipse UserFriend
Well, Expression is almost the rest of my grammar (very big)

For information, all my grammar worked fine before I add this line:

BarToMBar:
'BarToMBar('input=[Assignable|STR] ',' output=[Assignable|STR]')'

Assignable is only used by BarToMBar and FunctionCall
Re: Rules priority xtext [message #1735779 is a reply to message #1735778] Wed, 22 June 2016 11:36 Go to previous message
Eclipse UserFriend
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
Previous Topic:Using forEach correctly
Next Topic:port existing Eclipse Plugin to Intellij
Goto Forum:
  


Current Time: Wed Jul 23 08:30:20 EDT 2025

Powered by FUDForum. Page generated in 0.11029 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top