Extend xbase with a more expressive range [message #1831563] |
Sun, 23 August 2020 18:34  |
Eclipse User |
|
|
|
Hi,
I am trying to extend Xbase to provide a more expressive range type. Basically I want to be able to write code like below:
var x = 9
var y = 15.0
(x..15) // evaluate to Range<Integer>.open(x,15)
[x..15) // evaluate to Range<Integer>.closedOpen(x, 15)
[x..y] // error, x and y have different types
Questions are:
1. Which type should I override in Xbase grammar? I was trying with XOtherOperatorExpression, but not sure if this is the right choice.
2. How to write the grammar? My version below gets error when tried to generate artifact from xtext.
@Override
XOtherOperatorExpression returns XExpression:
{Range}
(open='('|'[' left=XAdditiveExpression '..' right=XAdditiveExpression close= ')'|']') | super
;
Thanks in advance for any insight or hints!
|
|
|
|
Re: Extend xbase with a more expressive range [message #1831568 is a reply to message #1831567] |
Mon, 24 August 2020 01:24   |
Eclipse User |
|
|
|
Ed,
Thanks for the hint. What you said makes sense but I am afraid that I have not hit that yet. Here is the error:
error(211): ../...omitted.../parser/antlr/internal/InternalScg.g:238:2: [fatal] rule ruleXOtherOperatorExpression has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
warning(200): ../...omitted.../parser/antlr/internal/InternalScg.g:238:2: Decision can match input such as "'(' ']'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
Semantic predicates were present but were hidden by actions.
warning(200): ../...omitted.../parser/antlr/internal/InternalScg.g:2449:6: Decision can match input such as "')'" using multiple alternatives: 2, 3
As a result, alternative(s) 3 were disabled for that input
Semantic predicates were present but were hidden by actions.
error(201): ../...omitted.../antlr/internal/InternalScg.g:2449:6: The following alternatives can never be matched: 3
warning(200): ../...omitted.../parser/antlr/internal/InternalScg.g:2994:3: Decision can match input such as "{RULE_STRING..RULE_DECIMAL, ']'..')', '['..'(', '{', '<', '+'..'-', '!', '#', 'if', 'switch', 'for'..'do', 'super'..'try', 'synchronized'}" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
Semantic predicates were present but were hidden by actions.
error(201): ../...omitted.../parser/antlr/internal/InternalScg.g:2994:3: The following alternatives can never be matched: 2
warning(200): ../...omitted.../parser/antlr/internal/InternalScg.g:3246:3: Decision can match input such as "{RULE_ID..RULE_DECIMAL, ']'..')', '['..'(', '{', '<', '+'..'-', '!', '#', 'if', 'switch', 'for'..'try', 'synchronized'}" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
Semantic predicates were present but were hidden by actions.
error(211): ../...omitted.../parser/antlr/internal/InternalScg.g:4067:3: [fatal] rule ruleXBasicForLoopExpression has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
warning(200): ../...omitted.../parser/antlr/internal/InternalScg.g:4767:4: Decision can match input such as "')'" using multiple alternatives: 2, 3
As a result, alternative(s) 3 were disabled for that input
Semantic predicates were present but were hidden by actions.
error(201): ../...omitted.../antlr/internal/InternalScg.g:4767:4: The following alternatives can never be matched: 3
warning(200): ../...omitted.../parser/antlr/internal/InternalScg.g:5100:4: Decision can match input such as "')'" using multiple alternatives: 2, 3
As a result, alternative(s) 3 were disabled for that input
Semantic predicates were present but were hidden by actions.
error(201): ../...omitted.../parser/antlr/internal/InternalScg.g:5100:4: The following alternatives can never be matched: 3
So I am afraid it was my using of parenthesis/brackets causing problem.
If I have to write my own lexer, could you point me to some good tutorials? Thanks. The OCL work is pretty cool but perhaps is too big for me to mimic.
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04619 seconds