Skip to content

Instantly share code, notes, and snippets.

@ruoso
Created August 4, 2009 19:19
Show Gist options
  • Save ruoso/161467 to your computer and use it in GitHub Desktop.
Save ruoso/161467 to your computer and use it in GitHub Desktop.
grammar XML::SAX;
token TOP {
^
<startDocument>
<element>
<endDocument>
$
}
token startDocument {
<prolog>
{*}
}
token prolog {
<xmlDecl>?
<Misc>*
[ <doctypeDecl>
<Misc>* ]?
{*}
}
token endDocument {
<Misc>*
{*}
}
token Misc {
<S>
| <processingInstruction>
| <comment>
}
token whitespace {
["\x20" | "\x9" | "\xD" | "\xA"]
}
token S {
<whitespace> <ignorableWhitespace>?
}
token ignorableWhitespace {
<whitespace>+ {*}
}
token processingInstruction {
'<?' <PITarget> [<S> <char>*? ]? '?>' {*}
}
token PITarget {
<!before [['X'|'x']['M'|'m']['L'|'l']]>
<char*>
}
token xmlDecl {
'<?xml' <VersionInfo> <EncodingDecl>? <SDDecl>? <S>? '?>' {*}
}
token VersionInfo {
<S> 'version' <Eq> [ '"' <VersionNum> '"' | "'" <VersionNum> "'" ]
}
token Eq {
<S>? '=' <S>?
}
token VersionNum {
'1.' <[0..9]>+
}
token SDDecl {
<S> 'standalone' <Eq> [["'" ['yes' | 'no'] "'"] | ['"' ['yes' | 'no'] '"']]
}
token EncodingDecl {
<S> 'encoding' <Eq> ['"' <EncName> '"' | "'" <EncName> "'" ]
}
token EncName {
<[A..Z a..z '.' '_']> <[A..Z a..z 0..9 '.' '_' '-']>*
}
token doctypeDecl {
'<!DOCTYPE' # die "NYI!"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment