/***************************************************************************** Grammar for XSugar. (See http://www.brics.dk/grammar/) *****************************************************************************/ REGEXP = [A-Z][a-zA-Z0-9_\.]* (MAX) /* built in: _, __, NCNAME, QNAME, CHAR, NAMECHAR, LETTER, URI */ NONTERMINAL = [a-z][a-zA-Z0-9_\.]* (MAX) NAME = [a-zA-Z0-9_\.]+ (MAX) WHITESPACE = [\ \t\n\r\f]+ (MAX) COMMENT = "/*"~(.*"*/".*)"*/"|"//"[^\r\n]* (MAX) NUMBER = [0-9]+ (MAX) HEXNUMBER = [0-9a-fA-F]+ (MAX) NONRESERVEDCHAR = [^\ \.\;\"\#\@\|\&\?\*\+\{\}\(\)\<\>\[\]\-\\\b\t\n\r\f] ESCAPEDCHAR = \\(u[0-9a-fA-F]{4}|[^u\b\t\n\r\f]|[btnrf])|\&(lt|gt|amp|apos|quot|\#|\#x)\; CHARCLASSCHAR = [^\^\]\&\\\-\b\t\n\r\f] STRING = ([^\"\\\b\t\n\r\f]|)* (MAX) URI = [^\"]* (MAX) NCNAME = [^\ \t\n\r\:\>\/\=]+ (MAX) PREFIX = &~"xmlns" (MAX) /* * A stylesheet consists of includes, namespace declarations, regexp definitions, and productions. */ Stylesheet : _ Includes[includes] NamespaceDecls[nsdecls] RegexpDefs[regexps] Productions[productions] /* * File inclusion. */ Includes[present] : Include[include] Includes[more] [absent] | Include : "include" __ "\"" [uri] "\"" __ /* * Namespace declarations associate URIs with prefixes. */ NamespaceDecls[present] : NamespaceDecl[nsdecl] NamespaceDecls[more] [absent] | NamespaceDecl : "xmlns" OptPrefix[prefix] _ "=" _ "\"" [uri] "\"" __ OptPrefix[present] : ":" [prefix] [absent] | /* * Regexp definitions define named regular expressions. */ RegexpDefs[present] : RegexpDef[regexp] RegexpDefs[more] [absent] | RegexpDef : [name] _ "=" _ Regexp[exp] OptMax[max] __ /* * Every production has a non-XML side and an XML side. If the nonterminal is omitted, the one from * the previous production is assumed. The first occurring nonterminal in the main file is the start nonterminal. */ Productions[present] : Production[production] Productions[more] [absent] | Production : OptNonterminal[nonterminal] OptPriority[priority] ":" OptUnordered[unordered_left] _ LeftItems[items_left] "=" OptUnordered[unordered_right] _ RightItems[items_right] OptNonterminal[present] : [nonterminal] _ [absent] | /* * A production with '>' has lower parsing priority than those defined previously for the same nonterminal. */ OptPriority[higher] : ">" [equal] | /* * A non-XML side or XML side marked with '&' is unordered, meaning that it matches the items in any order. * (On XML side, '&' can only be used at top-level element contents.) */ OptUnordered[present] : "&" [absent] | /* * Production items can be nonterminals, regexp terminals, string terminals, whitespace, and elements. */ LeftItems[present] : LeftItem[item] _ LeftItems[more] [absent] | RightItems[present] : RightItem[item] _ RightItems[more] [absent] | LeftItem : Item[item] RightItem[item] : Item[item] [element] | Element[element] Item[nonterminal] : "[" _ [nonterminal] OptNameOrExample[nameexample] _ "]" [regexp_terminal] | "[" _ [regexp] OptNameOrExample[nameexample] _ "]" [string_terminal] | "\"" [string] "\"" [nonempty_whitespace] | "__" [whitespace] | "_" __ Element[element] : "<" _ Name[name] Attributes[attributes] _ ">" _ RightItems[contents] "" [empty_element] | "<" _ Name[name] Attributes[attributes] _ "/>" Attributes[present] : __ Attribute[attribute] Attributes[more] [absent] | Attribute[const] : Name[name] _ "=" _ "\"" [value] "\"" [regexp] | Name[name] _ "=" _ "[" _ [regexp] OptNameOrExample[nameexample] _ "]" [nonterminal] | Name[name] _ "=" _ "[" _ [nonterminal] OptNameOrExample[nameexample] _ "]" Name[unqualified] : [localname] [qualified] | [prefix] ":" [localname] [regexp] | "[" _ [regexp] OptNameOrExample[nameexample] _ "]" /* * Each nonterminal or terminal may be 'named' (meaning that it corresponds to a branch in the parse tree), * or anonymous (meaning that it is not reflected in the parse tree). If anonymous, an example string (used * for unparsing) may be specified for overriding the automatically generated default. */ OptNameOrExample[name] : __ [name] [example] | __ "\"" [example] "\"" [empty] | /* * Regular expressions essentially use the notation from dk.brics.automaton * (see http://www.brics.dk/automaton/). */ Regexp : UnionExp[e] UnionExp[union] : InterExp[e] _ "|" _ UnionExp[more] [other] | InterExp[e] InterExp[inter] : ConcatExp[e] _ "&" _ InterExp[more] [other] | ConcatExp[e] ConcatExp[concat] : RepeatExp[e] ConcatExp[more] [other] | RepeatExp[e] RepeatExp[optional] : RepeatExp[e] "?" [star] | RepeatExp[e] "*" [plus] | RepeatExp[e] "+" [number] | RepeatExp[e] "{" [n] "}" [min] | RepeatExp[e] "{" [n] ",}" [interval] | RepeatExp[e] "{" [n] "," [m] "}" [other] | ComplExp[e] ComplExp[complement] : "~" ComplExp[e] [other] | CharclassExp[e] CharclassExp[charclass] : "[" Charclasses[c] "]" [negativeclass] | "[^" Charclasses[c] "]" [other] | SimpleExp[e] Charclasses[first] : Charclass[c] Charclasses[more] [last] | Charclass[c] Charclass[interval] : Charclasschar[c1] "-" Charclasschar[c2] [single] | Charclasschar[c] Charclasschar[char] : [c] [escape] | [c] SimpleExp[char] : [c] [escape] | [c] [dot] | "." [empty] | "#" [all] | "@" [string] | "\"" [string] "\"" [epsilon] | "()" [exp] | "(" UnionExp[e] ")" [named] | "<" [id] ">" [numeric] | "<" [n] "-" [m] ">" /* * A regexp marked with '(MAX)' matches only maximal substrings. * (Useful for parsing performance and disambiguation.) */ OptMax[present] : __ "(" "MAX" ")" [absent] | /* whitespace and other ignorable stuff */ Ignorable : | | __ : Ignorable _ _ : Ignorable _ |