shader
shader

Reputation: 841

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?

Upvotes: 0

Views: 40

Answers (1)

Apalala
Apalala

Reputation: 9244

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.

Upvotes: 1

Related Questions