Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Rules priority xtext
Rules priority xtext [message #1735763] Wed, 22 June 2016 14:25 Go to next message
Josselin Kerdraon is currently offline Josselin KerdraonFriend
Messages: 29
Registered: February 2016
Junior Member
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 14:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13710
Registered: July 2009
Senior Member
actually there is no conflict

at least not with deeper knowlege of STR rule

can you give a complete minimal grammar illustrating your problem


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Rules priority xtext [message #1735770 is a reply to message #1735765] Wed, 22 June 2016 14:54 Go to previous messageGo to next message
Josselin Kerdraon is currently offline Josselin KerdraonFriend
Messages: 29
Registered: February 2016
Junior Member
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 15:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13710
Registered: July 2009
Senior Member
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)


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Rules priority xtext [message #1735773 is a reply to message #1735772] Wed, 22 June 2016 15:15 Go to previous messageGo to next message
Josselin Kerdraon is currently offline Josselin KerdraonFriend
Messages: 29
Registered: February 2016
Junior Member
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 15:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13710
Registered: July 2009
Senior Member
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


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Rules priority xtext [message #1735778 is a reply to message #1735775] Wed, 22 June 2016 15:31 Go to previous messageGo to next message
Josselin Kerdraon is currently offline Josselin KerdraonFriend
Messages: 29
Registered: February 2016
Junior Member
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 15:36 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13710
Registered: July 2009
Senior Member
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


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Using forEach correctly
Next Topic:port existing Eclipse Plugin to Intellij
Goto Forum:
  


Current Time: Wed Jan 20 20:43:24 GMT 2021

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

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

Back to the top