syntax .vala-esc

state char-esc special
    char "bfnrt\\'\"" END special
    char 0 oct
    char u hex4
    noeat short

state oct special
    char 0-3 oct2
    char 4-7 oct1
    noeat END

state oct2 special
    char 0-7 oct1
    noeat END

state oct1 special
    char 0-7 END special
    noeat END

state hex4 special
    char 0-9a-fA-F hex3
    noeat END

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

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

state hex1 special
    char 0-9a-fA-F END special
    noeat END

state short special
    char "\x80-\xff" not-ascii
    # Any ASCII character but \n
    char -n "\n" END error
    # Don't eat \n
    noeat END

# Eats (at least) one multibyte UTF-8 character
state not-ascii error
    char "\x80-\xff" this
    noeat END

# TODO: Check against the Vala spec (was copied from the Java syntax)
syntax vala

state code
    char -b a-zA-Z_ ident
    char 0 zero
    char 1-9 dec
    char . dot
    char \" string
    char \' char
    str "//" cpp-comment
    str "/*" c-comment
    eat this

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

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

state ident
    char -b a-zA-Z0-9_ this
    inlist keyword code
    inlist type code
    inlist constant code
    noeat code

state zero numeric
    char xX hex
    char 0-7 oct
    char . float
    noeat num-suffix

state oct numeric
    char 0-7 this
    noeat num-suffix

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

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

state num-suffix
    char lLfFdD check-suffix numeric
    noeat check-suffix

state float-suffix
    char fFdD check-suffix numeric
    noeat check-suffix

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

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

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

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

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

state string
    char \\ .vala-esc:this
    char \" code string
    eat this

state char
    char "\\" .vala-esc:char-end
    char "\n" code
    char \' code error
    char "\x80-\xff" not-ascii
    eat char-end

# Eats (at least) one multibyte UTF-8 character
state not-ascii char
    char "\x80-\xff" this
    noeat char-end

state char-end char
    char \' code char
    eat code error

list keyword \
    if else switch case default do while for foreach in break continue \
    return try catch finally throw lock class interface struct enum \
    delegate errordomain const weak unowned dynamic abstract virtual \
    override signal extern static async inline new public private \
    protected internal out ref throws requires ensures namespace using \
    as is in new delete sizeof typeof this base null true false get set \
    construct default value construct static construct class construct \
    void var yield global owned

list type \
    bool char uchar short ushort int uint long ulong size_t ssize_t int8 \
    uint8 int16 uint16 int32 uint32 int64 uint64 unichar float double string

list constant \
    false true null
