Skip to content

Commit 73fe578

Browse files
committed
Forked textmate grammar from language-lua package
1 parent e9fae39 commit 73fe578

File tree

1 file changed

+117
-94
lines changed

1 file changed

+117
-94
lines changed

grammars/grammar-lua.json

Lines changed: 117 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -6,166 +6,189 @@
66

77
"patterns": [
88
{
9-
"comment": "Single-line comment",
10-
"name": "comment.line.double-dash.lua",
11-
"match": "--(?!\\[=*\\[).*",
129
"captures": {
13-
"1": { "name": "punctuation.definition.comment.lua"}
14-
}
10+
"1": {
11+
"name": "keyword.control.lua"
12+
},
13+
"2": {
14+
"name": "entity.name.function.scope.lua"
15+
},
16+
"3": {
17+
"name": "entity.name.function.lua"
18+
},
19+
"4": {
20+
"name": "punctuation.definition.parameters.begin.lua"
21+
},
22+
"5": {
23+
"name": "variable.parameter.function.lua"
24+
},
25+
"6": {
26+
"name": "punctuation.definition.parameters.end.lua"
27+
}
28+
},
29+
"match": "\\b(function)(?:\\s+([a-zA-Z_.:]+[.:])?([a-zA-Z_]\\w*)\\s*)?(\\()([^)]*)(\\))",
30+
"name": "meta.function.lua"
1531
},
1632
{
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-
}
33+
"match": "(?<![\\d.])\\s0x[a-fA-F\\d]+|\\b\\d+(\\.\\d+)?([eE]-?\\d+)?|\\.\\d+([eE]-?\\d+)?",
34+
"name": "constant.numeric.lua"
2735
},
28-
2936
{
30-
"comment": "String (single quoted)",
3137
"begin": "'",
3238
"beginCaptures": {
33-
"0": { "name": "punctuation.definition.string.begin.lua" }
39+
"0": {
40+
"name": "punctuation.definition.string.begin.lua"
41+
}
3442
},
3543
"end": "'",
3644
"endCaptures": {
37-
"0": { "name": "punctuation.definition.string.end.lua" }
45+
"0": {
46+
"name": "punctuation.definition.string.end.lua"
47+
}
3848
},
3949
"name": "string.quoted.single.lua",
4050
"patterns": [
4151
{
42-
"comment": "Special characters",
43-
"match": "\\\\([abfnrtv']|\\d{1,3}|[xX]\\h\\h|u\\{\\h{,7}\\})",
52+
"include": "punctuation.definition.string.begin.lua"
53+
},
54+
{
55+
"include": "punctuation.definition.string.end.lua"
56+
},
57+
{
58+
"match": "\\\\.",
4459
"name": "constant.character.escape.lua"
4560
}
4661
]
4762
},
4863
{
49-
"comment": "String (double quoted)",
5064
"begin": "\"",
5165
"beginCaptures": {
52-
"0": { "name": "punctuation.definition.string.begin.lua" }
66+
"0": {
67+
"name": "punctuation.definition.string.begin.lua"
68+
}
5369
},
5470
"end": "\"",
5571
"endCaptures": {
56-
"0": { "name": "punctuation.definition.string.end.lua" }
72+
"0": {
73+
"name": "punctuation.definition.string.end.lua"
74+
}
5775
},
5876
"name": "string.quoted.double.lua",
5977
"patterns": [
6078
{
61-
"comment": "Special characters",
62-
"match": "\\\\([abfnrtv\"]|\\d{1,3}|[xX]\\h\\h|u\\{\\h{,7}\\})",
79+
"include": "punctuation.definition.string.begin.lua"
80+
},
81+
{
82+
"include": "punctuation.definition.string.end.lua"
83+
},
84+
{
85+
"match": "\\\\.",
6386
"name": "constant.character.escape.lua"
6487
}
6588
]
6689
},
6790
{
68-
"comment": "String (multiline)",
69-
"begin": "(?<!--)\\[(=*)\\[",
91+
"begin": "(?<=\\.cdef)\\s*(\\[(=*)\\[)",
7092
"beginCaptures": {
71-
"0": { "name": "punctuation.definition.string.begin.lua" }
93+
"0": {
94+
"name": "string.quoted.other.multiline.lua"
95+
},
96+
"1": {
97+
"name": "punctuation.definition.string.begin.lua"
98+
}
7299
},
73-
"end": "\\]\\1\\]",
100+
"contentName": "meta.embedded.lua",
101+
"end": "(\\]\\2\\])",
74102
"endCaptures": {
75-
"0": { "name": "punctuation.definition.string.end.lua" }
103+
"0": {
104+
"name": "string.quoted.other.multiline.lua"
105+
},
106+
"1": {
107+
"name": "punctuation.definition.string.end.lua"
108+
}
76109
},
77-
"name": "string.quoted.single.lua",
78110
"patterns": [
79111
{
80-
"comment": "Special characters",
81-
"match": "\\\\([abfnrtv\\[\\]]|\\d{1,3}|[xX]\\h\\h|u\\{\\h{,7}\\})",
82-
"name": "constant.character.escape.lua"
112+
"include": "source.c"
83113
}
84114
]
85115
},
86-
87116
{
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"
117+
"begin": "(?<!--)\\[(=*)\\[",
118+
"beginCaptures": {
119+
"0": {
120+
"name": "punctuation.definition.string.begin.lua"
109121
}
110-
}
122+
},
123+
"end": "\\]\\1\\]",
124+
"endCaptures": {
125+
"0": {
126+
"name": "punctuation.definition.string.end.lua"
127+
}
128+
},
129+
"name": "string.quoted.other.multiline.lua"
111130
},
112-
113131
{
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"
132+
"begin": "--\\[(=*)\\[",
133+
"captures": {
134+
"0": {
135+
"name": "punctuation.definition.comment.lua"
136+
}
137+
},
138+
"end": "\\]\\1\\]",
139+
"name": "comment.block.lua"
117140
},
118-
119141
{
120-
"comment": "Variables (language)",
121-
"match": "(?<!^\\.|[^.]\\.|:)\\b(self|this)\\b|((?<![.])\\.{3}(?!\\.)|_G|_VERSION)",
122-
"name": "variable.language.lua"
142+
"begin": "(^[ \\t]+)?(?=--(?!\\[(=*)\\[))",
143+
"beginCaptures": {
144+
"1": {
145+
"name": "punctuation.whitespace.comment.leading.lua"
146+
}
147+
},
148+
"end": "(?!\\G)",
149+
"patterns": [
150+
{
151+
"begin": "--",
152+
"beginCaptures": {
153+
"0": {
154+
"name": "punctuation.definition.comment.lua"
155+
}
156+
},
157+
"end": "\\n",
158+
"name": "comment.line.double-dash.lua"
159+
}
160+
]
123161
},
124-
125162
{
126-
"comment": "Constants",
127-
"match": "(?<!^\\.|[^.]\\.|:)\\b(true|nil|false)\\b",
128-
"name": "constant.language.lua"
163+
"match": "\\b(and|or|not|break|do|else|for|if|elseif|return|then|repeat|while|until|end|function|local|in|goto)\\b",
164+
"name": "keyword.control.lua"
129165
},
130-
131166
{
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"
167+
"match": "(?<![^.]\\.|:)\\b([A-Z_]+|false|nil|true|math\\.(pi|huge))\\b|(?<![.])\\.{3}(?!\\.)",
168+
"name": "constant.language.lua"
135169
},
136-
137170
{
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"
171+
"match": "(?<![^.]\\.|:)\\b(self)\\b",
172+
"name": "variable.language.self.lua"
141173
},
142-
143174
{
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",
175+
"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)\\b(?=\\s*(?:[({\"']|\\[\\[))",
146176
"name": "support.function.lua"
147177
},
148178
{
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",
179+
"match": "(?<![^.]\\.|:)\\b(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(?=\\s*(?:[({\"']|\\[\\[))",
151180
"name": "support.function.library.lua"
152181
},
153182
{
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-
}
183+
"match": "\\b([A-Za-z_]\\w*)\\b(?=\\s*(?:[({\"']|\\[\\[))",
184+
"name": "support.function.any-method.lua"
159185
},
160-
161186
{
162-
"comment": "Operators (logical)",
163-
"match": "\\b(and|or|not)\\b",
164-
"name": "keyword.operator.logical.lua"
187+
"match": "(?<=[^.]\\.|:)\\b([A-Za-z_]\\w*)",
188+
"name": "variable.other.lua"
165189
},
166190
{
167-
"comment": "Operators",
168-
"match": "\\b(=|<|<=|==|~=|>=|>|\\||~|&|<<|>>|\\+|-|\\*|/|//|%|(?<!\\.)\\.{2}(?!\\.)|\\^|#)\\b",
191+
"match": "\\+|-|%|#|\\*|\\/|\\^|==?|~=|<=?|>=?|(?<!\\.)\\.{2}(?!\\.)",
169192
"name": "keyword.operator.lua"
170193
}
171194
]

0 commit comments

Comments
 (0)