grammardslxtextmodel-driven-development

Numbers in XText not accepted


I have the following rule:

terminal MIDI_VALUE: 
 (             '0'..'9') |
 (    '1'..'9' '0'..'9') |
 ('1' '0'..'1' '0'..'9') |
 ('1' '2'      '0'..'7');

This rule is meant to read values from [0..127].

However, it does not accept values from [1..16], while 0 and 17 to 127 is accepted.

When I hover over the error I get:

mismatched input: '16' expecting RULE_MIDI_VALUE.

How can I fix this?

2nd Example

This example is maybe even more trivial:

DmxDelayTimeSubCommand:
    'DelayTime' time=Time;

Time:
    time=INT type=('ms' | 's' );

While the input

    AllFrontBlue AllGroupsAll Mode loop DelayTime 255 ms;

Shows an error over 255 showing when hovering over it:

Mismatched input '255' expecting RULE_INT

While RULE_INT is a predefined terminal:

terminal INT returns ecore::EInt: ('0'..'9')+;

I get this error for all values below 256 (all values from [0..255]).


Solution

  • the rules MIDI_VALUE and INT overlap with each other.

    possible solutions

    1. use INT + validator (for all of them)
    2. use a datatyperule like MIDI_CHANNEL: INT (no terminal keyword) + a valueconverter
    3. use terminal rules that dont overlap and datatype rules MIDI_CHANNEL: TERMINAL1|TERMINAL2| ....