syntax .xml-entity

state entity
    char # hash
    char -b a-zA-Z0-9 name
    recolor error 1
    char "\n" END
    eat END error

state hash entity
    char xX x
    char 0-9 dec
    eat END error

state x entity
    char 0-9a-fA-F hex
    eat END error

state hex entity
    char 0-9a-fA-F this
    char ";" END entity
    eat END error

state dec entity
    char 0-9 this
    char ";" END entity
    eat END error

state name error
    char -b a-zA-Z0-9 this
    inlist entity semicolon
    noeat semicolon

state semicolon error
    char ";" END entity
    eat END error

list entity \
    quot apos amp lt gt

syntax xml

state line1 text
    char " \t\n" this
    str "<?" xml
    str -i "<!doctype" doctype
    noeat text

state line2 text
    char " \t\n" this
    str -i "<!doctype" doctype
    noeat text

# Eat <?xml ... ?>
state xml comment
    char > line2 comment
    char < line2 error
    eat this

state doctype comment
    char > text comment
    char < text error
    eat this

state text
    str "<!--" comment
    char < tag-start
    char > this error
    char "&" .xml-entity:this
    eat this

state comment
    str -- --> text comment
    eat this

state tag-start tag
    char / close-tag
    char -b a-zA-Z_: tag-name
    char > text tag
    eat this error

state close-tag tag
    char -b a-zA-Z_: close-tag-name
    eat text error

state tag-name tag
    char -b a-zA-Z0-9_:.- this
    noeat attrs

state close-tag-name tag
    char -b a-zA-Z0-9_:.- this
    noeat close-tag-end

state close-tag-end special
    char " \t\n" this
    char > text tag
    eat text error

state attrs code
    char " \t\n" this
    char -b a-zA-Z:_ attr-name
    char > text tag
    char / short-close
    eat this error

state short-close tag
    char > text tag
    eat text error

state attr-name attr
    char a-zA-Z0-9_:.- this
    char = attr-eq
    noeat attrs

state attr-eq attr
    char \" dq
    char \' sq
    noeat attrs

state dq string
    char \" attrs string
    char "\n" attrs
    char "&" .xml-entity:this
    eat this

state sq string
    char \' attrs string
    char "\n" attrs
    char "&" .xml-entity:this
    eat this

default special entity
