by Eric van der Vlist is published by O'Reilly & Associates (ISBN: 0596004214)

Escaping Named Pattern Identifiers in the Compact Syntax

In the previous chapter, I introduced the compact syntax and noted that any word reserved for use by RELAX NG can be used as an element or attribute name. That's no longer the case for the identifiers of named patterns, because they can appear in the same position as the keywords.

If you want to define a named pattern named "text," "start," or "element," for instance, the identifier of this named pattern can be confused with the keyword. In this case you need to escape being confused with the identifier by a leading backslash. For instance to define (and by extension to make a reference) to a named pattern named "start," write:


start = \start

\start = element start { text }


In the XML syntax, this translates into:

<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="">
    <ref name="start"/>
  <define name="start">
    <element name="start">

This text is released under the Free Software Foundation GFDL.