module xml-prolog
imports xml-whitespace xml-names xml-comments xml-pi xml-external

exports
  context-free syntax

    XMLDecl? Misc* DocTypePrologue? -> Prologue {cons("Prologue")}
    Misc* -> Epilogue {cons("Epilogue")}
    Comment -> Misc {cons("Comment")}
    PI      -> Misc

  context-free syntax

    "<?xml" VersionInfo EncodingDecl? StandaloneDecl? "?>" -> XMLDecl {cons("XMLDecl")}

    "standalone" "=" StandaloneValue -> StandaloneDecl {cons("StandaloneDecl")}
    "version"    "=" VersionValue    -> VersionInfo    {cons("VersionDecl")}
    "encoding"   "=" EncodingValue   -> EncodingDecl   {cons("EncodingDecl")}

    "\"" YesNo "\"" -> StandaloneValue {cons("Standalone")}
    "'"  YesNo "'" -> StandaloneValue {cons("StandaloneSingle")}

    "\"" EncodingName "\"" -> EncodingValue {cons("Encoding")}
    "'"  EncodingName "'" -> EncodingValue {cons("EncodingSingle")}

    "\"" VersionNum "\"" -> VersionValue {cons("Version")}
    "'"  VersionNum "'"  -> VersionValue {cons("VersionSingle")}

  context-free syntax

    DocTypeDecl Misc* -> DocTypePrologue {cons("DocTypePrologue")}

    "<!DOCTYPE" QName ExternalID ">" -> DocTypeDecl {cons("DocTypeDecl")}

  lexical syntax

    [a-zA-Z0-9\_\.\:\-]+ -> VersionNum
    [A-Za-z] [A-Za-z0-9\.\_\-]* -> EncodingName

    "yes" -> YesNo
    "no"  -> YesNo
