Grammar-Kit: Checking semantic rules

Hi, I'm trying to create a plugin with Grammar-Kit for a template language which consists of pair tags in curly brackets. The valid language can be described with the following PCRE (vizualization):

^
(
     (?:
          { (\w+) } (?1) {/ \2 } |
          [\w\s]
     )*
)
$


The syntax can be easily described by PEG

root ::= template eof
template ::= (pairMacro | text)*
pairMacro ::= '{' wordChar+ '}' template '{/' wordChar+ '}'
text ::= wordChar | whitespace


However AFAIK PEG itself cannot describe the semantic rule which states that the name of close tag must be the same as the name of corresponding open tag, e.g.
this is invalid {aaa}lorem ipsum{/bbb}
and this is valid: {aaa}lorem ipsum{/aaa}

What is the recommended way to implement this semantic rule?

Please sign in to leave a comment.