syntax .lua-long-string

state body string
    char ] end-match
    eat this

state end-match string
    heredocend end
    noeat body

state end string
    char ] END string
    noeat body

syntax .lua-long-comment

state body comment
    char ] end-match
    eat this

state end-match comment
    heredocend end
    noeat body

state end comment
    char ] END comment
    noeat body

syntax .lua-escape

state escape
    char "abfnrtv\\\"'" END special
    char x hex1
    char 0-1 decimal-low
    char 2 decimal-two
    char 3-9 decimal-high
    noeat short

state hex1 special
    char 0-9a-fA-F hex2
    noeat short

state hex2 special
    char 0-9a-fA-F END special
    noeat short

state decimal-low special
    char 0-9 decimal-last
    noeat END

state decimal-last special
    char 0-9 END special
    noeat END

state decimal-two special
    char 0-4 decimal-last
    char 5 decimal-two-five
    char 6-9 decimal-short
    noeat END

state decimal-two-five special
    char 0-5 END special
    char 6-9 END error
    noeat END

state decimal-high special
    char 0-9 decimal-short
    noeat END

state decimal-short special
    char 0-9 END error
    noeat END

state short special
    char -n "\n" END error
    noeat END

syntax lua

list constant false true nil
list opword and or not

list keyword \
    do end while repeat until if elseif then else for in \
    function local return goto break

state first-line
    char " \t" this
    char # line-comment
    noeat code

state code
    char -b a-zA-Z_ identifier
    char 0 zero
    char 1-9 decimal
    char \' single-quote
    char \" double-quote
    char \- dash
    char [ bracket
    char -b : colon
    str '~=' this operator
    char =/+*#<>^%|&~ this operator
    str '...' this special
    str '..' this operator
    char . dot
    char '!@`$?' this error
    eat this

state bracket string
    char [ .lua-long-string:code string
    char -b = bracket-equals
    recolor default 1
    noeat code

state colon
    char -b : colon-colon
    noeat code

state colon-colon
    char -b a-zA-Z_ colon-colon-name
    eat code error

state colon-colon-name
    char -b a-zA-Z0-9_ this
    char -b : colon-colon-name-colon
    eat code error

state colon-colon-name-colon
    char -b : label
    eat code error

state label
    recolor label
    noeat code

state bracket-equals string
    char -b = this
    char -n [ code error
    heredocbegin .lua-long-string code

state dash operator
    char \- dash-dash
    noeat code

state dash-dash comment
    recolor comment 2
    char "\n" code
    char [ dash-dash-bracket
    eat line-comment comment

state dash-dash-bracket comment
    char [ .lua-long-comment:code comment
    char -b = dash-dash-bracket-equals comment
    eat line-comment

state dash-dash-bracket-equals
    char -b = this comment
    char -n [ line-comment
    heredocbegin .lua-long-comment code

state line-comment comment
    char "\n" code
    eat this comment

state zero numeric
    char 0-9 decimal
    char xX hex
    char . float
    noeat check-suffix

state decimal numeric
    char 0-9 this
    char eE exponent
    char . float
    noeat check-suffix

state hex numeric
    char 0-9a-fA-F this
    noeat check-suffix

state float numeric
    char 0-9 this
    char eE exponent
    noeat check-suffix

state exponent numeric
    char +- exponent-digit
    char 0-9 exponent-digit
    noeat check-suffix

state exponent-digit numeric
    char 0-9 this
    noeat check-suffix

state check-suffix error
    char a-zA-Z0-9_ this
    noeat code

state dot
    char 0-9 dot-float
    noeat code

state dot-float
    recolor numeric 2
    noeat float

state identifier
    char -b a-zA-Z0-9_ this
    inlist keyword code
    inlist constant code
    inlist opword code operator
    noeat code

state single-quote string
    char \' code string
    char "\n" code
    char "\\" .lua-escape:this special
    eat this

state double-quote string
    char \" code string
    char "\n" code
    char "\\" .lua-escape:this special
    eat this
