Skip to content

Commit 4361091

Browse files
committed
Add textmate grammar
1 parent c7451a9 commit 4361091

File tree

1 file changed

+165
-1
lines changed

1 file changed

+165
-1
lines changed

grammars/grammar-lua.json

Lines changed: 165 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,169 @@
44

55
"fileTypes": [ "lua" ],
66

7-
"patterns": []
7+
"patterns": [
8+
{
9+
"comment": "Single-line comment",
10+
"name": "comment.line.double-dash.lua",
11+
"match": "--(?!\\[=*\\[).*",
12+
"captures": {
13+
"1": { "name": "punctuation.definition.comment.lua"}
14+
}
15+
},
16+
{
17+
"comment": "Multi-line comment",
18+
"name": "comment.line.block.lua",
19+
"begin": "--\\[(=*)\\[",
20+
"beginCaptures": {
21+
"0": { "name": "punctuation.definition.comment.begin.lua" }
22+
},
23+
"end": "\\]\\1\\]",
24+
"endCaptures": {
25+
"0": { "name": "punctuation.definition.comment.begin.lua" }
26+
}
27+
},
28+
29+
{
30+
"comment": "String (single quoted)",
31+
"begin": "'",
32+
"beginCaptures": {
33+
"0": { "name": "punctuation.definition.string.begin.lua" }
34+
},
35+
"end": "'",
36+
"endCaptures": {
37+
"0": { "name": "punctuation.definition.string.end.lua" }
38+
},
39+
"name": "string.quoted.single.lua",
40+
"patterns": [
41+
{
42+
"comment": "Special characters",
43+
"match": "\\\\([abfnrtv']|\\d{1,3}|[xX]\\h\\h|u\\{\\h{,7}\\})",
44+
"name": "constant.character.escape.lua"
45+
}
46+
]
47+
},
48+
{
49+
"comment": "String (double quoted)",
50+
"begin": "\"",
51+
"beginCaptures": {
52+
"0": { "name": "punctuation.definition.string.begin.lua" }
53+
},
54+
"end": "\"",
55+
"endCaptures": {
56+
"0": { "name": "punctuation.definition.string.end.lua" }
57+
},
58+
"name": "string.quoted.double.lua",
59+
"patterns": [
60+
{
61+
"comment": "Special characters",
62+
"match": "\\\\([abfnrtv\"]|\\d{1,3}|[xX]\\h\\h|u\\{\\h{,7}\\})",
63+
"name": "constant.character.escape.lua"
64+
}
65+
]
66+
},
67+
{
68+
"comment": "String (multiline)",
69+
"begin": "(?<!--)\\[(=*)\\[",
70+
"beginCaptures": {
71+
"0": { "name": "punctuation.definition.string.begin.lua" }
72+
},
73+
"end": "\\]\\1\\]",
74+
"endCaptures": {
75+
"0": { "name": "punctuation.definition.string.end.lua" }
76+
},
77+
"name": "string.quoted.single.lua",
78+
"patterns": [
79+
{
80+
"comment": "Special characters",
81+
"match": "\\\\([abfnrtv\\[\\]]|\\d{1,3}|[xX]\\h\\h|u\\{\\h{,7}\\})",
82+
"name": "constant.character.escape.lua"
83+
}
84+
]
85+
},
86+
87+
{
88+
"comment": "Functions",
89+
"match": "\\b(function)(?:\\s+([a-zA-Z_.:]+[.:])?([a-zA-Z_]\\w*)\\s*)?(\\()([^)]*)(\\))",
90+
"name": "meta.function.lua",
91+
"captures": {
92+
"1": {
93+
"name": "keyword.control.lua"
94+
},
95+
"2": {
96+
"name": "entity.name.function.scope.lua"
97+
},
98+
"3": {
99+
"name": "entity.name.function.lua"
100+
},
101+
"4": {
102+
"name": "punctuation.definition.parameters.begin.lua"
103+
},
104+
"5": {
105+
"name": "variable.parameter.function.lua"
106+
},
107+
"6": {
108+
"name": "punctuation.definition.parameters.end.lua"
109+
}
110+
}
111+
},
112+
113+
{
114+
"comment": "Metamethods",
115+
"match": "(?<!^\\.|[^.]\\.|:)\\b(__(?:add|call|concat|div|eq|index|len|le|lt|mod|mode|mul|newindex|pow|sub|unm)|print)\\b",
116+
"name": "support.function.metamethod.lua"
117+
},
118+
119+
{
120+
"comment": "Variables (language)",
121+
"match": "(?<!^\\.|[^.]\\.|:)\\b(self|this)\\b|((?<![.])\\.{3}(?!\\.)|_G|_VERSION)",
122+
"name": "variable.language.lua"
123+
},
124+
125+
{
126+
"comment": "Constants",
127+
"match": "(?<!^\\.|[^.]\\.|:)\\b(true|nil|false)\\b",
128+
"name": "constant.language.lua"
129+
},
130+
131+
{
132+
"comment": "Numeric",
133+
"match": "(?<![\\d.])\\b0[xX][a-fA-F\\d\\.]+([pP][\\-\\+]?\\d+)?|\\b\\d+(\\.\\d+)?([eE]-?\\d+)?|\\.\\d+([eE]-?\\d+)?",
134+
"name": "constant.numeric.lua"
135+
},
136+
137+
{
138+
"comment": "Keywords",
139+
"match": "\\b(break|do|else|for|if|elseif|return|then|repeat|while|until|end|function|local|in)\\b",
140+
"name": "keyword.control.lua"
141+
},
142+
143+
{
144+
"comment": "Lua basic functions",
145+
"match": "(?<!^\\.|[^.]\\.|:)\\b(assert|collectgarbage|dofile|error|getfenv|getmetatable|ipairs|load|loadfile|loadstring|next|pairs |pcall|rawequal|rawset|select|setfenv|setmetatable|tonumber|tostring|type|unpack|xpcall)\\b",
146+
"name": "support.function.lua"
147+
},
148+
{
149+
"comment": "Lua collections library",
150+
"match": "(?<!^\\.|[^.]\\.|:)\\b(coroutine\\.(create|resume|running|status|wrap|yield)|debug\\.(debug|getfenv|gethook|getinfo|getlocal|getmetatable|getregistry|getupvalue|setfenv|sethook|setlocal|setmetatable|setupvalue|traceback)|io\\.(close|flush|input|lines|open|output|popen|read|stderr|stdin|stdout|tmpfile|type|write)|file\\:(close|flush|lines|read|seek|stvbuf|write)|match\\.(abs|acos|asin|atan|atan2|ceil|cos|cosh|deg|exp|floor|fmod|frexp|huge|idexp|log|log10|max|min|modf|pi|pow|rad|random|randomseed|sin|sinh|sqrt|tan|tanh)|os\\.(clock|date|difftime|execute|exit|getenv|remove|rename|setlocale|time|tmpname)|package\\.(cpath|loaded|loaders|loadlib|path|preload|seeall)|string\\.(byte|char|dump|find|format|gmatch|gsub|len|lower|match|rep|reverse|sub|upper)|table\\.(concat|insert|maxn|remove|sort))\\b",
151+
"name": "support.function.library.lua"
152+
},
153+
{
154+
"comment": "Lua ponctuation functions library",
155+
"match": "(?<=\\w|\\)|\\])(:)(?:(byte|char|dump|find|format|gfind|gmatch|gsub|len|lower|match|rep|reverse|sub|trim|upper))\\b",
156+
"captures": {
157+
"0": { "name": "support.function.lua" }
158+
}
159+
},
160+
161+
{
162+
"comment": "Operators (logical)",
163+
"match": "\\b(and|or|not)\\b",
164+
"name": "keyword.operator.logical.lua"
165+
},
166+
{
167+
"comment": "Operators",
168+
"match": "\\b(=|<|<=|==|~=|>=|>|\\||~|&|<<|>>|\\+|-|\\*|/|//|%|(?<!\\.)\\.{2}(?!\\.)|\\^|#)\\b",
169+
"name": "keyword.operator.lua"
170+
}
171+
]
8172
}

0 commit comments

Comments
 (0)