1
+ import "ace-builds/src-noconflict/ace" ;
2
+ import { PythonHighlightRules } from "ace-builds/src-noconflict/mode-python"
3
+ import { ShHighlightRules } from "ace-builds/src-noconflict/mode-sh"
4
+
5
+ const TextHighlightRules = ace . require ( 'ace/mode/text_highlight_rules' ) . TextHighlightRules ;
6
+ const TextMode = ace . require ( "ace/mode/text" ) . Mode
7
+
8
+ export class BitBakeHighlightRules extends TextHighlightRules {
9
+ constructor ( ) {
10
+ super ( ) ;
11
+ const bitbakeIdentifierRegex = / [ \w _ ] [ \w . \- + { } $ : ] * / ;
12
+
13
+ this . $rules = {
14
+ "start" : [
15
+ {
16
+ // Comment - don't bother handling line continuation in comments
17
+ token : "comment" ,
18
+ regex : "#(.*)$" ,
19
+ next : "start"
20
+ } ,
21
+ {
22
+ // python task
23
+ token : "keyword" ,
24
+ regex : / p y t h o n (? = \s | \( ) / ,
25
+ next : "python_task" ,
26
+ } ,
27
+ {
28
+ // fakeroot task
29
+ token : "keyword" ,
30
+ regex : / f a k e r o o t (? = \s ) / ,
31
+ next : "shell_task" ,
32
+ } ,
33
+ {
34
+ // def
35
+ token : "keyword" ,
36
+ regex : "def" ,
37
+ next : "python-def-start" ,
38
+ } ,
39
+ {
40
+ // addhandler, addtask, deltask, EXPORT_FUNCTIONS
41
+ token : "keyword" ,
42
+ regex : / (?: a d d h a n d l e r | a d d t a s k | d e l t a s k | E X P O R T _ F U N C T I O N S ) (? = \s ) / ,
43
+ next : "directive" ,
44
+ } ,
45
+ {
46
+ token : "keyword" ,
47
+ regex : / (?: i n h e r i t | r e q u i r e | i n c l u d e ) (? = \s ) / ,
48
+ next : "unquoted_value" ,
49
+ } ,
50
+ {
51
+ token : "variable" ,
52
+ regex : bitbakeIdentifierRegex ,
53
+ next : "task_or_variable" ,
54
+ }
55
+ ] ,
56
+ "task_or_variable" : [
57
+ {
58
+ token : "keyword.operator" ,
59
+ regex : / = | \? { 1 , 2 } = | = \+ | \+ = | : = | = : / ,
60
+ } ,
61
+ {
62
+ // Varflag
63
+ token : [ "paren.lparen" , "constant.character" , "paren.rparen" ] ,
64
+ regex : / ( \[ ) ( [ - \w _ + . ] + ) ( ] ) /
65
+ } ,
66
+ {
67
+ token : "string" ,
68
+ regex : / " .* " $ / ,
69
+ next : "start" ,
70
+ } ,
71
+ {
72
+ token : "string" ,
73
+ regex : / ' .* ' $ / ,
74
+ next : "start" ,
75
+ } ,
76
+ {
77
+ token : "paren.lparen" ,
78
+ regex : / \( / ,
79
+ push : [ {
80
+ token : "paren.rparen" ,
81
+ regex : / \) / ,
82
+ next : "pop" ,
83
+ } ]
84
+ } ,
85
+ {
86
+ token : "paren.lparen" ,
87
+ regex : / \{ / ,
88
+ next : "sh-start" ,
89
+ }
90
+ ] ,
91
+ "directive" : [
92
+ {
93
+ token : "keyword" ,
94
+ regex : / (?: a f t e r | b e f o r e ) (? = \s ) / ,
95
+ } ,
96
+ {
97
+ token : "text" ,
98
+ regex : bitbakeIdentifierRegex ,
99
+ } ,
100
+ {
101
+ // TODO: handle line continuations
102
+ token : "text" ,
103
+ regex : / $ / ,
104
+ next : "start" ,
105
+ }
106
+ ] ,
107
+ "unquoted_value" : [
108
+ {
109
+ token : [ "text" , "constant.language.escape" ] ,
110
+ regex : / ( .+ ?) ( \\ ) $ / ,
111
+ } ,
112
+ {
113
+ token : "text" ,
114
+ regex : / .+ $ / ,
115
+ next : "start" ,
116
+ }
117
+ ] ,
118
+ "python_task" : [
119
+ {
120
+ token : "keyword" ,
121
+ regex : / f a k e r o o t (? = \s ) /
122
+ } ,
123
+ {
124
+ token : "entity.function" ,
125
+ regex : bitbakeIdentifierRegex ,
126
+ } ,
127
+ {
128
+ token : "paren.lparen" ,
129
+ regex : / \( / ,
130
+ push : [ {
131
+ token : "paren.rparen" ,
132
+ regex : / \) / ,
133
+ next : "pop" ,
134
+ } ]
135
+ } ,
136
+ {
137
+ token : "paren.lparen" ,
138
+ regex : / \{ / ,
139
+ next : "python-start" ,
140
+ }
141
+ ] ,
142
+ "shell_task" : [
143
+ {
144
+ token : "entity.function" ,
145
+ regex : bitbakeIdentifierRegex ,
146
+ } ,
147
+ {
148
+ token : "paren.lparen" ,
149
+ regex : / \( / ,
150
+ push : [ {
151
+ token : "paren.rparen" ,
152
+ regex : / \) / ,
153
+ next : "pop" ,
154
+ } ]
155
+ } ,
156
+ {
157
+ token : "paren.lparen" ,
158
+ regex : / \{ / ,
159
+ next : "sh-start" ,
160
+ }
161
+ ]
162
+ } ;
163
+
164
+ this . embedRules ( PythonHighlightRules , "python-" , [
165
+ {
166
+ token : "paren.rparen" ,
167
+ regex : "^}$" ,
168
+ next : "start"
169
+ }
170
+ ] ) ;
171
+
172
+ this . embedRules ( ShHighlightRules , "sh-" , [
173
+ {
174
+ token : "paren.rparen" ,
175
+ regex : "^}$" ,
176
+ next : "start"
177
+ }
178
+ ] ) ;
179
+
180
+ this . embedRules ( PythonHighlightRules , "python-def-" , [
181
+ {
182
+ token : "text" ,
183
+ // A Python def function ends on the first non-indented line
184
+ regex : / ^ (? = [ ^ \s ] ) / ,
185
+ next : "start"
186
+ }
187
+ ] ) ;
188
+
189
+ this . normalizeRules ( ) ;
190
+ }
191
+ }
192
+
193
+ export default class BitBakeMode extends TextMode {
194
+ constructor ( ) {
195
+ super ( ) ;
196
+ this . HighlightRules = BitBakeHighlightRules ;
197
+ }
198
+ }
0 commit comments