Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » letter-based depth structure
letter-based depth structure [message #1701002] Wed, 08 July 2015 15:12
Hendrik Motza is currently offline Hendrik MotzaFriend
Messages: 7
Registered: October 2014
Junior Member
Hi,

I have a DSL looking like this:

a: ...
   b: ...
      c: ...
      c: ...
         d: ...
a: ...
   b: ...
a: ...


'a:' defines the top elements which can be followed by other a-rules or they can contain b-rules as childrens. In the same way b-rules can only contain c-rules and so on. The deepest allowed letter is q.
All those rules are similar and should be mapped to the same java class. But now i have trouble to define a recursive grammar which maps these rules to children.
There are three situations on which the handling depends:
Adoption: We processed an a-rule and now we go on
Case 1: The next rule uses the next letter (b) and should therefore be stored in a children list of the current a-rule.
Case 2: The next rule is below the next letter (c or behind) which means this is a syntax error!
Case 3: The next rule is a rule of the same letter (a) or a letter above (not possible in this depth). In this case the a-rule is completely parsed and we can continue with the new a-rule which we have just discovered.

I have no idea how to write a grammar for this situation. I might need something like this:

Rule:
		depth=RULE_DEPTH content=STRING 
		// add rule as children only when depth is current+1
		children+=(Rule r matching r.depth==this.depth+1)*
;

terminal RULE_DEPTH returns ecore::EInt : ('a'..'q') ':';  // <- convert to numbers: a=1, b=2...


I'm not quite sure whether this is possible with xtext anyway, but probably someone knows better? Wink
Previous Topic:importURI with particular path syntax
Next Topic:Preferences page
Goto Forum:
  


Current Time: Tue Mar 19 03:15:22 GMT 2024

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

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

Back to the top