Skip to content

Commit 61dea9f

Browse files
Ashi KrishnanMax Brunsfeld
andcommitted
Inject and highlight regular expressions with tree-sitter-regex
Co-Authored-By: Max Brunsfeld <[email protected]>
1 parent 0c3de9c commit 61dea9f

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

grammars/tree-sitter-regex.cson

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
id: 'regex'
2+
name: 'Javascript RegExp'
3+
type: 'tree-sitter'
4+
parser: 'tree-sitter-regex'
5+
legacyScopeName: 'source.js.regexp'
6+
fileTypes: ['jsre']
7+
injectionRegExp: 'regex'
8+
9+
comments:
10+
start: '// '
11+
12+
scopes:
13+
'pattern': 'string.quoted',
14+
'group_name': 'variable.other.object.property'
15+
'atom_escape, class_escape': 'constant.character.character-class.regexp'
16+
'assertion': 'constant.character.character-class.regexp'
17+
'quantifier': 'storage.modifier'
18+
'character_class': 'string.regexp'
19+
'"(", "(?", "(?:", "(?<"': 'punctuation.definition.parameters.begin.bracket.round'
20+
'">", ")"': 'punctuation.definition.parameters.end.bracket.round'
21+
'"=", "<=", "!", "<!"': 'punctuation.definition.parameters.begin.bracket.round'

lib/main.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,17 @@ exports.activate = function() {
3838
}
3939
}
4040
})
41+
42+
atom.grammars.addInjectionPoint('javascript', {
43+
type: 'regex_pattern',
44+
45+
language (regex) {
46+
return 'regex'
47+
},
48+
49+
content (regex) {
50+
return regex
51+
}
52+
})
53+
4154
}

0 commit comments

Comments
 (0)