Skip to content

Commit 3fad6e9

Browse files
authored
Merge pull request #7 from schneidmaster/new-sublime-syntax
Convert syntax to sublime-syntax instead of tmLanguage.
2 parents b23f7cd + 0899f1e commit 3fad6e9

File tree

3 files changed

+381
-1110
lines changed

3 files changed

+381
-1110
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Sublime syntax highlighting for CJSX
44

5+
## Version Support
6+
7+
This package uses the `.sublime-syntax` syntax definition for rich highlighting and improved performance. As a consequence, only Sublime Text 3, Build 3103 and newer is supported. If you're using Sublime Text 2 or an older version of Sublime Text 3, you can retrieve the old `.tmLanguage` file from [this commit](https://github.com/Guidebook/sublime-cjsx/tree/b23f7cd2fbad387f904a8ead2cb3a79f983c9897) -- however, only the master `.sublime-syntax` definition will receive future updates.
8+
59
## Installation
610

711
### Install via Package Control

syntax/CJSX.sublime-syntax

Lines changed: 377 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,377 @@
1+
%YAML 1.2
2+
---
3+
# http://www.sublimetext.com/docs/3/syntax.html
4+
name: CJSX
5+
comment: CJSX Syntax
6+
file_extensions:
7+
- cjsx
8+
- coffee
9+
- Cakefile
10+
- coffee.erb
11+
- cson
12+
first_line_match: ^#!.*\bcoffee
13+
scope: source.coffee
14+
contexts:
15+
main:
16+
- include: jsx
17+
- match: '(\([^()]*?\))\s*([=-]>)'
18+
comment: "match stuff like: a -> …"
19+
scope: meta.inline.function.coffee
20+
captures:
21+
1: variable.parameter.function.coffee
22+
2: storage.type.function.coffee
23+
- match: (new)\s+(\w+(?:\.\w*)*)
24+
scope: meta.class.instance.constructor
25+
captures:
26+
1: keyword.operator.new.coffee
27+
2: support.class.coffee
28+
- match: "'''"
29+
captures:
30+
0: punctuation.definition.string.begin.coffee
31+
push:
32+
- meta_scope: string.quoted.heredoc.coffee
33+
- match: "'''"
34+
captures:
35+
0: punctuation.definition.string.end.coffee
36+
pop: true
37+
- match: '"""'
38+
captures:
39+
0: punctuation.definition.string.begin.coffee
40+
push:
41+
- meta_scope: string.quoted.double.heredoc.coffee
42+
- match: '"""'
43+
captures:
44+
0: punctuation.definition.string.end.coffee
45+
pop: true
46+
- match: \\.
47+
scope: constant.character.escape.coffee
48+
- include: interpolated_coffee
49+
- match: "`"
50+
captures:
51+
0: punctuation.definition.string.begin.coffee
52+
push:
53+
- meta_scope: string.quoted.script.coffee
54+
- match: "`"
55+
captures:
56+
0: punctuation.definition.string.end.coffee
57+
pop: true
58+
- match: '\\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]|37[0-7]?|[4-7][0-7]?|.)'
59+
scope: constant.character.escape.coffee
60+
- match: (?<!#)###(?!#)
61+
captures:
62+
0: punctuation.definition.comment.coffee
63+
push:
64+
- meta_scope: comment.block.coffee
65+
- match: "###"
66+
captures:
67+
0: punctuation.definition.comment.coffee
68+
pop: true
69+
- match: '@\w*'
70+
scope: storage.type.annotation.coffeescript
71+
- match: '(#)(?!\{).*$\n?'
72+
scope: comment.line.number-sign.coffee
73+
captures:
74+
1: punctuation.definition.comment.coffee
75+
- match: "/{3}"
76+
push:
77+
- meta_scope: string.regexp.coffee
78+
- match: "/{3}[imgy]{0,4}"
79+
pop: true
80+
- include: interpolated_coffee
81+
- include: embedded_comment
82+
- match: '/(?![\s=/*+{}?]).*?[^\\]/[igmy]{0,4}(?![a-zA-Z0-9])'
83+
scope: string.regexp.coffee
84+
- match: |-
85+
(?x)
86+
\b(?<![\.\$])(
87+
break|by|catch|continue|else|finally|for|in|of|if|return|switch|
88+
then|throw|try|unless|when|while|until|loop|do|(?<=for)\s+own
89+
)(?!\s*:)\b
90+
scope: keyword.control.coffee
91+
- match: |-
92+
(?x)
93+
and=|or=|!|%|&|\^|\*|\/|(\-)?\-(?!>)|\+\+|\+|~|==|=(?!>)|!=|<=|>=|<<=|>>=|
94+
>>>=|<>|<|>|!|&&|\.\.(\.)?|\?|\||\|\||\:|\*=|(?<!\()/=|%=|\+=|\-=|&=|
95+
\^=|\b(?<![\.\$])(instanceof|new|delete|typeof|and|or|is|isnt|not|super)\b
96+
scope: keyword.operator.coffee
97+
- match: '([a-zA-Z\$_](\w|\$|\.)*\s*(?!\::)((:)|(=[^=]))(?!(\s*\(.*\))?\s*((=|-)>)))'
98+
scope: variable.assignment.coffee
99+
captures:
100+
1: variable.assignment.coffee
101+
4: punctuation.separator.key-value
102+
5: keyword.operator.coffee
103+
- match: '(?<=\s|^)([\[\{])(?=.*?[\]\}]\s+[:=])'
104+
captures:
105+
0: keyword.operator.coffee
106+
push:
107+
- meta_scope: meta.variable.assignment.destructured.coffee
108+
- match: '([\]\}]\s*[:=])'
109+
captures:
110+
0: keyword.operator.coffee
111+
pop: true
112+
- include: variable_name
113+
- include: instance_variable
114+
- include: jsx-single-quoted-prop
115+
- include: jsx-double-quoted-prop
116+
- include: numeric
117+
- match: |-
118+
(?x)
119+
(\s*)
120+
(?=[a-zA-Z\$_])
121+
(
122+
[a-zA-Z\$_](\w|\$|:|\.)*\s*
123+
(?=[:=](\s*\(.*\))?\s*([=-]>))
124+
)
125+
scope: meta.function.coffee
126+
captures:
127+
2: entity.name.function.coffee
128+
3: entity.name.function.coffee
129+
4: variable.parameter.function.coffee
130+
5: storage.type.function.coffee
131+
- match: ^\s*(describe|it|app\.(get|post|put|all|del|delete))
132+
comment: Show well-known functions from Express and Mocha in Go To Symbol view
133+
push:
134+
- meta_scope: meta.function.symbols.coffee
135+
- match: $
136+
pop: true
137+
- include: main
138+
- match: "[=-]>"
139+
scope: storage.type.function.coffee
140+
- match: '\b(?<!\.)(true|on|yes)(?!\s*[:=])\b'
141+
scope: constant.language.boolean.true.coffee
142+
- match: '\b(?<!\.)(false|off|no)(?!\s*[:=])\b'
143+
scope: constant.language.boolean.false.coffee
144+
- match: '\b(?<!\.)null(?!\s*[:=])\b'
145+
scope: constant.language.null.coffee
146+
- match: '\b(?<!\.)(this|extends)(?!\s*[:=])\b'
147+
scope: variable.language.coffee
148+
- match: '(class\b)\s+(@?[a-zA-Z\$_][\w\.]*)?(?:\s+(extends)\s+(@?[a-zA-Z\$\._][\w\.]*))?'
149+
scope: meta.class.coffee
150+
captures:
151+
1: storage.type.class.coffee
152+
2: entity.name.type.class.coffee
153+
3: keyword.control.inheritance.coffee
154+
4: entity.other.inherited-class.coffee
155+
- match: \b(debugger|\\)\b
156+
scope: keyword.other.coffee
157+
- match: |-
158+
(?x)\b(
159+
Array|ArrayBuffer|Blob|Boolean|Date|document|event|Function|
160+
Int(8|16|32|64)Array|Math|Map|Number|
161+
Object|Proxy|RegExp|Set|String|WeakMap|
162+
window|Uint(8|16|32|64)Array|XMLHttpRequest
163+
)\b
164+
scope: support.class.coffee
165+
- match: ((?<=console\.)(debug|warn|info|log|error|time|timeEnd|assert))\b
166+
scope: support.function.console.coffee
167+
- match: |-
168+
(?x)\b(
169+
decodeURI(Component)?|encodeURI(Component)?|eval|parse(Float|Int)|require
170+
)\b
171+
scope: support.function.coffee
172+
- match: |-
173+
(?x)((?<=\.)(
174+
apply|call|concat|every|filter|forEach|from|hasOwnProperty|indexOf|
175+
isPrototypeOf|join|lastIndexOf|map|of|pop|propertyIsEnumerable|push|
176+
reduce(Right)?|reverse|shift|slice|some|sort|splice|to(Locale)?String|
177+
unshift|valueOf
178+
))\b
179+
scope: support.function.method.array.coffee
180+
- match: |-
181+
(?x)((?<=Array\.)(
182+
isArray
183+
))\b
184+
scope: support.function.static.array.coffee
185+
- match: |-
186+
(?x)((?<=Object\.)(
187+
create|definePropert(ies|y)|freeze|getOwnProperty(Descriptors?|Names)|
188+
getProperty(Descriptor|Names)|getPrototypeOf|is(Extensible|Frozen|Sealed)?|
189+
isnt|keys|preventExtensions|seal
190+
))\b
191+
scope: support.function.static.object.coffee
192+
- match: |-
193+
(?x)((?<=Math\.)(
194+
abs|acos|acosh|asin|asinh|atan|atan2|atanh|ceil|cos|cosh|exp|expm1|floor|
195+
hypot|log|log10|log1p|log2|max|min|pow|random|round|sign|sin|sinh|sqrt|
196+
tan|tanh|trunc
197+
))\b
198+
scope: support.function.static.math.coffee
199+
- match: |-
200+
(?x)((?<=Number\.)(
201+
is(Finite|Integer|NaN)|toInteger
202+
))\b
203+
scope: support.function.static.number.coffee
204+
- match: \b(Infinity|NaN|undefined)\b
205+
scope: constant.language.coffee
206+
- match: \;
207+
scope: punctuation.terminator.statement.coffee
208+
- match: ',[ |\t]*'
209+
scope: meta.delimiter.object.comma.coffee
210+
- match: \.
211+
scope: meta.delimiter.method.period.coffee
212+
- match: '\{|\}'
213+
scope: meta.brace.curly.coffee
214+
- match: \(|\)
215+
scope: meta.brace.round.coffee
216+
- match: '\[|\]\s*'
217+
scope: meta.brace.square.coffee
218+
- include: instance_variable
219+
- include: single_quoted_string
220+
- include: double_quoted_string
221+
- include: numeric
222+
double_quote:
223+
- match: '\\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]|37[0-7]?|[4-7][0-7]?|.)'
224+
scope: constant.character.escape.coffee
225+
- include: interpolated_coffee
226+
- include: jsx-entities
227+
double_quoted_string:
228+
- match: '"'
229+
captures:
230+
0: punctuation.definition.string.begin.coffee
231+
push:
232+
- meta_scope: string.quoted.double.coffee
233+
- match: '"'
234+
captures:
235+
0: punctuation.definition.string.end.coffee
236+
pop: true
237+
- include: double_quote
238+
embedded_comment:
239+
- match: (?<!\\)(#).*$\n?
240+
scope: comment.line.number-sign.coffee
241+
captures:
242+
1: punctuation.definition.comment.coffee
243+
instance_variable:
244+
- match: '(@)([a-zA-Z_\$]\w*)?'
245+
scope: variable.other.readwrite.instance.coffee
246+
interpolated_coffee:
247+
- match: '\#\{'
248+
captures:
249+
0: punctuation.section.embedded.coffee
250+
push:
251+
- meta_scope: source.coffee.embedded.source
252+
- match: '\}'
253+
captures:
254+
0: punctuation.section.embedded.coffee
255+
pop: true
256+
- include: main
257+
jsx:
258+
- include: jsx-evaluated-code
259+
- include: jsx-tag-area
260+
- include: jsx-tag-open
261+
- include: jsx-tag-close
262+
- include: jsx-tag-invalid
263+
jsx-double-quoted-prop:
264+
- match: (?:\s*=\s*)(")
265+
captures:
266+
1: string.quoted.double.punctuation.definition.begin.coffee
267+
push:
268+
- match: '"'
269+
captures:
270+
0: string.quoted.double.punctuation.definition.end.coffee
271+
pop: true
272+
- include: double_quote
273+
- match: .*?
274+
scope: string.quoted.double.coffee
275+
jsx-entities:
276+
- match: "(&)([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+)(;)"
277+
scope: constant.character.entity.coffee
278+
captures:
279+
1: punctuation.definition.entity.coffee
280+
3: punctuation.definition.entity.coffee
281+
- match: "&"
282+
scope: invalid.illegal.bad-ampersand.coffee
283+
jsx-evaluated-code:
284+
- match: "{"
285+
captures:
286+
0: punctuation.definition.brace.curly.start.coffee
287+
push:
288+
- meta_scope: meta.brace.curly.coffee
289+
- match: "}"
290+
captures:
291+
0: punctuation.definition.brace.curly.end.coffee
292+
pop: true
293+
- include: main
294+
jsx-single-quoted-prop:
295+
- match: (?:=)\s?*(')
296+
captures:
297+
1: string.quoted.single.punctuation.definition.string.begin.coffee
298+
push:
299+
- match: "'"
300+
captures:
301+
0: string.quoted.single.punctuation.definition.string.end.coffee
302+
pop: true
303+
- include: single_quote
304+
- match: .*?
305+
scope: string.quoted.single.coffee
306+
jsx-tag-area:
307+
- match: |-
308+
(<)([a-zA-Z0-9:.]+)(?![^
309+
]*/>)
310+
captures:
311+
1: punctuation.definition.tag.begin.coffee
312+
2: entity.name.tag.coffee
313+
push:
314+
- meta_scope: jsx.tag-area.coffee
315+
- match: '(</)(\2)([^>]*>)|(\/>)'
316+
captures:
317+
1: punctuation.definition.tag.begin.coffee
318+
2: entity.name.tag.coffee
319+
4: punctuation.definition.tag.end.coffee
320+
pop: true
321+
- include: jsx-tag-attributes
322+
- include: jsx
323+
jsx-tag-attribute-name:
324+
- match: '\b([a-zA-Z_:][a-zA-Z_:0-9\-\.]*)'
325+
scope: meta.tag.attribute-name.html
326+
captures:
327+
1: entity.other.attribute-name.html
328+
jsx-tag-attributes:
329+
- include: jsx-tag-attribute-name
330+
- include: jsx-double-quoted-prop
331+
- include: jsx-single-quoted-prop
332+
- include: jsx-evaluated-code
333+
jsx-tag-close:
334+
- match: '(</)([^>]+)(>)|(\/>)'
335+
scope: tag.close.coffee
336+
captures:
337+
1: punctuation.definition.tag.begin.coffee
338+
2: entity.name.tag.coffee
339+
3: punctuation.definition.tag.end.coffee
340+
jsx-tag-invalid:
341+
- match: <\s*>
342+
scope: invalid.illegal.tag.incomplete.coffee
343+
jsx-tag-open:
344+
- match: "(<)([a-zA-Z0-9:.]+)"
345+
captures:
346+
1: punctuation.definition.tag.begin.coffee
347+
2: entity.name.tag.coffee
348+
push:
349+
- meta_scope: tag.open.coffee
350+
- match: (/?>)
351+
captures:
352+
1: punctuation.definition.tag.end.coffee
353+
pop: true
354+
- include: jsx-tag-attributes
355+
numeric:
356+
- match: '(?<!\$)\b((0([box])[0-9a-fA-F]+)|([0-9]+(\.[0-9]+)?(e[+\-]?[0-9]+)?))\b'
357+
scope: constant.numeric.coffee
358+
single_quote:
359+
- match: '\\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.)'
360+
scope: constant.character.escape.coffee
361+
- include: jsx-entities
362+
single_quoted_string:
363+
- match: "'"
364+
captures:
365+
0: punctuation.definition.string.begin.coffee
366+
push:
367+
- meta_scope: string.quoted.single.coffee
368+
- match: "'"
369+
captures:
370+
0: punctuation.definition.string.end.coffee
371+
pop: true
372+
- include: single_quote
373+
variable_name:
374+
- match: '([a-zA-Z\$_]\w*(\.\w+)*)'
375+
scope: variable.assignment.coffee
376+
captures:
377+
1: variable.assignment.coffee

0 commit comments

Comments
 (0)