-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
source.lex.js
137 lines (135 loc) · 3.8 KB
/
source.lex.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// This is a TextMate grammar distributed by `starry-night`.
// This grammar is developed at
// <https://github.com/Alhadis/language-grammars>
// and licensed `isc`.
// See <https://github.com/wooorm/starry-night> for more info.
/**
* @import {Grammar} from '@wooorm/starry-night'
*/
/** @type {Grammar} */
const grammar = {
dependencies: ['source.c++', 'source.jflex'],
extensions: ['.lex'],
names: ['lex', 'flex'],
patterns: [{include: '#main'}],
repository: {
comments: {
patterns: [
{
begin: '/\\*',
beginCaptures: {
0: {name: 'punctuation.definition.begin.comment.lex'}
},
end: '\\*/',
endCaptures: {0: {name: 'punctuation.definition.end.comment.lex'}},
name: 'comment.block.lex'
},
{
begin: '//',
beginCaptures: {0: {name: 'punctuation.definition.comment.lex'}},
end: '(?=$)',
name: 'comment.line.double-slash.lex'
}
]
},
definition: {
begin: '^\\s*([A-Za-z_][A-Za-z0-9_-]*)',
beginCaptures: {1: {name: 'entity.name.definition.lex'}},
end: '$',
name: 'meta.definition.lex',
patterns: [
{
captures: {0: {patterns: [{include: 'source.lex.regexp'}]}},
match: '(?<=\\s)\\S.*',
name: 'meta.pattern.lex'
}
]
},
definitions: {
begin: '\\A(?!\\s*%%)',
end: '^(?=\\s*(?:%%|(?:package|import)\\s+\\w))',
name: 'meta.definitions.lex',
patterns: [
{include: '#comments'},
{include: '#directives'},
{include: '#passthrough'},
{include: '#definition'}
]
},
directives: {
begin: '^\\s*((%)\\w+)(?=\\s|$)',
captures: {
1: {name: 'keyword.control.directive.lex'},
2: {name: 'punctuation.definition.directive.lex'}
},
end: '(?=$)',
name: 'meta.directive.lex',
patterns: [
{include: '#comments'},
{match: '\\S+', name: 'constant.language.other.lex'}
]
},
jflex: {
begin: '^(?=\\s*(?:package|import)\\s+\\w)',
end: '(?=A)B',
name: 'meta.jflex.lex',
patterns: [{include: 'source.jflex'}]
},
main: {
patterns: [
{include: '#jflex'},
{include: '#comments'},
{include: '#definitions'},
{include: '#rules'},
{include: 'source.c++'}
]
},
passthrough: {
begin: '^%{',
beginCaptures: {0: {name: 'punctuation.section.embedded.begin.lex'}},
end: '^%}',
endCaptures: {0: {name: 'punctuation.section.embedded.end.lex'}},
name: 'meta.code-chunk.lex',
patterns: [{include: 'source.c++'}]
},
'rule.action': {
begin: '(?<!^)(?=\\S)',
end: '(?=\\s*$|^)',
name: 'meta.action.lex',
patterns: [
{include: '#comments'},
{begin: '(?={)', end: '(?<=})', patterns: [{include: 'source.c++'}]},
{
captures: {1: {patterns: [{include: 'source.c++'}]}},
match: '([^{\\s][^{]*?)\\s*$'
}
]
},
'rule.pattern': {
begin: '(?<=^|\\n)(?=\\S)',
end: '(?=\\s|$)',
name: 'meta.pattern.lex',
patterns: [{include: 'source.lex.regexp'}]
},
rules: {
begin: '^\\s*(%%)\\s*(?:$\\s*|(?=/\\*))',
beginCaptures: {1: {name: 'keyword.control.section.begin.lex'}},
end: '^\\s*(%%)\\s*(?:$\\s*|(?=/\\*))',
endCaptures: {1: {name: 'keyword.control.section.end.lex'}},
patterns: [
{include: '#passthrough'},
{include: '#rule.pattern'},
{include: '#rule.action'}
]
},
'user-code': {
begin: '(?<=^%%|\\s%%)',
contentName: 'source.embedded.cpp',
end: '(?=A)B',
name: 'meta.user-code.lex',
patterns: [{include: 'source.c++'}]
}
},
scopeName: 'source.lex'
}
export default grammar