## Syntax highlighting for Lua.

## Original author:  Matthew Wild
## License:  GPL version 3 or newer

syntax lua "\.lua$"
magic "Lua script"
comment "--"

linter luacheck --no-color

# Operators
color brightyellow "#|%|&|\*|\+|-|/|:|<|<=|==|>=|>|\^|\||~|~=|\.\.|\<(and|or|not)\>"
# Don't partially color ... as an operator
color normal "\.\.\."

# Statements
color brightblue "\<(do|end|for|in|if|then|elseif|else|repeat|until|while|break|goto|return|function|global|local)\>"

# Basic functions
color brightyellow "\<(assert|collectgarbage|dofile|error|(get|set)metatable|load(file)?|next|i?pairs|x?pcall|print|raw(equal|get|len|set)|require|select|tonumber|tostring|type|warn)[[:blank:]]*\("

# Standard library
color brightyellow "\<coroutine\.(create|isyieldable|resume|running|status|wrap|yield)\>"
color brightyellow "\<debug\.(debug|(get|set)(hook|local|metatable|(up|user)value)|getinfo|getregistry|traceback|upvalue(id|join))\>"
color brightyellow "\<io\.(close|flush|input|lines|output|p?open|read|std(in|out|err)|tmpfile|type|write)\>"
color brightyellow "\<math\.(abs|acos|asin|atan|ceil|cos|deg|(fr|ld)?exp|floor|fmod|huge|log|(max|min)(integer)?|modf|pi|rad|random(seed)?|sin|sqrt|tan|tointeger|type|ult)\>"
color brightyellow "\<os\.(clock|date|difftime|execute|exit|getenv|remove|rename|setlocale|time|tmpname)\>"
color brightyellow "\<package\.(config|cpath|loaded|loadlib|path|preload|searchers|searchpath)\>"
color brightyellow "\<string\.(byte|char|dump|find|format|gmatch|gsub|len|lower|match|pack|packsize|rep|reverse|sub|unpack|upper)\>"
color brightyellow "\<table\.(concat|create|insert|move|pack|remove|sort|unpack)\>"
color brightyellow "\<utf8\.(char|charpattern|codepoint|codes|len|offset)\>"

# File handle methods
color brightyellow ":(close|flush|lines|read|seek|setvbuf|write)\>"

# External files
color brightgreen "\<(dofile|require)\>"

# Special words
color brightmagenta "\<(false|nil|true)\>"
color lime "(_G|_ENV|_VERSION)\>"

# Decimal and hexadecimal numbers
color orange "\<[0-9]+(\.[0-9]*)?([Ee][+-]?[0-9]+)?\>"
color orange "\<0[Xx][[:xdigit:]]+(\.[[:xdigit:]]*)?([Pp][+-]?[0-9]+)?\>"

# Brackets
color brightmagenta "\(|\)|\[|\]|\{|\}"

# Shebang
color brightcyan "^#!.*"

# Labels
color pink "::[[:alnum:]_]+::"

# Strings
color orange ""([^"\]|\\.)*"|'([^'\]|\\.)*'"
color orange start="\[\[" end="\]\]"

# Backslash escapes
color mauve "\\([abfnrtvz\"']|[0-9]{1,3}|x[[:xdigit:]]{2}|u\{[[:xdigit:]]{1,6}\})"

# Simple comments and multiline comments
color green "--.*"
color green start="--\[\[" end="\]\]"
