Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Help with recursive grammar
Help with recursive grammar [message #1792431] Tue, 17 July 2018 18:08 Go to next message
Eclipse UserFriend
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 14:08 Go to previous messageGo to next message
Eclipse UserFriend
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)
Re: Help with recursive grammar [message #1792504 is a reply to message #1792503] Wed, 18 July 2018 14:11 Go to previous messageGo to next message
Eclipse UserFriend
P.s:

if the tool creates the indentation aligned with the grand counts then you could try to use a std. indentation based language
Re: Help with recursive grammar [message #1792506 is a reply to message #1792504] Wed, 18 July 2018 14:23 Go to previous messageGo to next message
Eclipse UserFriend
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
		''')
Re: Help with recursive grammar [message #1792511 is a reply to message #1792506] Wed, 18 July 2018 15:37 Go to previous messageGo to next message
Eclipse UserFriend
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 15:39 Go to previous message
Eclipse UserFriend
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: Sun Jun 15 05:50:36 EDT 2025

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

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

Back to the top