@wooorm/starry-night
Version:
Syntax highlighting, like GitHub
95 lines (92 loc) • 3.43 kB
JavaScript
/**
* @import {Grammar} from '@wooorm/starry-night'
*/
/** @type {Grammar} */
const grammar = {
extensions: [],
names: [],
patterns: [{include: '#regexp'}],
repository: {
'regex-character-class': {
patterns: [
{
match: '\\\\[wWsSdDtrnvf]|\\.',
name: 'constant.character.character-class.regexp'
},
{
match: '\\\\([0-7]{3}|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4})',
name: 'constant.character.numeric.regexp'
},
{match: '\\\\c[A-Z]', name: 'constant.character.control.regexp'},
{match: '\\\\.', name: 'constant.character.escape.backslash.regexp'}
]
},
regexp: {
patterns: [
{match: '\\\\[bB]|\\^|\\$', name: 'keyword.control.anchor.regexp'},
{
match: '\\\\[1-9]\\d*|\\\\k<[a-zA-Z_$][\\w$]*>',
name: 'keyword.other.back-reference.regexp'
},
{
match: '[?+*]|\\{(\\d+,\\d+|\\d+,|,\\d+|\\d+)\\}\\??',
name: 'keyword.operator.quantifier.regexp'
},
{match: '\\|', name: 'keyword.operator.or.regexp'},
{
begin: '(\\()(?:(\\?=)|(\\?!)|(\\?<=)|(\\?<!))',
beginCaptures: {
1: {name: 'punctuation.definition.group.regexp'},
2: {name: 'meta.assertion.look-ahead.regexp'},
3: {name: 'meta.assertion.negative-look-ahead.regexp'},
4: {name: 'meta.assertion.look-behind.regexp'},
5: {name: 'meta.assertion.negative-look-behind.regexp'}
},
end: '(\\))',
endCaptures: {1: {name: 'punctuation.definition.group.regexp'}},
name: 'meta.group.assertion.regexp',
patterns: [{include: '#regexp'}]
},
{
begin: '\\(((\\?:)|(\\?<[a-zA-Z_$][\\w$]*>))?',
beginCaptures: {0: {name: 'punctuation.definition.group.regexp'}},
end: '\\)',
endCaptures: {0: {name: 'punctuation.definition.group.regexp'}},
name: 'meta.group.regexp',
patterns: [{include: '#regexp'}]
},
{
begin: '(\\[)(\\^)?',
beginCaptures: {
1: {name: 'punctuation.definition.character-class.regexp'},
2: {name: 'keyword.operator.negation.regexp'}
},
end: '(\\])',
endCaptures: {
1: {name: 'punctuation.definition.character-class.regexp'}
},
name: 'constant.other.character-class.set.regexp',
patterns: [
{
captures: {
1: {name: 'constant.character.numeric.regexp'},
2: {name: 'constant.character.control.regexp'},
3: {name: 'constant.character.escape.backslash.regexp'},
4: {name: 'constant.character.numeric.regexp'},
5: {name: 'constant.character.control.regexp'},
6: {name: 'constant.character.escape.backslash.regexp'}
},
match:
'(?:.|(\\\\(?:[0-7]{3}|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}))|(\\\\c[A-Z])|(\\\\.))\\-(?:[^\\]\\\\]|(\\\\(?:[0-7]{3}|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}))|(\\\\c[A-Z])|(\\\\.))',
name: 'constant.other.character-class.range.regexp'
},
{include: '#regex-character-class'}
]
},
{include: '#regex-character-class'}
]
}
},
scopeName: 'source.js.regexp'
}
export default grammar