parsingdsltatsu

Parsing unique but unordered named blocks


I have a DSL where a file consists of multiple named blocks. Ideally, each block should occur only once, but the order doesn't matter.

How do I write a parser that ignores block order, but gives syntax errors if the same block is repeated?


Solution

  • One option is to detect the error after parsing, perhaps with a walker.

    If you need to detect the errors during parsing, then add a semantics class that stores the block identifiers and raises SemanticError if a block name is repeated.