Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Getting value of parser rules during runtime(How to get value of a rule during runtime while specifying the language)
Getting value of parser rules during runtime [message #1075283] Mon, 29 July 2013 07:14 Go to next message
Priya Sabut is currently offline Priya SabutFriend
Messages: 41
Registered: September 2012
Member
Hi All,
I am writing grammar to parse a specific type of command. Where I parse the command depending on some separator. My command has a header and body separated by 'header-boby separator'. Again the body part consists of one or more parameters separated with a 'parameter separator'. The parameter can be value-only or a name-value pair delimited with 'name-value delimiter'. For a specific element, the commands have different separators(they can be same also, to make it simple I am considering commands with unique separators).

For example:
The commands for element -1 is "Header1 : Param11=value11, value12, param13 = value13", where colon(: ) is header-body separator, comma (,) is parameter separator and equal(=) is name-value delimiter.

The commands for element -2 is "Header2, value21: param22 - value22: param23 - value23", where comma(,) is header-body separator, colon(: ) is parameter separator and dash(-) is name-value delimiter.

If both the rules - HEADERDELIMITER and PARAMSEPARATOR has same value (':' | ','), I get parser error while running xtext file. As they are conflicting with each other. Sad

To parse commands for both the elements I have to create two xtext files with different separator values for both conflicting rules, which is not a good way!

Can I somehow get these separators during runtime while specifying the language. In my language if I specify
Language::

'headerBodySeparator :' //the value colon (: ) should be the value of rule HEADERDELIMITER.

Rule Definition ::
HEADERDELIMITER :
valueOf(headerBodySeparator) ;

My grammar below::

DomainModel:
(commands += Command+)
;
Command:
header = Header (blocks += Block*) tail=Tail
;
Block hidden(WS,ML_COMMENT,SL_COMMENT):
{Block}
(segSep=HEADERDELIMITER) (paramSet+=ParameterSet*)
;
ParameterSet:
{ParameterSet}
param = CommandParameter (paramSep = PARAMSEPARATOR?)
;
CommandParameter:
valueOnly = ValueOnly | nameValuePair = NameValuePair
;
ValueOnly:
name=ValidID
;
NameValuePair:
name=ValidID sep = Assign (variableName=Variable | literal=CommandLiteral)
;
Variable:
'<' name= IDORINT'>';
CommandLiteral:
name = IDORINTORSTRING
;
IDORINT:
(ValidID | INT)
;
IDORINTORSTRING:
(IDORINT | STRING)
;
Header:
name=ValidID
;
HEADERDELIMITER:
(':' | ',')
;
Tail:
(';')
;
PARAMSEPARATOR:
(':' | ',')
;
Assign:
('=' | '-')
;

Thank you in advance...
Re: Getting value of parser rules during runtime [message #1075581 is a reply to message #1075283] Mon, 29 July 2013 17:21 Go to previous messageGo to next message
Priya Sabut is currently offline Priya SabutFriend
Messages: 41
Registered: September 2012
Member
Any help please ...

Is it possible in xtext ? I want to get some rule values(tokens) during runtime...
Re: Getting value of parser rules during runtime [message #1075587 is a reply to message #1075581] Mon, 29 July 2013 17:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i did not really get the problem but you can quire the node model via NodeModelUtils (from an eobject)
and then traverse the node model (and ask it for grammar elements like parser rules)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting value of parser rules during runtime [message #1075599 is a reply to message #1075587] Mon, 29 July 2013 18:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hmmm i read your post once more. i dont think this is possible/ a viable option.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting value of parser rules during runtime [message #1075603 is a reply to message #1075599] Mon, 29 July 2013 18:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Btw if the grammar is ambigous what is the expected output?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting value of parser rules during runtime [message #1075833 is a reply to message #1075283] Tue, 30 July 2013 06:53 Go to previous messageGo to next message
Priya Sabut is currently offline Priya SabutFriend
Messages: 41
Registered: September 2012
Member
Hi Christian,

Thank you for your reply.

The grammar is becoming ambiguous, If it is focusing to parse the commands that are targeted to multiple target elements. But for a single element It is not ambiguous as the separators will be different.

For example:

For Target Element-1 : header delimiter is colon(: ), parameter separator is comma(,), name-value delimiter is equal(=).
For Target Element-2 : header delimiter is comma(,), parameter separator is colon(: ), name-value delimiter is equal(-).

At a time, I will be processing commands for either Element-1 or Element-2 not both.

So my idea is to provide all the delimiters before putting the command, Somewhat similar to below statement :

For Element -1
//Define all the separators
define HeaderDelimiter :
define ParameterSeparator ,
define Name-ValueDelimiter =

//Put the command
Header:parm1=val1,parm2,parm3=val

For Element -2
//Define all the separators
define HeaderDelimiter ,
define ParameterSeparator :
define Name-ValueDelimiter -

//Put the command
Header,parm1=val1:parm2:parm3-val

So that I an use these delimiter values(provided in the language) in the grammar to specify the parser rule.

I hope, I conveyed my problem to you.

Is there any other way to solve the same problem described ? Please share...
Re: Getting value of parser rules during runtime [message #1075841 is a reply to message #1075833] Tue, 30 July 2013 07:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Dry I don't have a fast idea for that

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting value of parser rules during runtime [message #1076296 is a reply to message #1075841] Wed, 31 July 2013 05:56 Go to previous messageGo to next message
Priya Sabut is currently offline Priya SabutFriend
Messages: 41
Registered: September 2012
Member
Okay...

Can the design of the grammar may change to handle this problem ?
Re: Getting value of parser rules during runtime [message #1076302 is a reply to message #1076296] Wed, 31 July 2013 06:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
sorry i dont have the time to give this a deep digg. but i still do not understand how you solve the amiguity on business level if both separators are the same.
how do you distinguish a new Block from another CommandParameter ????


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Wed, 31 July 2013 06:12]

Report message to a moderator

Re: Getting value of parser rules during runtime [message #1076330 is a reply to message #1076302] Wed, 31 July 2013 07:25 Go to previous message
Priya Sabut is currently offline Priya SabutFriend
Messages: 41
Registered: September 2012
Member
I construct the command using java and put the appropriate separator as defined. And those constructed command will be sent to the targeted element. Here the target elements are different for different set of parameters.

As described in previous message,
for element -1, it knows that a block starts with a colon and parameters are being separated by comma and
for Element-2, it knows a block starts with a comma and parameter are being separated by colon.
Previous Topic:Xtext 2.4.2: What is CancelationIndicator ?
Next Topic:Get CharSequence from JvmOperation object
Goto Forum:
  


Current Time: Thu Apr 25 12:52:24 GMT 2024

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

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

Back to the top