Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 4619867

Browse files
committed
Recognize function/method bodies
1 parent b731239 commit 4619867

File tree

2 files changed

+173
-68
lines changed

2 files changed

+173
-68
lines changed

grammars/javascript.cson

+170-65
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
'name': 'meta.class.js'
6161
}
6262
{
63-
'begin': '([a-zA-Z_?.$][\\w?.$]*)\\.(prototype)\\.([a-zA-Z_?.$][\\w?.$]*)\\s*(=)\\s*(?:(async)(?:\\s+))?(function\\*?)\\s*(\\*?)(\\()'
63+
'begin': '([a-zA-Z_?.$][\\w?.$]*)\\.(prototype)\\.([a-zA-Z_?.$][\\w?.$]*)\\s*(=)\\s*(?:(async)(?:\\s+))?(function\\*?)\\s*(\\*?)(?=\\()'
6464
'beginCaptures':
6565
'1':
6666
'name': 'support.class.js'
@@ -76,18 +76,19 @@
7676
'name': 'storage.type.function.js'
7777
'7':
7878
'name': 'storage.type.function.js'
79-
'8':
80-
'name': 'punctuation.definition.parameters.begin.js'
8179
'comment': 'match stuff like: Sound.prototype.play = function() { … }'
82-
'end': '(\\))'
80+
'end': '\\}'
8381
'endCaptures':
84-
'1':
85-
'name': 'punctuation.definition.parameters.end.js'
82+
'0':
83+
'name': 'punctuation.definition.function.body.end.js'
8684
'name': 'meta.function.prototype.js'
8785
'patterns': [
8886
{
8987
'include': '#function-params'
9088
}
89+
{
90+
'include': '#function-body'
91+
}
9192
]
9293
}
9394
{
@@ -105,7 +106,7 @@
105106
'name': 'meta.function.js'
106107
}
107108
{
108-
'begin': '([a-zA-Z_?.$][\\w?.$]*)\\.([a-zA-Z_?.$][\\w?.$]*)\\s*(=)\\s*(?:(async)(?:\\s+))?(function\\*?)\\s*(\\*?)\\s*([a-zA-Z_?$][\\w?$]*)?\\s*(\\()'
109+
'begin': '([a-zA-Z_?.$][\\w?.$]*)\\.([a-zA-Z_?.$][\\w?.$]*)\\s*(=)\\s*(?:(async)(?:\\s+))?(function\\*?)\\s*(\\*?)\\s*([a-zA-Z_?$][\\w?$]*)?\\s*(?=\\()'
109110
'beginCaptures':
110111
'1':
111112
'name': 'support.class.js'
@@ -124,19 +125,22 @@
124125
'8':
125126
'name': 'punctuation.definition.parameters.begin.js'
126127
'comment': 'match stuff like: Sound.play = function() { … }'
127-
'end': '(\\))'
128+
'end': '\\}'
128129
'endCaptures':
129-
'1':
130-
'name': 'punctuation.definition.parameters.end.js'
130+
'0':
131+
'name': 'punctuation.definition.function.body.end.js'
131132
'name': 'meta.function.js'
132133
'patterns': [
133134
{
134135
'include': '#function-params'
135136
}
137+
{
138+
'include': '#function-body'
139+
}
136140
]
137141
}
138142
{
139-
'begin': '([a-zA-Z_?$][\\w?$]*)\\s*(=)\\s*(?:(async)(?:\\s+))?(function\\*?)\\s*(\\*?)\\s*([a-zA-Z_?$][\\w?$]*)?\\s*(\\()'
143+
'begin': '([a-zA-Z_?$][\\w?$]*)\\s*(=)\\s*(?:(async)(?:\\s+))?(function\\*?)\\s*(\\*?)\\s*([a-zA-Z_?$][\\w?$]*)?\\s*(?=\\()'
140144
'beginCaptures':
141145
'1':
142146
'name': 'entity.name.function.js'
@@ -153,19 +157,22 @@
153157
'7':
154158
'name': 'punctuation.definition.parameters.begin.js'
155159
'comment': 'match stuff like: play = function() { … }'
156-
'end': '(\\))'
160+
'end': '\\}'
157161
'endCaptures':
158-
'1':
159-
'name': 'punctuation.definition.parameters.end.js'
162+
'0':
163+
'name': 'punctuation.definition.function.body.end.js'
160164
'name': 'meta.function.js'
161165
'patterns': [
162166
{
163167
'include': '#function-params'
164168
}
169+
{
170+
'include': '#function-body'
171+
}
165172
]
166173
}
167174
{
168-
'begin': '\\b(?:(async)(?:\\s+))?(function\\*?)\\s*((\\*)|(?:(?:\\s+)(\\*?[a-zA-Z_$]\\w*)))?\\s*(\\()'
175+
'begin': '\\b(?:(async)(?:\\s+))?(function\\*?)\\s*((\\*)|(?:(?:\\s+)(\\*?[a-zA-Z_$]\\w*)))?\\s*(?=\\()'
169176
'beginCaptures':
170177
'1':
171178
'name': 'storage.modifier.js'
@@ -178,19 +185,22 @@
178185
'6':
179186
'name': 'punctuation.definition.parameters.begin.js'
180187
'comment': 'match regular function like: function myFunc(arg) { … }'
181-
'end': '(\\))'
188+
'end': '\\}'
182189
'endCaptures':
183-
'1':
184-
'name': 'punctuation.definition.parameters.end.js'
190+
'0':
191+
'name': 'punctuation.definition.function.body.end.js'
185192
'name': 'meta.function.js'
186193
'patterns': [
187194
{
188195
'include': '#function-params'
189196
}
197+
{
198+
'include': '#function-body'
199+
}
190200
]
191201
}
192202
{
193-
'begin': '\\b([a-zA-Z_?.$][\\w?.$]*)\\s*(:)\\s*\\b(?:(async)(?:\\s+))?(function\\*?)\\s*(\\*?)\\s*([a-zA-Z_?$][\\w?$]*)?\\s*(\\()'
203+
'begin': '\\b([a-zA-Z_?.$][\\w?.$]*)\\s*(:)\\s*\\b(?:(async)(?:\\s+))?(function\\*?)\\s*(\\*?)\\s*([a-zA-Z_?$][\\w?$]*)?\\s*(?=\\()'
194204
'beginCaptures':
195205
'1':
196206
'name': 'entity.name.function.js'
@@ -207,19 +217,22 @@
207217
'7':
208218
'name': 'punctuation.definition.parameters.begin.js'
209219
'comment': 'match stuff like: foobar: function() { … }'
210-
'end': '(\\))'
220+
'end': '\\}'
211221
'endCaptures':
212-
'1':
213-
'name': 'punctuation.definition.parameters.end.js'
222+
'0':
223+
'name': 'punctuation.definition.function.body.end.js'
214224
'name': 'meta.function.json.js'
215225
'patterns': [
216226
{
217227
'include': '#function-params'
218228
}
229+
{
230+
'include': '#function-body'
231+
}
219232
]
220233
}
221234
{
222-
'begin': '(?:((\')([^\']*?)(\'))|((")([^"]*?)(")))\\s*(:)\\s*\\b(?:(async)(?:\\s+))?(function\\*?)\\s*(\\*?)\\s*([a-zA-Z_?$][\\w?$]*)?\\s*(\\()'
235+
'begin': '(?:((\')([^\']*?)(\'))|((")([^"]*?)(")))\\s*(:)\\s*\\b(?:(async)(?:\\s+))?(function\\*?)\\s*(\\*?)\\s*([a-zA-Z_?$][\\w?$]*)?\\s*(?=\\()'
223236
'beginCaptures':
224237
'1':
225238
'name': 'string.quoted.single.js'
@@ -250,32 +263,38 @@
250263
'14':
251264
'name': 'punctuation.definition.parameters.begin.js'
252265
'comment': 'Attempt to match "foo": function'
253-
'end': '(\\))'
266+
'end': '\\}'
254267
'endCaptures':
255-
'1':
256-
'name': 'punctuation.definition.parameters.end.js'
268+
'0':
269+
'name': 'punctuation.definition.function.body.end.js'
257270
'name': 'meta.function.json.js'
258271
'patterns': [
259272
{
260273
'include': '#function-params'
261274
}
275+
{
276+
'include': '#function-body'
277+
}
262278
]
263279
}
264280
{
265-
'begin': '\\b(constructor)\\s*(\\()'
281+
'begin': '\\b(constructor)\\s*(?=\\()'
266282
'beginCaptures':
267283
'1':
268284
'name': 'entity.name.function.constructor.js'
269285
'2':
270286
'name': 'punctuation.definition.parameters.begin.js'
271-
'end': '(\\))'
287+
'end': '\\}'
272288
'endCaptures':
273-
'1':
274-
'name': 'punctuation.definition.parameters.end.js'
289+
'0':
290+
'name': 'punctuation.definition.function.body.end.js'
275291
'patterns': [
276292
{
277293
'include': '#function-params'
278294
}
295+
{
296+
'include': '#function-body'
297+
}
279298
]
280299
}
281300
{
@@ -313,7 +332,37 @@
313332
'name': 'storage.type.arrow.js'
314333
'patterns': [
315334
{
316-
'include': '#function-params'
335+
'include': '#numbers'
336+
}
337+
{
338+
'include': '#strings'
339+
}
340+
{
341+
'match': '\\(|\\)'
342+
'name': 'meta.brace.round.js'
343+
}
344+
{
345+
'match': '\\[|\\]'
346+
'name': 'meta.brace.square.js'
347+
}
348+
{
349+
'match': '\\{|\\}'
350+
'name': 'meta.brace.curly.js'
351+
}
352+
{
353+
'match': ','
354+
'name': 'meta.object.delimiter.js'
355+
}
356+
{
357+
'match': '='
358+
'name': 'keyword.operator.js'
359+
}
360+
{
361+
'include': '#comments'
362+
}
363+
{
364+
'match': '[a-zA-Z_$][a-zA-Z_$0-9]*'
365+
'name': 'variable.parameter.function.js'
317366
}
318367
]
319368
}
@@ -336,7 +385,37 @@
336385
'name': 'storage.type.arrow.js'
337386
'patterns': [
338387
{
339-
'include': '#function-params'
388+
'include': '#numbers'
389+
}
390+
{
391+
'include': '#strings'
392+
}
393+
{
394+
'match': '\\(|\\)'
395+
'name': 'meta.brace.round.js'
396+
}
397+
{
398+
'match': '\\[|\\]'
399+
'name': 'meta.brace.square.js'
400+
}
401+
{
402+
'match': '\\{|\\}'
403+
'name': 'meta.brace.curly.js'
404+
}
405+
{
406+
'match': ','
407+
'name': 'meta.object.delimiter.js'
408+
}
409+
{
410+
'match': '='
411+
'name': 'keyword.operator.js'
412+
}
413+
{
414+
'include': '#comments'
415+
}
416+
{
417+
'match': '[a-zA-Z_$][a-zA-Z_$0-9]*'
418+
'name': 'variable.parameter.function.js'
340419
}
341420
]
342421
}
@@ -661,7 +740,7 @@
661740
'name': 'meta.method.js'
662741
'comment': 'match regular function like: function myFunc(arg) { … }'
663742

