@@ -0,0 +1,257 @@
1+%YAML 1.2
2+---
3+# http://www.sublimetext.com/docs/3/syntax.html
4+name: Nim
5+file_extensions:
6+ - nim
7+ - nims
8+scope: source.nim
9+contexts:
10+ main:
11+ - match: '(\#\[\s*(TODO|todo)?)'
12+ comment: A multiline comment.
13+ captures:
14+ 1: punctuation.definition.multi-comment.nim
15+ 2: invalid.illegal.TODO.nim
16+ push:
17+ - meta_scope: comment.line.number-sign.multi-comment.nim
18+ - match: '(.*]\#)'
19+ captures:
20+ 1: punctuation.definition.multi-comment.nim
21+ 2: invalid.illegal.TODO.nim
22+ pop: true
23+ - match: (##\s*(TODO|todo)?).+$\n?
24+ comment: A documentation comment.
25+ scope: comment.line.number-sign.doc-comment.nim
26+ captures:
27+ 1: punctuation.definition.doc-comment.nim
28+ 2: invalid.illegal.TODO.nim
29+ - match: (##\s*)$\n?
30+ comment: An empty documentation comment.
31+ scope: comment.line.number-sign.doc-comment.empty.nim
32+ captures:
33+ 1: punctuation.definition.doc-comment.empty.nim
34+ - match: (#\s*(TODO|todo)?).*$\n?
35+ comment: A regular comment
36+ scope: comment.line.number-sign.comment.nim
37+ captures:
38+ 1: punctuation.definition.comment.nim
39+ 2: invalid.illegal.TODO.nim
40+ - match: '\{\.'
41+ comment: Pragmas
42+ push:
43+ - meta_scope: pragma
44+ - match: '\.?\}'
45+ pop: true
46+ - match: \"
47+ push:
48+ - meta_scope: string.something.nim
49+ - match: \"
50+ pop: true
51+ - match: '([\w\x{80}-\x{10FFFF}]+)'
52+ scope: entity.other.attribute-name.pragma.nim
53+ - match: discard \"\"\"
54+ comment: A discarded triple string literal comment
55+ push:
56+ - meta_scope: comment.line.discarded.nim
57+ - match: \"\"\"
58+ pop: true
59+ - match: '(?<![\w\x{80}-\x{10FFFF}])(\d[_\d]*((\.[_\d]+([eE][\+\-]?\d[_\d]*)?)|([eE][\+\-]?\d[_\d]*)))(''?([fF](32|64|128))|[fFdD])?'
60+ comment: A float literal
61+ scope: constant.numeric.float.decimal.nim
62+ - match: '(?<![\w\x{80}-\x{10FFFF}])(0[xX][0-9A-Fa-f][_0-9A-Fa-f]*)(''?(([iIuUfF](8|16|32|64))|[uUfFdD]))?'
63+ comment: A hexadecimal literal
64+ scope: constant.numeric.integer.hexadecimal.nim
65+ - match: '(?<![\w\x{80}-\x{10FFFF}])(0[ocC][0-7][_0-7]*)(''?(([iIuUfF](8|16|32|64))|[uUfFdD]))?'
66+ comment: A base-8 integer literal
67+ scope: constant.numeric.integer.octal.nim
68+ - match: '(?<![\w\x{80}-\x{10FFFF}])(0(b|B)[01][_01]*)(''?(([iIuUfF](8|16|32|64))|[uUfFdD]))?'
69+ comment: A base-2 integer literal
70+ scope: constant.numeric.integer.binary.nim
71+ - match: '(?<![\w\x{80}-\x{10FFFF}])(\d[_\d]*)(''?(([iIuUfF](8|16|32|64))|[uUfFdD]))?'
72+ comment: A base-10 integer literal
73+ scope: constant.numeric.integer.decimal.nim
74+ - match: '(?<![\w\x{80}-\x{10FFFF}])(true|false|inf|nil)(?![\w\x{80}-\x{10FFFF}])'
75+ comment: Language Constants.
76+ scope: constant.language.nim
77+ - match: (?:^|\s+|=)(when|if)\b
78+ comment: Primary branching keywords
79+ captures:
80+ 1: keyword.control.primary.nim
81+ push:
82+ - match: (?=:)
83+ captures:
84+ 1: control.variable.parameter.nim
85+ pop: true
86+ - include: scope:source.nim
87+ - match: (?:^|\s+|=)(case)\b
88+ comment: Primary branching keyword 'case'
89+ captures:
90+ 1: keyword.control.primary.nim
91+ push:
92+ - match: (?=\bof\b)
93+ captures:
94+ 1: control.variable.parameter.nim
95+ pop: true
96+ - include: scope:source.nim
97+ - match: (?:^|\s+)(of|else|elif)\b
98+ comment: Secondary branching keywords and their conditions
99+ captures:
100+ 1: keyword.control.secondary.nim
101+ push:
102+ - match: (?=:)
103+ captures:
104+ 1: control.variable.parameter.nim
105+ pop: true
106+ - include: scope:source.nim
107+ - match: '(?<![\w\x{80}-\x{10FFFF}])(await|block|break|continue|do|end|except|finally|raise|return|try|while|yield)(?![\w\x{80}-\x{10FFFF}])'
108+ comment: Keywords that affect program control flow or scope.
109+ scope: keyword.control.nim
110+ - match: '((?<![\w\x{80}-\x{10FFFF}])(and|in|is|isnot|not|notin|or|xor)(?![\w\x{80}-\x{10FFFF}]))'
111+ comment: Keyword boolean operators for expressions.
112+ scope: keyword.operator.boolean.nim
113+ - match: '((?<![\w\x{80}-\x{10FFFF}])(addr|as|atomic|bind|cast|const|converter|defer|discard|distinct|div|enum|export|include|let|mixin|object|of|ptr|ref|shl|shr|static|type|var)(?![\w\x{80}-\x{10FFFF}]))'
114+ comment: Other keywords.
115+ scope: keyword.other.nim
116+ - match: (\b()\b|(=|\+|-|\*|/|<|>|@|\$|~|&|%|!|\?|\^|\.|:|\\)+)
117+ comment: Generic operators for expressions.
118+ scope: keyword.operator.nim
119+ - match: (for)\s+
120+ comment: in keyword in a 'for' loop
121+ captures:
122+ 1: keyword.control.nim
123+ push:
124+ - meta_scope: meta.forloop.nim
125+ - match: (?=:)
126+ captures:
127+ 1: keyword.control.nim
128+ pop: true
129+ - match: '\ [\w\x{80}-\x{10FFFF},]+\s+(in)\s+'
130+ captures:
131+ 1: keyword.control.nim
132+ - include: scope:source.nim
133+ - match: '((import)\s+[\.|\w|\/]+,?)'
134+ comment: Import syntax
135+ captures:
136+ 2: keyword.control.nim
137+ - match: '(from)\s+[\/\w]+\s+(?=import)'
138+ captures:
139+ 1: keyword.control.nim
140+ - match: (var|let)\s*\(
141+ comment: Destructure syntax
142+ captures:
143+ 1: keyword.other.nim
144+ push:
145+ - match: \)
146+ captures:
147+ 1: keyword.other.nim
148+ pop: true
149+ - match: '((?<![\w\x{80}-\x{10FFFF}])(generic|interface|lambda|out|shared|with|without)(?![\w\x{80}-\x{10FFFF}]))'
150+ comment: Invalid and unused keywords.
151+ scope: keyword.invalid.nim
152+ - match: '(?<![\w\x{80}-\x{10FFFF}])(new|GC_ref|GC_unref|assert|echo|defined|declared|newException|countup|countdown|len|high|low)(?![\w\x{80}-\x{10FFFF}])'
153+ comment: Common functions
154+ scope: keyword.other.common.function.nim
155+ - match: '(?<![\w\x{80}-\x{10FFFF}])(((uint|int|float)(8|16|32|64)?)|clong|culong|cchar|cschar|cshort|cint|csize|clonglong|cfloat|cdouble|clongdouble|cuchar|cushort|cuint|culonglong|cstringArray|bool|string|auto|cstring|char|byte|tobject|typedesc|stmt|expr|any|untyped|typed)(?![\w\x{80}-\x{10FFFF}])'
156+ comment: Built-in, concrete types.
157+ scope: storage.type.concrete.nim
158+ - match: '(?<![\w\x{80}-\x{10FFFF}])(range|array|seq|tuple|natural|set|ref|ptr|pointer)(?![\w\x{80}-\x{10FFFF}])'
159+ comment: Built-in, generic types.
160+ scope: storage.type.generic.nim
161+ - match: '(?<![\w\x{80}-\x{10FFFF}])(proc|iterator|method|template|macro)(?![\w\x{80}-\x{10FFFF}])'
162+ comment: Function types
163+ scope: storage.type.function.nim
164+ - match: '(?<![\w\x{80}-\x{10FFFF}])(openarray|varargs|void)(?![\w\x{80}-\x{10FFFF}])'
165+ comment: Special types.
166+ scope: storage.type.generic.nim
167+ - match: '(?<![\w\x{80}-\x{10FFFF}])([A-Z][A-Z0-9_]+)(?![\w\x{80}-\x{10FFFF}])'
168+ comment: Other constants.
169+ scope: support.constant.nim
170+ - match: '(?<![\w\x{80}-\x{10FFFF}])([A-Z]\w+)(?![\w\x{80}-\x{10FFFF}])'
171+ comment: Other types.
172+ scope: support.type.nim
173+ - match: '(?<![\w\x{80}-\x{10FFFF}])(\w+)(?![\w\x{80}-\x{10FFFF}])(?=\()'
174+ comment: Function call.
175+ scope: support.function.any-method.nim
176+ - match: r?\"\"\"
177+ comment: (Raw) Triple Quoted String
178+ push:
179+ - meta_scope: string.quoted.triple.nim
180+ - match: '\"\"\"[^\"]'
181+ pop: true
182+ - match: r\"
183+ comment: Raw Double Quoted String
184+ push:
185+ - meta_scope: string.quoted.double.raw.nim
186+ - match: \"
187+ pop: true
188+ - match: \"\"
189+ - match: \"
190+ comment: Double Quoted String
191+ push:
192+ - meta_scope: string.quoted.double.nim
193+ - match: \"
194+ pop: true
195+ - include: escaped_char
196+ - match: \'
197+ comment: Single quoted character literal
198+ push:
199+ - meta_scope: string.quoted.single.nim
200+ - match: \'
201+ pop: true
202+ - match: \\n
203+ scope: invalid.illegal.character.nim
204+ - include: escaped_char
205+ - match: '([^\''][^\'']+?)'
206+ scope: invalid.illegal.character.nim
207+ - match: '([\w\x{80}-\x{10FFFF}\`]+)\s*(?=\(|\[.+?\]\s*\()'
208+ comment: Call syntax
209+ captures:
210+ 1: support.function.any-method.nim
211+ push:
212+ - match: \)
213+ captures:
214+ 1: support.function.any-method.nim
215+ pop: true
216+ - include: scope:source.nim
217+ - match: '([\w\x{80}-\x{10FFFF}]+)(?=\s+[\w](?![\w\x{80}-\x{10FFFF}]+((?!\n)\s)+))'
218+ comment: Command syntax
219+ captures:
220+ 1: support.function.any-method.nim
221+ - match: '([\w\x{80}-\x{10FFFF}]+)(?=\s+[\"\''\`])'
222+ captures:
223+ 1: support.function.any-method.nim
224+ - match: (tmpl(i)?)(?=( (nim|html|xml|js|css|glsl|md))?\"\"\")
225+ comment: tmpl specifier
226+ captures:
227+ 1: storage.type.function.nim
228+ 2: keyword.operator.nim
229+ escaped_char:
230+ - match: '\\[nN]'
231+ scope: constant.character.escape.newline.nim
232+ - match: '\\[cC]|\\[rR]'
233+ scope: constant.character.escape.carriagereturn.nim
234+ - match: '\\[lL]'
235+ scope: constant.character.escape.linefeed.nim
236+ - match: '\\[fF]'
237+ scope: constant.character.escape.formfeed.nim
238+ - match: '\\[tT]'
239+ scope: constant.character.escape.tabulator.nim
240+ - match: '\\[vV]'
241+ scope: constant.character.escape.verticaltabulator.nim
242+ - match: \\\"
243+ scope: constant.character.escape.double-quote.nim
244+ - match: \\'
245+ scope: constant.character.escape.single-quote.nim
246+ - match: '\\[0-9]+'
247+ scope: constant.character.escape.chardecimalvalue.nim
248+ - match: '\\[aA]'
249+ scope: constant.character.escape.alert.nim
250+ - match: '\\[bB]'
251+ scope: constant.character.escape.backspace.nim
252+ - match: '\\[eE]'
253+ scope: constant.character.escape.escape.nim
254+ - match: '\\[xX][0-9A-Fa-f]{2}'
255+ scope: constant.character.escape.hex.nim
256+ - match: \\\\
257+ scope: constant.character.escape.backslash.nim