Skip to content

Instantly share code, notes, and snippets.

@rorydriscoll
Created February 24, 2012 07:02
Show Gist options
  • Save rorydriscoll/1898611 to your computer and use it in GitHub Desktop.
Save rorydriscoll/1898611 to your computer and use it in GitHub Desktop.
Lua Grammar for Sublime Text 2. All you need is Lua.tmLanguage (i.e. You don't need the JSON file). Copy Lua.tmLanguage over your existing version and restart Sublime Text.
{
"name": "Lua",
"scopeName": "source.lua",
"fileTypes": [
"lua"
],
"repository": {
"general": {
"patterns": [
{
"include": "#linecomment"
},
{
"include": "#blockcomment"
},
{
"include": "#number"
},
{
"include": "#constant"
},
{
"include": "#singlequotestring"
},
{
"include": "#doublequotestring"
},
{
"include": "#function"
},
{
"include": "#functioncall"
},
{
"include": "#if"
},
{
"include": "#ifblock"
},
{
"include": "#forblock"
},
{
"include": "#whileblock"
},
{
"include": "#repeatblock"
},
{
"include": "#tabledecl"
},
{
"include": "#arrayindex"
},
{
"include": "#operator"
},
{
"include": "#keyword"
},
{
"include": "#variable"
}
]
},
"linecomment": {
"name": "comment.line.double-dash.lua",
"match": "(--)(?!\\[\\[).*$\\n?",
"captures": {
"1": {
"name": "punctuation.definition.comment.lua"
}
}
},
"blockcomment": {
"name": "comment.block.lua",
"begin": "--\\[(=*)\\[",
"end": "\\]\\1\\]",
"captures": {
"0": {
"name": "punctuation.definition.comment.lua"
}
}
},
"constant": {
"name": "constant.language.lua",
"match": "nil|true|false|_G|_VERSION|\\.\\.\\."
},
"number": {
"name": "constant.numeric.lua",
"match": "(?<![\\d.])\\s0x[a-fA-F\\d]+|\\b\\d+(\\.\\d+)?([eE]-?\\d+)?|\\.\\d+([eE]-?\\d+)?"
},
"singlequotestring": {
"name": "string.quoted.single.lua",
"begin": "'",
"beginCaptures": {
"0": {
"name": "punctuation.definition.string.begin.lua"
}
},
"end": "'",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.end.lua"
}
},
"patterns": [
{
"match": "\\\\.",
"name": "constant.character.escape.lua"
}
]
},
"doublequotestring": {
"name": "string.quoted.double.lua",
"begin": "\"",
"beginCaptures": {
"0": {
"name": "punctuation.definition.string.begin.lua"
}
},
"end": "\"",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.end.lua"
}
},
"patterns": [
{
"match": "\\\\.",
"name": "constant.character.escape.lua"
}
]
},
"function": {
"name": "meta.function.lua",
"begin": "\\b(function)(\\s+(((\\w(\\w|\\d)*)\\.)*(\\w(\\w|\\d)*)))?\\s*(\\()((\\.\\.\\.|\\w(\\w|\\d)*)(,\\s*(\\.\\.\\.|\\w(\\w|\\d)*))*)?(\\))",
"beginCaptures": {
"1": {
"name": "keyword.control.lua"
},
"3": {
"name": "entity.name.function.lua"
},
"10": {
"name": "variable.parameter.function.lua"
}
},
"end": "end",
"endCaptures": {
"0": {
"name": "keyword.control.lua"
}
},
"patterns": [
{
"include": "#general"
}
]
},
"libfunctioncall": {
"name": "meta.functioncall.lua",
"match": "(?<![^.]\\.|:)\\b(assert|collectgarbage|dofile|error|getfenv|getmetatable|ipairs|loadfile|loadstring|module|next|pairs|pcall|print|rawequal|rawget|rawset|require|select|setfenv|setmetatable|tonumber|tostring|type|unpack|xpcall|coroutine\\.(create|resume|running|status|wrap|yield)|string\\.(byte|char|dump|find|format|gmatch|gsub|len|lower|match|rep|reverse|sub|upper)|table\\.(concat|insert|maxn|remove|sort)|math\\.(abs|acos|asin|atan2?|ceil|cosh?|deg|exp|floor|fmod|frexp|ldexp|log|log10|max|min|modf|pow|rad|random|randomseed|sinh?|sqrt|tanh?)|io\\.(close|flush|input|lines|open|output|popen|read|tmpfile|type|write)|os\\.(clock|date|difftime|execute|exit|getenv|remove|rename|setlocale|time|tmpname)|package\\.(cpath|loaded|loadlib|path|preload|seeall)|debug\\.(debug|[gs]etfenv|[gs]ethook|getinfo|[gs]etlocal|[gs]etmetatable|getregistry|[gs]etupvalue|traceback))\\b(?=[( {])",
"beginCaptures": {
"1": {
"name": "support.function.lua"
}
},
"end": "\\)",
"patterns": [
{
"include": "#general"
}
]
},
"functioncall": {
"name": "meta.functioncall.lua",
"begin": "((\\w(\\w|\\d)*[\\.:])*\\w(\\w|\\d)*)\\(",
"beginCaptures": {
"1": {
"name": "entity.name.function.lua"
}
},
"end": "\\)",
"patterns": [
{
"include": "#general"
}
]
},
"ifblock": {
"name": "meta.ifblock.lua",
"begin": "\\bif\\b",
"beginCaptures": {
"0": {
"name": "keyword.control.lua"
}
},
"end": "\\bend\\b",
"endCaptures": {
"0": {
"name": "keyword.control.lua"
}
},
"patterns": [
{
"include": "#general"
}
]
},
"forblock": {
"name": "meta.forblock.lua",
"begin": "\\bfor\\b",
"beginCaptures": {
"0": {
"name": "keyword.control.lua"
}
},
"end": "\\bend\\b",
"endCaptures": {
"0": {
"name": "keyword.control.lua"
}
},
"patterns": [
{
"include": "#general"
}
]
},
"whileblock": {
"name": "meta.whileblock.lua",
"begin": "\\bwhile\\b",
"beginCaptures": {
"0": {
"name": "keyword.control.lua"
}
},
"end": "\\bend\\b",
"endCaptures": {
"0": {
"name": "keyword.control.lua"
}
},
"patterns": [
{
"include": "#general"
}
]
},
"repeatblock": {
"name": "meta.repeatblock.lua",
"begin": "\\brepeat\\b",
"beginCaptures": {
"0": {
"name": "keyword.control.lua"
}
},
"end": "\\buntil\\b",
"endCaptures": {
"0": {
"name": "keyword.control.lua"
}
},
"patterns": [
{
"include": "#general"
}
]
},
"tabledecl":{
"name": "meta.tabledecl.lua",
"begin": "{",
"end": "}",
"patterns": [
{
"include": "#general"
}
]
},
"arrayindex":{
"name": "meta.arrayindex.lua",
"begin": "\\[",
"end": "\\]",
"patterns": [
{
"include": "#general"
}
]
},
"operator": {
"name": "keyword.operator.lua",
"match": "(\\b(and|or|not)\\b)|(\\+|-|%|#|\\*|\\/|\\^|==?|~=|<=?|>=?|(?<!\\.)\\.{2}(?!\\.))"
},
"keyword": {
"name": "keyword.control.lua",
"match": "\\b(break|do|else|for|if|elseif|return|then|repeat|while|until|end|function|local|in)\\b"
},
"variable": {
"name": "variable.other.lua",
"match": "([A-Za-z_][A-Za-z0-9_\\.]*)"
}
},
"patterns": [
{
"include": "#general"
}
],
"uuid": "29fa8a60-20f1-4d96-866d-04cfd323c801"
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fileTypes</key>
<array>
<string>lua</string>
</array>
<key>name</key>
<string>Lua</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#general</string>
</dict>
</array>
<key>repository</key>
<dict>
<key>arrayindex</key>
<dict>
<key>begin</key>
<string>\[</string>
<key>end</key>
<string>\]</string>
<key>name</key>
<string>meta.arrayindex.lua</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#general</string>
</dict>
</array>
</dict>
<key>blockcomment</key>
<dict>
<key>begin</key>
<string>--\[(=*)\[</string>
<key>captures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.comment.lua</string>
</dict>
</dict>
<key>end</key>
<string>\]\1\]</string>
<key>name</key>
<string>comment.block.lua</string>
</dict>
<key>constant</key>
<dict>
<key>match</key>
<string>nil|true|false|_G|_VERSION|\.\.\.</string>
<key>name</key>
<string>constant.language.lua</string>
</dict>
<key>doublequotestring</key>
<dict>
<key>begin</key>
<string>"</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.string.begin.lua</string>
</dict>
</dict>
<key>end</key>
<string>"</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.string.end.lua</string>
</dict>
</dict>
<key>name</key>
<string>string.quoted.double.lua</string>
<key>patterns</key>
<array>
<dict>
<key>match</key>
<string>\\.</string>
<key>name</key>
<string>constant.character.escape.lua</string>
</dict>
</array>
</dict>
<key>forblock</key>
<dict>
<key>begin</key>
<string>\bfor\b</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>keyword.control.lua</string>
</dict>
</dict>
<key>end</key>
<string>\bend\b</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>keyword.control.lua</string>
</dict>
</dict>
<key>name</key>
<string>meta.forblock.lua</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#general</string>
</dict>
</array>
</dict>
<key>function</key>
<dict>
<key>begin</key>
<string>\b(function)(\s+(((\w(\w|\d)*)\.)*(\w(\w|\d)*)))?\s*(\()((\.\.\.|\w(\w|\d)*)(,\s*(\.\.\.|\w(\w|\d)*))*)?(\))</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control.lua</string>
</dict>
<key>10</key>
<dict>
<key>name</key>
<string>variable.parameter.function.lua</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>entity.name.function.lua</string>
</dict>
</dict>
<key>end</key>
<string>end</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>keyword.control.lua</string>
</dict>
</dict>
<key>name</key>
<string>meta.function.lua</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#general</string>
</dict>
</array>
</dict>
<key>functioncall</key>
<dict>
<key>begin</key>
<string>((\w(\w|\d)*[\.:])*\w(\w|\d)*)\(</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>entity.name.function.lua</string>
</dict>
</dict>
<key>end</key>
<string>\)</string>
<key>name</key>
<string>meta.functioncall.lua</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#general</string>
</dict>
</array>
</dict>
<key>general</key>
<dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#linecomment</string>
</dict>
<dict>
<key>include</key>
<string>#blockcomment</string>
</dict>
<dict>
<key>include</key>
<string>#number</string>
</dict>
<dict>
<key>include</key>
<string>#constant</string>
</dict>
<dict>
<key>include</key>
<string>#singlequotestring</string>
</dict>
<dict>
<key>include</key>
<string>#doublequotestring</string>
</dict>
<dict>
<key>include</key>
<string>#function</string>
</dict>
<dict>
<key>include</key>
<string>#functioncall</string>
</dict>
<dict>
<key>include</key>
<string>#if</string>
</dict>
<dict>
<key>include</key>
<string>#ifblock</string>
</dict>
<dict>
<key>include</key>
<string>#forblock</string>
</dict>
<dict>
<key>include</key>
<string>#whileblock</string>
</dict>
<dict>
<key>include</key>
<string>#repeatblock</string>
</dict>
<dict>
<key>include</key>
<string>#tabledecl</string>
</dict>
<dict>
<key>include</key>
<string>#arrayindex</string>
</dict>
<dict>
<key>include</key>
<string>#operator</string>
</dict>
<dict>
<key>include</key>
<string>#keyword</string>
</dict>
<dict>
<key>include</key>
<string>#variable</string>
</dict>
</array>
</dict>
<key>ifblock</key>
<dict>
<key>begin</key>
<string>\bif\b</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>keyword.control.lua</string>
</dict>
</dict>
<key>end</key>
<string>\bend\b</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>keyword.control.lua</string>
</dict>
</dict>
<key>name</key>
<string>meta.ifblock.lua</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#general</string>
</dict>
</array>
</dict>
<key>keyword</key>
<dict>
<key>match</key>
<string>\b(break|do|else|for|if|elseif|return|then|repeat|while|until|end|function|local|in)\b</string>
<key>name</key>
<string>keyword.control.lua</string>
</dict>
<key>libfunctioncall</key>
<dict>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>support.function.lua</string>
</dict>
</dict>
<key>end</key>
<string>\)</string>
<key>match</key>
<string>(?&lt;![^.]\.|:)\b(assert|collectgarbage|dofile|error|getfenv|getmetatable|ipairs|loadfile|loadstring|module|next|pairs|pcall|print|rawequal|rawget|rawset|require|select|setfenv|setmetatable|tonumber|tostring|type|unpack|xpcall|coroutine\.(create|resume|running|status|wrap|yield)|string\.(byte|char|dump|find|format|gmatch|gsub|len|lower|match|rep|reverse|sub|upper)|table\.(concat|insert|maxn|remove|sort)|math\.(abs|acos|asin|atan2?|ceil|cosh?|deg|exp|floor|fmod|frexp|ldexp|log|log10|max|min|modf|pow|rad|random|randomseed|sinh?|sqrt|tanh?)|io\.(close|flush|input|lines|open|output|popen|read|tmpfile|type|write)|os\.(clock|date|difftime|execute|exit|getenv|remove|rename|setlocale|time|tmpname)|package\.(cpath|loaded|loadlib|path|preload|seeall)|debug\.(debug|[gs]etfenv|[gs]ethook|getinfo|[gs]etlocal|[gs]etmetatable|getregistry|[gs]etupvalue|traceback))\b(?=[( {])</string>
<key>name</key>
<string>meta.functioncall.lua</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#general</string>
</dict>
</array>
</dict>
<key>linecomment</key>
<dict>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.comment.lua</string>
</dict>
</dict>
<key>match</key>
<string>(--)(?!\[\[).*$\n?</string>
<key>name</key>
<string>comment.line.double-dash.lua</string>
</dict>
<key>number</key>
<dict>
<key>match</key>
<string>(?&lt;![\d.])\s0x[a-fA-F\d]+|\b\d+(\.\d+)?([eE]-?\d+)?|\.\d+([eE]-?\d+)?</string>
<key>name</key>
<string>constant.numeric.lua</string>
</dict>
<key>operator</key>
<dict>
<key>match</key>
<string>(\b(and|or|not)\b)|(\+|-|%|#|\*|\/|\^|==?|~=|&lt;=?|&gt;=?|(?&lt;!\.)\.{2}(?!\.))</string>
<key>name</key>
<string>keyword.operator.lua</string>
</dict>
<key>repeatblock</key>
<dict>
<key>begin</key>
<string>\brepeat\b</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>keyword.control.lua</string>
</dict>
</dict>
<key>end</key>
<string>\buntil\b</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>keyword.control.lua</string>
</dict>
</dict>
<key>name</key>
<string>meta.repeatblock.lua</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#general</string>
</dict>
</array>
</dict>
<key>singlequotestring</key>
<dict>
<key>begin</key>
<string>'</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.string.begin.lua</string>
</dict>
</dict>
<key>end</key>
<string>'</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.string.end.lua</string>
</dict>
</dict>
<key>name</key>
<string>string.quoted.single.lua</string>
<key>patterns</key>
<array>
<dict>
<key>match</key>
<string>\\.</string>
<key>name</key>
<string>constant.character.escape.lua</string>
</dict>
</array>
</dict>
<key>tabledecl</key>
<dict>
<key>begin</key>
<string>{</string>
<key>end</key>
<string>}</string>
<key>name</key>
<string>meta.tabledecl.lua</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#general</string>
</dict>
</array>
</dict>
<key>variable</key>
<dict>
<key>match</key>
<string>([A-Za-z_][A-Za-z0-9_\.]*)</string>
<key>name</key>
<string>variable.other.lua</string>
</dict>
<key>whileblock</key>
<dict>
<key>begin</key>
<string>\bwhile\b</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>keyword.control.lua</string>
</dict>
</dict>
<key>end</key>
<string>\bend\b</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>keyword.control.lua</string>
</dict>
</dict>
<key>name</key>
<string>meta.whileblock.lua</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#general</string>
</dict>
</array>
</dict>
</dict>
<key>scopeName</key>
<string>source.lua</string>
<key>uuid</key>
<string>29fa8a60-20f1-4d96-866d-04cfd323c801</string>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment