Skip to content

Commit 14e02bd

Browse files
author
Wliu
authored
Merge pull request atom#512 from atom/wl-jsdoc-changes
Re-implement embedded JSDoc JavaScript highlighting
2 parents f99edc1 + 23fac44 commit 14e02bd

File tree

2 files changed

+538
-325
lines changed

2 files changed

+538
-325
lines changed

grammars/jsdoc.cson

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
'3':
1212
'name': 'constant.language.access-type.jsdoc'
1313
'match': '''(?x)
14-
((@)access)
14+
((@)(?:access|api))
1515
\\s+
1616
(private|protected|public)
1717
\\b
@@ -155,7 +155,15 @@
155155
|
156156
# JSDoc namepath
157157
(
158-
(?!https?://)
158+
(?!
159+
# Avoid matching bare URIs (also acceptable as links)
160+
https?://
161+
|
162+
# Avoid matching {@inline tags}; we match those below
163+
(?:\\[[^\\[\\]]*\\])? # Possible description [preceding]{@tag}
164+
{@(?:link|linkcode|linkplain|tutorial)\\b
165+
)
166+
# Matched namepath
159167
(?:[^@\\s*/]|\\*[^/])+
160168
)
161169
)
@@ -252,33 +260,51 @@
252260
'name': 'variable.other.jsdoc'
253261
}
254262
{
263+
# Optional value
255264
'name': 'variable.other.jsdoc'
256-
'begin': '\\['
257-
'end': '\\]|(?=\\*/)'
258-
'patterns': [
259-
{
260-
'match': '(=)((?:[^\\]*]|\\*[^/])*)'
261-
'captures':
262-
'1':
263-
'name': 'keyword.operator.assignment.jsdoc'
264-
'2':
265-
'name': 'source.embedded.js'
266-
'patterns': [
267-
{
268-
'include': '#inline-tags'
269-
}
270-
{
271-
'include': 'source.js'
272-
}
273-
]
274-
}
275-
{
276-
'include': '#brackets'
277-
}
278-
{
279-
'include': '#quotes'
280-
}
281-
]
265+
'match': '''(?x)
266+
(\\[)\\s*
267+
[\\w$]+
268+
(?:
269+
(?:\\[\\])? # Foo[].bar properties within an array
270+
\\. # Foo.Bar namespaced parameter
271+
[\\w$]+
272+
)*
273+
(?:
274+
\\s*
275+
(=) # [foo=bar] Default parameter value
276+
\\s*
277+
(
278+
# The inner regexes are to stop the match early at */ and to not stop at escaped quotes
279+
(?:
280+
"(?:(?:\\*(?!/))|(?:\\\\(?!"))|[^*\\\\])*?" | # [foo="bar"] Double-quoted
281+
'(?:(?:\\*(?!/))|(?:\\\\(?!'))|[^*\\\\])*?' | # [foo='bar'] Single-quoted
282+
\\[ (?:(?:\\*(?!/))|[^*])*? \\] | # [foo=[1,2]] Array literal
283+
(?:(?:\\*(?!/))|[^*])*? # Everything else
284+
)*
285+
)
286+
)?
287+
\\s*(?:(\\])((?:[^*\\s]|\\*[^\\s/])+)?|(?=\\*/))
288+
'''
289+
'captures':
290+
'1':
291+
'name': 'punctuation.definition.optional-value.begin.bracket.square.jsdoc'
292+
'2':
293+
'name': 'keyword.operator.assignment.jsdoc'
294+
'3':
295+
'name': 'source.embedded.js'
296+
'patterns': [
297+
{
298+
'include': '#inline-tags'
299+
}
300+
{
301+
'include': 'source.js'
302+
}
303+
]
304+
'4':
305+
'name': 'punctuation.definition.optional-value.end.bracket.square.jsdoc'
306+
'5':
307+
'name': 'invalid.illegal.syntax.jsdoc'
282308
}
283309
]
284310
}
@@ -369,16 +395,16 @@
369395
'1':
370396
'name': 'punctuation.definition.block.tag.jsdoc'
371397
'match': '''(?x) (@)
372-
(?:abstract|access|alias|arg|argument|async|attribute|augments|author|beta|borrows|bubbles
398+
(?:abstract|access|alias|api|arg|argument|async|attribute|augments|author|beta|borrows|bubbles
373399
|callback|chainable|class|classdesc|code|config|const|constant|constructor|constructs|copyright
374400
|default|defaultvalue|define|deprecated|desc|description|dict|emits|enum|event|example|exception
375401
|exports?|extends|extension(?:_?for)?|external|externs|file|fileoverview|final|fires|for|func
376-
|function|global|host|ignore|implements|implicitCast|inherit[Dd]oc|inner|instance|interface|kind
377-
|lends|license|listens|main|member|memberof!?|method|mixes|mixins?|modifies|module|name|namespace
378-
|noalias|nocollapse|nocompile|nosideeffects|override|overview|package|param|preserve|private|prop
379-
|property|protected|public|read[Oo]nly|record|require[ds]|returns?|see|since|static|struct|submodule
380-
|summary|suppress|template|this|throws|todo|tutorial|type|typedef|unrestricted|uses|var|variation
381-
|version|virtual|writeOnce)
402+
|function|global|host|ignore|implements|implicitCast|inherit[Dd]oc|inner|instance|interface
403+
|internal|kind|lends|license|listens|main|member|memberof!?|method|mixes|mixins?|modifies|module
404+
|name|namespace|noalias|nocollapse|nocompile|nosideeffects|override|overview|package|param|preserve
405+
|private|prop|property|protected|public|read[Oo]nly|record|require[ds]|returns?|see|since|static
406+
|struct|submodule|summary|suppress|template|this|throws|todo|tutorial|type|typedef|unrestricted
407+
|uses|var|variation|version|virtual|writeOnce)
382408
\\b
383409
'''
384410
'name': 'storage.type.class.jsdoc'
@@ -458,28 +484,6 @@
458484
]
459485
}
460486
]
461-
# Balanced quotes
462-
'quotes':
463-
'patterns': [
464-
{
465-
'begin': "'"
466-
'end': "'|(?=\\*/)"
467-
'patterns': [
468-
{
469-
'include': '#quotes'
470-
}
471-
]
472-
}
473-
{
474-
'begin': '"'
475-
'end': '"|(?=\\*/)'
476-
'patterns': [
477-
{
478-
'include': '#quotes'
479-
}
480-
]
481-
}
482-
]
483487
# {type}
484488
'type':
485489
'patterns': [

0 commit comments

Comments
 (0)