broomhlda 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/hl/define.ay +10 -16
- data/lib/hl/formatters/html.ay +1 -1
- data/lib/hl/lexer.ay +2 -4
- data/lib/hl/lexers/yaml.ay +348 -0
- metadata +13 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3a9585d07f566041aaa2f64eb3c39d8549659b0
|
4
|
+
data.tar.gz: f177b9a4c5037651d946fed5b778701199732973
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db598fbeb791fb044348c1a28925edee938c043ed4a235170b6ac2c4c90c7059e1d8ae6e98c371d1b3209c76e420975667b3222f37636c726d51ab058a51d152
|
7
|
+
data.tar.gz: 8cc5f90657ff5fcf48e722bc0daa958bceb7f449d17f17b3153e74fb39b8c3ff21453546bec350d9a4a32c90d6f845b544c9e85ea039775e7762a09469bcf93e
|
data/lib/hl/define.ay
CHANGED
@@ -53,14 +53,11 @@ def(type-from(`(using(~who)))):
|
|
53
53
|
|
54
54
|
def(type-from(x)): raise("unknown match type: " + x inspect)
|
55
55
|
|
56
|
-
def(regexp-from(x
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
); call(~x))
|
62
|
-
|
63
|
-
`(regexps[~(Atomy Grammar AST Number new(regexps size - 1))])
|
56
|
+
def(regexp-from(x)):
|
57
|
+
`([x]: Regexp new(
|
58
|
+
x source
|
59
|
+
x options | @info fetch(.flags)
|
60
|
+
); call(~x))
|
64
61
|
|
65
62
|
def(state-from('pop)): '(State Pop new)
|
66
63
|
def(state-from(`(pop(~n)))): `(State PopNum new(~n))
|
@@ -86,15 +83,13 @@ macro(lex(~name) [~*args]: ~*tokens):
|
|
86
83
|
|
87
84
|
body = []
|
88
85
|
|
89
|
-
regexps = []
|
90
|
-
|
91
86
|
tokens each [c]:
|
92
87
|
c match:
|
93
88
|
-- implicit continue state
|
94
89
|
`(~x is(~y)):
|
95
90
|
branches <<
|
96
91
|
`(Matcher new(
|
97
|
-
~(regexp-from(x
|
92
|
+
~(regexp-from(x))
|
98
93
|
~(type-from(y))
|
99
94
|
State Continue new
|
100
95
|
))
|
@@ -103,7 +98,7 @@ macro(lex(~name) [~*args]: ~*tokens):
|
|
103
98
|
`(~x is(~y) -> ~z):
|
104
99
|
branches <<
|
105
100
|
`(Matcher new(
|
106
|
-
~(regexp-from(x
|
101
|
+
~(regexp-from(x))
|
107
102
|
~(type-from(y))
|
108
103
|
~(state-from(z))
|
109
104
|
))
|
@@ -112,7 +107,7 @@ macro(lex(~name) [~*args]: ~*tokens):
|
|
112
107
|
`(~x is(~y) => ~z):
|
113
108
|
branches <<
|
114
109
|
`(Matcher new(
|
115
|
-
~(regexp-from(x
|
110
|
+
~(regexp-from(x))
|
116
111
|
~(type-from(y))
|
117
112
|
State GoTo new(@matchers, .~z)
|
118
113
|
))
|
@@ -126,6 +121,5 @@ macro(lex(~name) [~*args]: ~*tokens):
|
|
126
121
|
|
127
122
|
body << `([~*branches] flatten)
|
128
123
|
|
129
|
-
`([
|
130
|
-
|
131
|
-
} call([~*regexps]))
|
124
|
+
`(@matchers[.~name] = proc [~*args]:
|
125
|
+
~*body)
|
data/lib/hl/formatters/html.ay
CHANGED
data/lib/hl/lexer.ay
CHANGED
@@ -40,7 +40,7 @@ fn(try-all(matchers)):
|
|
40
40
|
break
|
41
41
|
|
42
42
|
unless(closest):
|
43
|
-
|
43
|
+
Self error(NoMatchFor new(@input))
|
44
44
|
|
45
45
|
skipped = closest pre-match
|
46
46
|
@input = closest post-match
|
@@ -55,7 +55,7 @@ fn(try-all(matchers)):
|
|
55
55
|
|
56
56
|
tokens(closest, worked type)
|
57
57
|
|
58
|
-
|
58
|
+
class(Lexer):
|
59
59
|
def(initialize(input)):
|
60
60
|
@input = input dup
|
61
61
|
|
@@ -95,5 +95,3 @@ lexer = class:
|
|
95
95
|
|
96
96
|
def(flags &x):
|
97
97
|
@info[.flags] = x call
|
98
|
-
|
99
|
-
const-set(.Lexer, lexer)
|
@@ -0,0 +1,348 @@
|
|
1
|
+
use(require("atomy"))
|
2
|
+
use(require("hl/define"))
|
3
|
+
|
4
|
+
lexer = lexer:
|
5
|
+
name: "YAML"
|
6
|
+
aliases: "yaml"
|
7
|
+
extensions: [".yaml", ".yml"]
|
8
|
+
mimetypes: "text/x-yaml"
|
9
|
+
start: .root
|
10
|
+
flags: Regexp MULTILINE
|
11
|
+
|
12
|
+
-- starting point for lexing
|
13
|
+
lex(root):
|
14
|
+
@indent-stack = []
|
15
|
+
@indent = -1
|
16
|
+
@next-indent = 0
|
17
|
+
|
18
|
+
-- ignored whitespace
|
19
|
+
r"[ ]+(?=#|$)" is(text)
|
20
|
+
|
21
|
+
-- line breaks
|
22
|
+
r"\n+" is(text)
|
23
|
+
|
24
|
+
-- comments
|
25
|
+
r"#[^\n]*" is(comment.single)
|
26
|
+
|
27
|
+
-- '%YAML' directive
|
28
|
+
r"^%YAML(?=[ ]|$)" is(name.tag) -> do-all(
|
29
|
+
go-to(reset-indent)
|
30
|
+
go-to(yaml-directive)
|
31
|
+
)
|
32
|
+
|
33
|
+
-- '%TAG' directive
|
34
|
+
r"^%TAG(?=[ ]|$)" is(name.tag) -> do-all(
|
35
|
+
go-to(reset-indent)
|
36
|
+
go-to(tag-directive)
|
37
|
+
)
|
38
|
+
|
39
|
+
-- document start/end indicators
|
40
|
+
r"^(?:---|\.\.\.)(?=[ ]|$)" is(name.namespace) -> do-all(
|
41
|
+
go-to(reset-indent)
|
42
|
+
go-to(block-line)
|
43
|
+
)
|
44
|
+
|
45
|
+
-- indentation
|
46
|
+
r"[ ]*(?!\s|$)" is(text) -> do-all(
|
47
|
+
go-to(save-start-indent)
|
48
|
+
go-to(block-line)
|
49
|
+
go-to(indentation)
|
50
|
+
)
|
51
|
+
|
52
|
+
|
53
|
+
lex(reset-indent):
|
54
|
+
@indent-stack = []
|
55
|
+
@indent = -1
|
56
|
+
@next-indent = 0
|
57
|
+
|
58
|
+
r"" is(text) -> pop
|
59
|
+
|
60
|
+
lex(save-start-indent) [d]:
|
61
|
+
@next-indent = d[0] size
|
62
|
+
|
63
|
+
when(@next-indent < @indent):
|
64
|
+
while(@next-indent < @indent):
|
65
|
+
@indent = @indent-stack pop
|
66
|
+
|
67
|
+
r"" is(text) -> pop
|
68
|
+
|
69
|
+
lex(save-indent) [d]:
|
70
|
+
@next-indent += d[0] size
|
71
|
+
|
72
|
+
r"" is(text) -> pop
|
73
|
+
|
74
|
+
lex(set-indent) [d]:
|
75
|
+
when(@indent < @next-indent):
|
76
|
+
@indent-stack << @indent
|
77
|
+
@indent = @next-indent
|
78
|
+
|
79
|
+
@next-indent += d[0] size
|
80
|
+
|
81
|
+
r"" is(text) -> pop
|
82
|
+
|
83
|
+
lex(set-implicit-indent) [d]:
|
84
|
+
when(@indent < @next-indent):
|
85
|
+
@indent-stack << @indent
|
86
|
+
@indent = @next-indent
|
87
|
+
|
88
|
+
r"" is(text) -> pop
|
89
|
+
|
90
|
+
|
91
|
+
lex(ignored-line):
|
92
|
+
-- ignored whitespace
|
93
|
+
r"[ ]+(?=#|$)" is(text)
|
94
|
+
|
95
|
+
-- a comment
|
96
|
+
r"#[^\n]*" is(comment.single)
|
97
|
+
|
98
|
+
-- line break
|
99
|
+
r"\n" is(text) -> pop(2)
|
100
|
+
|
101
|
+
|
102
|
+
lex(yaml-directive):
|
103
|
+
-- the version number
|
104
|
+
r"([ ]+)([0-9]+\.[0-9]+)" is(by-groups(text, number)) => ignored-line
|
105
|
+
|
106
|
+
|
107
|
+
lex(tag-directive):
|
108
|
+
-- a tag handle and the corresponding prefix
|
109
|
+
r"([ ]+)(!|![\w-]*!)([ ]+)(!|!?[\w;/?:@&=+$,.!~*'()\[\]%-]+)" is(
|
110
|
+
by-groups(text, keyword.type, text, keyword.type)) => ignored-line
|
111
|
+
|
112
|
+
|
113
|
+
lex(indentation):
|
114
|
+
-- trailing whitespaces are ignored
|
115
|
+
r"[ ]*$" is(text) -> pop(2)
|
116
|
+
|
117
|
+
-- whitespaces preceding block collection indicators
|
118
|
+
r"[ ]+(?=[?:-](?:[ ]|$))" is(text) => save-indent
|
119
|
+
|
120
|
+
-- block collection indicators
|
121
|
+
r"[?:-](?=[ ]|$)" is(punctuation.indicator) => set-indent
|
122
|
+
|
123
|
+
-- the beginning a block line
|
124
|
+
r"[ ]*" is(text) -> do-all(pop, go-to(save-indent))
|
125
|
+
|
126
|
+
|
127
|
+
lex(block-line):
|
128
|
+
-- the line end
|
129
|
+
r"[ ]*(?=#|$)" is(text) -> pop -- something(Text)
|
130
|
+
|
131
|
+
-- whitespaces separating tokens
|
132
|
+
r"[ ]+" is(text)
|
133
|
+
|
134
|
+
-- tags, anchors and aliases,
|
135
|
+
any-of(descriptors)
|
136
|
+
|
137
|
+
-- block collections and scalars
|
138
|
+
any-of(block-nodes)
|
139
|
+
|
140
|
+
-- flow collections and quoted scalars
|
141
|
+
any-of(flow-nodes)
|
142
|
+
|
143
|
+
-- a plain scalar
|
144
|
+
r"(?=[^\s?:,\[\]{}#&*!|>'\"%@`-]|[?:-]\S)" is(name.variable) => plain-scalar-in-block-context -- something(Name.Variable)
|
145
|
+
|
146
|
+
|
147
|
+
lex(descriptors):
|
148
|
+
-- a full-form tag
|
149
|
+
r"!<[\w;/?:@&=+$,.!~*'()\[\]%-]+>" is(keyword.type)
|
150
|
+
|
151
|
+
-- a tag in the form '!', '!suffix' or '!handle!suffix'
|
152
|
+
r"!(?:[\w-]+)?(?:![\w;/?:@&=+$,.!~*'()\[\]%-]+)?" is(keyword.type)
|
153
|
+
|
154
|
+
-- an anchor
|
155
|
+
r"&[\w-]+" is(name.label)
|
156
|
+
|
157
|
+
-- an alias
|
158
|
+
r"\*[\w-]+" is(name.variable)
|
159
|
+
|
160
|
+
|
161
|
+
lex(block-nodes):
|
162
|
+
-- implicit key
|
163
|
+
r":(?=[ ]|$)" is(punctuation.indicator) => set-implicit-indent
|
164
|
+
|
165
|
+
-- literal and folded scalars
|
166
|
+
r"[|>][+-]?\n(?=([ ]*))" is(punctuation.indicator) => block-scalar-content
|
167
|
+
|
168
|
+
-- literal and folded scalars with explicit indent levels
|
169
|
+
r"[|>][+-]?([0-9]+)\n" is(punctuation.indicator) => block-scalar-content-with-indent
|
170
|
+
r"[|>]([0-9]+)[+-]?\n" is(punctuation.indicator) => block-scalar-content-with-indent
|
171
|
+
|
172
|
+
|
173
|
+
lex(block-scalar-content) [d]:
|
174
|
+
-- line break
|
175
|
+
r"\n" is(text)
|
176
|
+
|
177
|
+
-- indented line
|
178
|
+
r"^([ ]{#{d[1] size}})([^\n]*)" is(by-groups(text, name.constant))
|
179
|
+
|
180
|
+
-- unindented; leave state
|
181
|
+
r"^([ ]{0,#{d[1] size - 1}})(?=[^ ])" is(text) -> pop(2)
|
182
|
+
|
183
|
+
|
184
|
+
lex(block-scalar-content-with-indent) [d]:
|
185
|
+
-- line break
|
186
|
+
r"\n" is(text)
|
187
|
+
|
188
|
+
-- indented line
|
189
|
+
r"^([ ]{#{d[1] to-i}})([^\n]*)" is(by-groups(text, name.constant))
|
190
|
+
|
191
|
+
-- unindented; leave state
|
192
|
+
r"^([ ]{0,#{d[1] to-i - 1}})(?=[^ ])" is(text) -> pop(2)
|
193
|
+
|
194
|
+
|
195
|
+
lex(flow-nodes):
|
196
|
+
-- a flow sequence
|
197
|
+
r"\[" is(punctuation.indicator) => flow-sequence
|
198
|
+
|
199
|
+
-- a flow mapping
|
200
|
+
r"\{" is(punctuation.indicator) => flow-mapping
|
201
|
+
|
202
|
+
-- a single-quoted scalar
|
203
|
+
r"'" is(string) => single-quoted-scalar
|
204
|
+
|
205
|
+
-- a double-quoted scalar
|
206
|
+
r"\"" is(string) => double-quoted-scalar
|
207
|
+
|
208
|
+
|
209
|
+
lex(flow-collection):
|
210
|
+
-- whitespaces
|
211
|
+
r"[ ]+" is(text)
|
212
|
+
|
213
|
+
-- line breaks
|
214
|
+
r"\n+" is(text)
|
215
|
+
|
216
|
+
-- a comment
|
217
|
+
r"#[^\n]*" is(comment.single)
|
218
|
+
|
219
|
+
-- simple indicators
|
220
|
+
r"[?:,]" is(punctuation.indicator)
|
221
|
+
|
222
|
+
-- tags, anchors and aliases
|
223
|
+
any-of(descriptors)
|
224
|
+
|
225
|
+
-- nested collections and quoted scalars
|
226
|
+
any-of(flow-nodes)
|
227
|
+
|
228
|
+
-- a plain scalar
|
229
|
+
r"(?=[^\s?:,\[\]{}#&*!|>'\"%@`])" is(name.variable) => plain-scalar-in-flow-context
|
230
|
+
|
231
|
+
|
232
|
+
lex(flow-sequence):
|
233
|
+
-- include flow collection rules
|
234
|
+
any-of(flow-collection)
|
235
|
+
|
236
|
+
-- the closing indicator
|
237
|
+
r"\]" is(punctuation.indicator) -> pop
|
238
|
+
|
239
|
+
|
240
|
+
lex(flow-mapping):
|
241
|
+
-- include flow collection rules
|
242
|
+
any-of(flow-collection)
|
243
|
+
|
244
|
+
-- the closing indicator
|
245
|
+
r"\}" is(punctuation.indicator) -> pop
|
246
|
+
|
247
|
+
|
248
|
+
lex(quoted-scalar-whitespaces):
|
249
|
+
-- leading and trailing whitespaces are ignored
|
250
|
+
r"^[ ]+" is(text)
|
251
|
+
r"[ ]+$" is(text)
|
252
|
+
|
253
|
+
-- line breaks are ignored
|
254
|
+
r"\n+" is(text)
|
255
|
+
|
256
|
+
-- other whitespaces are a part of the value
|
257
|
+
r"[ ]+" is(name.variable)
|
258
|
+
|
259
|
+
|
260
|
+
lex(single-quoted-scalar):
|
261
|
+
-- include whitespace and line break rules
|
262
|
+
any-of(quoted-scalar-whitespaces)
|
263
|
+
|
264
|
+
-- escaping of the quote character
|
265
|
+
r"\'\'" is(string.escape)
|
266
|
+
|
267
|
+
-- regular non-whitespace characters
|
268
|
+
r"[^\s\']+" is(string)
|
269
|
+
|
270
|
+
-- the closing quote
|
271
|
+
r"\'" is(string) -> pop
|
272
|
+
|
273
|
+
|
274
|
+
lex(double-quoted-scalar):
|
275
|
+
-- include whitespace and line break rules
|
276
|
+
any-of(quoted-scalar-whitespaces)
|
277
|
+
|
278
|
+
-- escaping of special characters
|
279
|
+
r"\\[0abt\tn\nvfre \"\\N_LP]" is(string)
|
280
|
+
|
281
|
+
-- escape codes
|
282
|
+
r"\\(?:x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})" is(string.escape)
|
283
|
+
|
284
|
+
-- regular non-whitespace characters
|
285
|
+
r"[^\s\"\\]+" is(string)
|
286
|
+
|
287
|
+
-- the closing quote
|
288
|
+
r"\"" is(string) -> pop
|
289
|
+
|
290
|
+
|
291
|
+
lex(plain-scalar-in-block-context-new-line):
|
292
|
+
-- empty lines
|
293
|
+
r"^[ ]+$" is(text)
|
294
|
+
|
295
|
+
-- line breaks
|
296
|
+
r"\n+" is(text)
|
297
|
+
|
298
|
+
-- document start and document end indicators
|
299
|
+
r"^(?=---|\.\.\.)" is(name.namespace) -> pop(3)
|
300
|
+
|
301
|
+
-- continuing indentation spaces
|
302
|
+
r"^[ ]{#{@indent}}" is(text) -> pop
|
303
|
+
|
304
|
+
-- unindented; pop out of scalar
|
305
|
+
r"^[ ]{0,#{@indent - 1}}(?=[^ ])" is(text) -> pop(3)
|
306
|
+
|
307
|
+
|
308
|
+
lex(plain-scalar-in-block-context):
|
309
|
+
-- the scalar ends with the ':' indicator
|
310
|
+
r"[ ]*(?=:[ ]|:$)" is(text) -> pop -- something(Text)
|
311
|
+
|
312
|
+
-- the scalar ends with whitespaces followed by a comment
|
313
|
+
r"[ ]+(?=#)" is(text) -> pop
|
314
|
+
|
315
|
+
-- trailing whitespaces are ignored
|
316
|
+
r"[ ]+$" is(text)
|
317
|
+
|
318
|
+
-- line breaks are ignored
|
319
|
+
r"\n+" is(text) => plain-scalar-in-block-context-new-line
|
320
|
+
|
321
|
+
-- other whitespaces are a part of the value
|
322
|
+
r"[ ]+" is(literal.scalar.plain)
|
323
|
+
|
324
|
+
-- regular non-whitespace characters
|
325
|
+
r"(?::(?!\s)|[^\s:])+" is(name.property) --literal.scalar.plain)
|
326
|
+
|
327
|
+
|
328
|
+
lex(plain-scalar-in-flow-context):
|
329
|
+
-- the scalar ends with an indicator character
|
330
|
+
r"[ ]*(?=[,:?\[\]{}])" is(text) -> pop -- something(Text)
|
331
|
+
|
332
|
+
-- the scalar ends with a comment
|
333
|
+
r"[ ]+(?=#)" is(text) -> pop
|
334
|
+
|
335
|
+
-- leading and trailing whitespaces are ignored
|
336
|
+
r"^[ ]+" is(text)
|
337
|
+
r"[ ]+$" is(text)
|
338
|
+
|
339
|
+
-- line breaks are ignored
|
340
|
+
r"\n+" is(text)
|
341
|
+
|
342
|
+
-- other whitespaces are a part of the value
|
343
|
+
r"[ ]+" is(name.variable)
|
344
|
+
|
345
|
+
-- regular non-whitespace characters
|
346
|
+
r"[^\s,:?\[\]{}]+" is(name.variable)
|
347
|
+
|
348
|
+
const-set(.Lexer, lexer)
|
metadata
CHANGED
@@ -1,39 +1,39 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: broomhlda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Suraci
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: atomy
|
15
|
-
|
15
|
+
prerelease: false
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
18
|
- - "~>"
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.6.
|
20
|
+
version: 0.6.3
|
20
21
|
type: :runtime
|
21
|
-
|
22
|
-
requirement: !ruby/object:Gem::Requirement
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.6.
|
26
|
+
version: 0.6.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
|
-
|
29
|
+
prerelease: false
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
32
|
- - "~>"
|
32
33
|
- !ruby/object:Gem::Version
|
33
34
|
version: '10.4'
|
34
35
|
type: :development
|
35
|
-
|
36
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
@@ -215,9 +215,10 @@ files:
|
|
215
215
|
- lib/hl/lexers/imported/xslt.ay
|
216
216
|
- lib/hl/lexers/imported/xtend.ay
|
217
217
|
- lib/hl/lexers/ruby.ay
|
218
|
+
- lib/hl/lexers/yaml.ay
|
218
219
|
- lib/hl/state.ay
|
219
220
|
- lib/hl/token.ay
|
220
|
-
homepage:
|
221
|
+
homepage: https://vito.github.io/atomy
|
221
222
|
licenses:
|
222
223
|
- Apache-2.0
|
223
224
|
metadata: {}
|
@@ -237,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
238
|
version: '0'
|
238
239
|
requirements: []
|
239
240
|
rubyforge_project:
|
240
|
-
rubygems_version: 2.4.
|
241
|
+
rubygems_version: 2.4.6
|
241
242
|
signing_key:
|
242
243
|
specification_version: 4
|
243
244
|
summary: broomhlda syntax highlighter and tokenizer
|