Xtext grammar for a nested indented language

470 views Asked by At

I'm trying to write an Xtext grammar for a language as follows:

on Producer1
    then ProducerConsumer1
        then ProducerConsumer1_1
        then ProducerConsumer1_2
            then ProducerConsumer1_2_1
    then ProducerConsumer2
        then ProducerConsumer2_1

on Producer2
    then ProducerConsumer1

With the following grammar, I can see in the Eclipse editor that the white-space blocks are acknowledged but not nested how I intended:

Model:
    model+=On+
;

On:
    'on' producer=ValidID
    BEGIN
        (producerConsumers+=Then)*
    END
;

Then:
    'then' producerConsumer=ValidID
    BEGIN
        (children+=Then)*
    END
;

terminal BEGIN: 'synthetic:BEGIN';  // increase indentation
terminal END: 'synthetic:END';      // decrease indentation

I'm new to Xtext and would appreciate pointers on where I'm going wrong.

1

There are 1 answers

0
Christian Dietrich On BEST ANSWER

do you actually mean

Then:
'then' producerConsumer=ID
(BEGIN
    (children+=Then)+
END)?