Recursive Syntax in Oslo

Posted by Kevin Lawrence on Stack Overflow See other posts from Stack Overflow or by Kevin Lawrence
Published on 2010-05-25T06:47:45Z Indexed on 2010/05/25 6:51 UTC
Read the original article Hit count: 356

Filed under:
|

I'm writing my first DSL with Oslo and I am having a problem with a recursive syntax definition.

The input has sections which can contain questions or other sections recursively (composite pattern) like this:

Section: A
  Question: 1
  Question: 2

  Section: B
    Question: 1
  End
End  

My definition for a Section looks like this

syntax Section = "Section:"  id:Text
                   body:(SectionBody)*
                 "End Section";

Which works (but doesn't handle recursive sections) if I define SectionBody like this

    syntax SectionBody = (Question);

but doesn't work with a recursive definition like this

    syntax SectionBody = (Question | Section);

What am I missing?

© Stack Overflow or respective owner

Related posts about dsl

Related posts about Oslo