Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Help with recursive grammar
Help with recursive grammar [message #1792431] Tue, 17 July 2018 22:08 Go to next message
Jean Macena is currently offline Jean MacenaFriend
Messages: 2
Registered: July 2018
Junior Member
Hello, guys. I would first like to apologize for my English (I am not a native English speaker).

I'm looking at Xtext to create a model of a scheme from an xml file. I was able to extract the xml's structure using Ruby with the gem Nokogiri. Now I have a txt file that tells me all the attributes and types of xml tags. I need to transform this file into a model that follows the attached image.

However, when trying to generate the nested structure I need I'm getting the error:

"decision can match input such as "'is'" using multiple alternatives: 1, 2
As a result, alternative (s) 2 were disabled for that input"

I saw this topic: https://www.eclipse.org/forums/index.php/t/1094040/
And it helps, but I feel like I can not really apply my situation.

My code so far:

Model: releaseSet += ClinVarSet*;

ClinVarSet:
	'is' 'child' 'ClinVarSet' 'id' Number=ID (children+=Child)*
;

Child:
	'is' GranChild 'child' Name=ID ('contentTag' Type+=TypeName)* (children+=Child)*
;

GranChild:
	('gran')+
;

TypeName:
	name = ID
;

Number:
	name = ID
;


This is what I would like to do:
index.php/fa/33426/0/

And this is my steps so far:
index.php/fa/33425/0/
Step 1 - Get the xml
Step 2 - Extract xml's structure
Step 3 - Create a grama for generates model with the result from Step 2

Thanks a lot.
Re: Help with recursive grammar [message #1792503 is a reply to message #1792431] Wed, 18 July 2018 18:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i have doubts this is easily possible.
you basically have a indentation-aware grammar (like python)
with no indentation but the indentation level beeing determined by counting the number of grans.

Maybe you can use the mechanism xtext has for such languages
(https://www.eclipse.org/Xtext/documentation/307_special_languages.html#whitespace-aware-languages) and customize the util that calculates the indentation
(AbstractIndentationTokenSource)
but this is not a beginner task for sure

so maybe we should do some steps back and try to understand what you actually want to solve.
so can you give some more background
(simply getting a model from an xml file can be done by std. emf means)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Help with recursive grammar [message #1792504 is a reply to message #1792503] Wed, 18 July 2018 18:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
P.s:

if the tool creates the indentation aligned with the grand counts then you could try to use a std. indentation based language


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Help with recursive grammar [message #1792506 is a reply to message #1792504] Wed, 18 July 2018 18:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
here an example

ClinVarSet:
	'is' 'child' 'ClinVarSet' 'id' Number=ID (BEGIN (children+=Child)* END)?
;

Child:
	'is' GranChild 'child' Name=ID (BEGIN (children+=Child)* END)?
;

GranChild:
	('gran')+
;

TypeName:
	name = ID
;

Number:
	name = ID
;

	
terminal BEGIN: 'synthetic:BEGIN';
terminal END: 'synthetic:END';
	@Test
	def void loadModel() {
		val result = parseHelper.parse('''
			 is child ClinVarSet id x
			  is gran child RecordStatus
			  is gran child Title
			  is gran child ReferenceClinVarAssertion
			   is gran gran child ClinVarAccession
			   is gran gran child RecordStatus
			   is gran gran child ClinicalSignificance
			    is gran gran gran child ReviewStatus
			    is gran gran gran child Description
			   is gran gran child Assertion
			   is gran gran child ObservedIn
		''')


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Help with recursive grammar [message #1792511 is a reply to message #1792506] Wed, 18 July 2018 19:37 Go to previous messageGo to next message
Jean Macena is currently offline Jean MacenaFriend
Messages: 2
Registered: July 2018
Junior Member
I will check this out. Thank you Christian :)
Re: Help with recursive grammar [message #1792512 is a reply to message #1792506] Wed, 18 July 2018 19:39 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

It is well known that REGEX grammars (that underpin the Xtext terminals) cannot count.

You might solve your problem by intercepting the token stream between lexer and parser so that e.g. "gran gran gran" returns an integer-valued GRAN terminal token of value 3.

Regards

Ed Willink
Previous Topic:Xtext Editor Show in Navigator not available
Next Topic:RPGLE - Keyword Parsing
Goto Forum:
  


Current Time: Fri Apr 19 03:32:54 GMT 2024

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

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

Back to the top