dhakehurst / net.akehurst.language

Generic Language (DSL) support for kotlin multiplatform (parser, syntax-analyser, formatter, processor, etc)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Groups in Grammars

ba01m opened this issue · comments

commented

When there is a group in your grammar, something like

single_match_definition      = match_field ('AS' match_field_in_event)?;

why does the sppt contain a group which contains another group. (aka why are there 2 group elements not only one?)

sppt.toStringIntended(" ") yields this:

  single_match_definition {
    match_field {
      NAME : 'field'
      WHITESPACE { "\s+" : ' ' }
    }
    §single_match_definition§multi0 { §single_match_definition§group0 { §single_match_definition§group0 {
          'AS'
          WHITESPACE { "\s+" : ' ' }
          match_field_in_event {
            NAME : 'bla'
            WHITESPACE { "\s+" : ' ' }
          }
        } } }
  }

§single_match_definition§multi0 is because of the quantifier that makes the group optional ( = ? )

I am asking because the example that is provided is too tiny (for me) to elaborate how to create my own AST objects for my grammar.

hmm, that is odd.

If you rewrite the grammar making the implicit rules explicit it helps understand the SPPT:

single_match_definition = match_field ('AS' match_field_in_event)?;

becomes,

single_match_definition      = match_field optionalGroup ;
optionalGroup                     = group? ;                                      // §single_match_definition§multi0
group                                   = 'AS' match_field_in_event ;       // §single_match_definition§group0

but I believe you should not have 2 '§single_match_definition§group0' items.

Please provide me a complete grammar and example sentence that reproduces this...I will investigate.
Also, which version of AGL?

I believe this should be fixed in the latest pre-release 4.0.0-rc.5
please let me know if this is now ok.

I assume this is now fixed as no reply from you.
Thus I close the bug