664-
'begin': '\\b((?!(?:break|case|catch|continue|do|else|finally|for|function|if|export|import|package|return|switch|throw|try|while|with)[\\s\\(])(?:[a-zA-Z_$][a-zA-Z_$0-9]*))\\s*(\\()(?=(?:[^\\(\\)]*)?\\)\\s*\\{)'
743+
'begin': '\\b((?!(?:break|case|catch|continue|do|else|finally|for|function|if|export|import|package|return|switch|throw|try|while|with)[\\s\\(])(?:[a-zA-Z_$][a-zA-Z_$0-9]*))\\s*(?=\\((?:[^\\(\\)]*)?\\)\\s*\\{)'
665744
'beginCaptures':
666745
'1':
667746
'name': 'entity.name.function.js'
@@ -672,51 +751,77 @@
672751
{
673752
'include': '#function-params'
674753
}
754+
{
755+
'include': '#function-body'
756+
}
675757
{
676758
'include': '#strings'
677759
}
678760
]
679761

680-
'end': '(\\))'
762+
'end': '\\}'
681763
'endCaptures':
682-
'1':
683-
'name': 'punctuation.definition.parameters.end.js'
764+
'0':
765+
'name': 'punctuation.definition.function.body.end.js'
684766
}
685767
]
686768
'function-params':
687769
'patterns': [
688770
{
689-
'include': '#numbers'
690-
}
691-
{
692-
'include': '#strings'
693-
}
694-
{
695-
'match': '\\(|\\)'
696-
'name': 'meta.brace.round.js'
697-
}
698-
{
699-
'match': '\\[|\\]'
700-
'name': 'meta.brace.square.js'
701-
}
702-
{
703-
'match': '\\{|\\}'
704-
'name': 'meta.brace.curly.js'
705-
}
706-
{
707-
'match': ','
708-
'name': 'meta.object.delimiter.js'
709-
}
710-
{
711-
'match': '='
712-
'name': 'keyword.operator.js'
713-
}
714-
{
715-
'include': '#comments'
771+
'begin': '\\('
772+
'beginCaptures':
773+
'0':
774+
'name': 'punctuation.definition.parameters.begin.js'
775+
'end': '\\)'
776+
'endCaptures':
777+
'0':
778+
'name': 'punctuation.definition.parameters.end.js'
779+
'patterns': [
780+
{
781+
'include': '#numbers'
782+
}
783+
{
784+
'include': '#strings'
785+
}
786+
{
787+
'match': '\\[|\\]'
788+
'name': 'meta.brace.square.js'
789+
}
790+
{
791+
'match': '\\{|\\}'
792+
'name': 'meta.brace.curly.js'
793+
}
794+
{
795+
'match': ','
796+
'name': 'meta.object.delimiter.js'
797+
}
798+
{
799+
'match': '='
800+
'name': 'keyword.operator.js'
801+
}
802+
{
803+
'include': '#comments'
804+
}
805+
{
806+
'match': '[a-zA-Z_$][a-zA-Z_$0-9]*'
807+
'name': 'variable.parameter.function.js'
808+
}
809+
]
716810
}
811+
]
812+
'function-body':
813+
'patterns': [
717814
{
718-
'match': '[a-zA-Z_$][a-zA-Z_$0-9]*'
719-
'name': 'variable.parameter.function.js'
815+
'begin': '\\{'
816+
'beginCaptures':
817+
'0':
818+
'name': 'punctuation.definition.function.body.begin.js'
819+
'end': '(?=\\})'
820+
'patterns': [
821+
{
822+
'include': '$self'
823+
}
824+
]
720825
}
721826
]
722827
'interpolated_js':

0 commit comments

Comments
 (0)