How to maka a rule LL(*) while preserving semantics? [message #1767318] |
Tue, 04 July 2017 15:49 |
David Black Messages: 33 Registered: June 2017 |
Member |
|
|
Hi,
whenever I have a rule like this:
XText asks me for applying left-refactoring. On paper, I'd do it like this:
A -> cC | "a"
C -> A | AB
(...)
But in XText you don't have "null" rules, I believe. So I do it by mixing in regular expressions:
And XText seems to swallow it as a "left refactorization".
The problem is that in my parsed model I want cA and cAB to mean different things and to be mapped into different ECore classes, and as I understand, my "regular expression" impedes that.
Let's show it on a real XText snippet. How can I make the following rule LL(*) and at the same time get different and meaningful ECore classes for alternatives 2 and 3?
terminal TYPE:
ID |
('(' TYPE ')') |
('(' TYPE ')' 'throws')
;
I've tried this hoping that it would guide XText throughout choices, but it did not work:
terminal TYPE:
ID |
COMPLICATED_TYPE
;
terminal fragment COMPLICATED_TYPE:
('(' TYPE ')') |
COMPLICATED_TYPE_WITH_THROWS
;
terminal fragment COMPLICATED_TYPE_WITH_THROWS:
('(' TYPE ')' 'throws')
;
Cheers, David.
[Updated on: Tue, 04 July 2017 15:50] Report message to a moderator
|
|
|
|
Re: How to maka a rule LL(*) while preserving semantics? [message #1767323 is a reply to message #1767321] |
Tue, 04 July 2017 16:11 |
David Black Messages: 33 Registered: June 2017 |
Member |
|
|
OK, my mistake.
I wish to rewrite a rule so that
1) Get's converted into LL(*), because XText complains that the rules it's not LL(*)
2) Ensures that I will have different generated classes for these two parsed lines:
(mytype)
and
(mytype) throws
The rule I want to fix is this one, TYPE:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
greetings+=Greeting*;
Greeting:
name=TYPE;
terminal TYPE:
ID |
('(' TYPE ')') |
('(' TYPE ')' 'throws')
;
[Updated on: Tue, 04 July 2017 16:14] Report message to a moderator
|
|
|
|
|
Re: How to maka a rule LL(*) while preserving semantics? [message #1767329 is a reply to message #1767324] |
Tue, 04 July 2017 16:32 |
David Black Messages: 33 Registered: June 2017 |
Member |
|
|
Thanks for the solution!
Hmm, those are actions, aren't they? I'm afraid I still can't understand them well. I wasn't able to make much from the official documentation.
Anyway, that '=>' symbol... so that's the solution, right? I read in the official docs that it "tells" XText which option to choose on ambiguous cases. However I did not look at it as an alternative because I still don't understand how to use it in most of the cases.
Anyway, I will use it in this case ;)
Thanks again!
[Updated on: Tue, 04 July 2017 16:34] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04127 seconds