0

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?

shader
  • 801
  • 1
  • 7
  • 25

1 Answers1

1

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.

Apalala
  • 9,017
  • 3
  • 30
  • 48