Parsing unique but unordered named blocks

37 Views Asked by At

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?

1

There are 1 best solutions below

0
Apalala On BEST ANSWER

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.