XText grammar with lookbehind [message #1756248] |
Tue, 14 March 2017 13:41 |
Stephan Pirnbaum Messages: 1 Registered: March 2017 |
Junior Member |
|
|
Hello,
I am new in developing a DSL using XText and I am currently stuck in a problem.
I have to parse a file which contains elements called Class and might look like this:
A {
B, //this comma is needed
C,
D {E}, //comma is optional after a closing curly brace
F {G}
H
}
I,
J
As you can see, a comma is a must after a class without subclasses (those enclosed by curly brackets) when another class follows. Otherwise, the comma is optional.
My current (wrong) solution is:
Model: (classes += Class)*
Class: name = ID ('{' (subclasses += Class) (',' subclasses += Class)* '}')?
Sadly, this works only when the comma is a must in any case. I believe the grammar should express the following structure:
Class: ID (',' Class | '{' subclasses += Class '}' ','? Class)?
Of course, that does not work since I need to assign the return value of Class to the subclasses of the parent. After some looking around different blogs, I belive that using a lookbehind would be a solution. However, I havn't found a way to express this in XText.
Is there a solution or a workaround for this issue?
Thanks in advance
Stephan
|
|
|
|
Powered by
FUDForum. Page generated in 0.05906 seconds