0

I want to define a Domain Specific Language (DSL) that is structures / cascaded like this

ROOT
  NAME "my dsl"
  TODO
    DESC "foo"
  END
  TODO
    DESC "bar"
  END
END

For my understanding it needs the following rules:

  • ROOT and TODO objects has to start with their keyword and end with an END.
  • ROOT must have a NAME attribute.
  • TODO must have a DESC attribute
  • TODO is 0..n times in ROOT

How can I express such ruleset in a BNF?

dnltsk
  • 1,037
  • 1
  • 8
  • 9

1 Answers1

1

Based on the Custom Language Support Tutorial (Simple Language), the following BNF snippet works for me.

{
  tokens=[
    space='regexp:[\s\n]+'
    string="regexp:'.*'"
  ]
}

simpleFile ::= 'ROOT' space nameAttr space (todoObj space)+ 'END'
nameAttr ::= 'NAME' space string

todoObj ::= 'TODO' space descAttr space 'END'
descAttr ::= 'DESC' space string
dnltsk
  • 1,037
  • 1
  • 8
  • 9