syntax .js-esc

state special
    char "'\"\\bfnrtv" END special
    char 0 3n
    char x 2left
    char u 4left
    noeat short

state 4left special
    char 0-9a-fA-F 3left
    noeat short

state 3left special
    char 0-9a-fA-F 2left
    noeat short

state 2left special
    char 0-9a-fA-F 1left
    noeat short

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

state 3n special
    char 0-9 2n
    noeat short

state 2n special
    char 0-9 1n
    noeat short

state 1n special
    char 0-9 END special
    noeat short

state short special
    # Don't eat \n
    char -n "\n" END error
    noeat END

syntax .js-regexp

state regexp
    char "\\" regexp-esc
    char "[" regexp-char-list-start
    char "{" regexp-range
    char "/" regexp-flags regexp
    char "^$|()?:*+." this regexp-special
    char "\n" END error
    eat this

state regexp-esc regexp-special
    char "\n" END error
    eat regexp regexp-special

state regexp-char-list-start regexp-special
    char ^ regexp-char-list regexp-special
    char ] regexp regexp-special
    char "\n" END error
    eat regexp-char-list

state regexp-char-list regexp
    char "-" this regexp-special
    char "\\" regexp-char-list-esc
    char ] regexp regexp-special
    char "\n" END error
    eat this

state regexp-char-list-esc regexp-special
    char "\n" END error
    eat regexp-char-list regexp-special

state regexp-range regexp-special
    char "0-9" this regexp
    char "," regexp-range-second
    char "}" regexp regexp-special
    char "\n" END error
    eat this error

state regexp-range-second regexp-special
    char "0-9" this regexp
    char "}" regexp regexp-special
    char "\n" END error
    eat this error

state regexp-flags regexp-special
    char gimuy this
    noeat END

syntax javascript

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

state code
    char -b a-zA-Z_ ident
    char 0 zero
    char 1-9 dec
    char . dot
    str "//" line-comment
    str "/*" long-comment
    char \' sq
    char \" dq
    char "(;:,=*/%&|!?+-" foo
    eat this

# who knows where regexps are allowed?
state foo code
    char " \t(;:,=*%&|!?+-" this
    str "//" line-comment
    str "/*" long-comment
    char / .js-regexp:code
    noeat code

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

state dec numeric
    char 0-9 this
    char eE exp
    char . float
    noeat check-suffix

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

state dot numeric
    char 0-9 float
    recolor code 1
    noeat code

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

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

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

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

state ident
    char -b a-zA-Z0-9_ this
    inlist keyword code
    inlist reserved code keyword
    inlist type code
    inlist errortype code type
    inlist constant code
    inlist builtin-namespace code constant
    inlist function code builtin
    inlist message code builtin
    inlist global code builtin
    inlist member code builtin
    inlist deprecated code
    noeat code

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

state long-comment comment
    str "*/" code comment
    eat this

state sq string
    char \' code string
    char "\n" code
    char "\\" .js-esc:this
    eat this

state dq string
    char \" code string
    char "\n" code
    char "\\" .js-esc:this
    eat this

list keyword \
    break case catch continue debugger default delete do else finally for \
    function if in instanceof new return switch this throw try typeof var \
    void while with

list reserved \
    class const enum export extends implements import interface let \
    package private protected public static super yield

list type \
    Array Boolean Date Function Number Object RegExp String \
    Map WeakMap Set WeakSet Symbol Promise Proxy ArrayBuffer DataView \
    Float32Array Float64Array Int8Array Int16Array Int32Array \
    Uint8Array Uint16Array Uint32Array Uint8ClampedArray

# Non-constructible, built-in objects (used and referred to as "namespaces")
list builtin-namespace \
    Intl JSON Math Reflect WebAssembly

list errortype \
    Error EvalError RangeError ReferenceError SyntaxError TypeError URIError

list constant \
    arguments \
    Infinity NaN false null true undefined

list function \
    decodeURI decodeURIComponent encodeURI encodeURIComponent eval \
    isFinite isNaN parseFloat parseInt

# builtin?
list message \
    alert confirm prompt status

list global \
    self window top parent

list member \
    document event location

list deprecated \
    escape unescape

default special regexp
default special regexp-special
