lapyst-rouge 0.1.0 → 0.1.2
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/lapyst-rouge/lexer.rb +251 -23
- data/lib/lapyst-rouge/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bcf766ad0f477171e588cbf8d911652481077f1b65a9470e6f03be2715ac01b
|
4
|
+
data.tar.gz: e74fafd7adefc9fa72ecf84d0f7c87e68a8d1d0d894baee879a00742c107a014
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa5239e36c744f2cfe1834df8288a65680e2dab89ca2c40c4b1ddae9ff27ef596ebbaaa0cadc7a724f163f9c3ca73aa6ba193e07b9a7fc79a9751b853dc0883c
|
7
|
+
data.tar.gz: 7d215a96a384d99e26620271a1984a9f470c7eefc720227891011dcceb02f27ee41d84ead4d43d6a717b8fff04deb5d450b37d664b9370d43220f6fe6c5f00a7
|
data/lib/lapyst-rouge/lexer.rb
CHANGED
@@ -52,6 +52,7 @@ module Rouge
|
|
52
52
|
|
53
53
|
state :strings do
|
54
54
|
rule %r/"/, Str::Double, :double_str
|
55
|
+
rule %r/r"/, Str::Double, :double_str
|
55
56
|
end
|
56
57
|
|
57
58
|
state :in_interp do
|
@@ -79,23 +80,97 @@ module Rouge
|
|
79
80
|
|
80
81
|
annotation_re = "@[\\p{L}_][\\p{L}\\p{N}_\\:]*"
|
81
82
|
|
83
|
+
state :generic_inner do
|
84
|
+
rule %r/\s+/, Text
|
85
|
+
|
86
|
+
rule %r/(?:#{builtin_types.join('|')})\b/, Keyword::Type
|
87
|
+
|
88
|
+
rule %r/#{annotation_re}/, Name::Decorator
|
89
|
+
|
90
|
+
mixin :literals
|
91
|
+
|
92
|
+
rule /\[/ do |m|
|
93
|
+
token Punctuation, m[0]
|
94
|
+
push :generic_inner
|
95
|
+
end
|
96
|
+
|
97
|
+
rule /\]/ do |m|
|
98
|
+
token Punctuation, m[0]
|
99
|
+
|
100
|
+
if (stack[-2].name == :generic_inner) then
|
101
|
+
pop!
|
102
|
+
else
|
103
|
+
case stack[-2].name
|
104
|
+
when :generic_start_var
|
105
|
+
pop!
|
106
|
+
goto :generic_end_var
|
107
|
+
when :generic_start_const
|
108
|
+
pop!
|
109
|
+
goto :generic_end_const
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
state :generic_start_var do rule(//) { push(:generic_inner) } end
|
116
|
+
state :generic_end_var do
|
117
|
+
rule %r/
|
118
|
+
(\s+)
|
119
|
+
( ! | \** )?
|
120
|
+
( [\p{L}_][\p{L}\p{N}_]* )
|
121
|
+
/x do
|
122
|
+
groups Text, Keyword::Declaration, Name::Variable
|
123
|
+
pop!
|
124
|
+
end
|
125
|
+
|
126
|
+
rule(//) { pop! }
|
127
|
+
end
|
128
|
+
|
129
|
+
state :generic_start_const do rule(//) { push(:generic_inner) } end
|
130
|
+
state :generic_end_const do
|
131
|
+
rule %r/
|
132
|
+
(\s+)
|
133
|
+
( ! | \** )?
|
134
|
+
( [\p{L}_][\p{L}\p{N}_]* )
|
135
|
+
/x do
|
136
|
+
groups Text, Keyword::Declaration, Name::Constant
|
137
|
+
pop!
|
138
|
+
end
|
139
|
+
|
140
|
+
rule(//) { pop! }
|
141
|
+
end
|
142
|
+
|
82
143
|
state :var_consts do
|
83
144
|
|
84
145
|
# typed var
|
85
146
|
rule %r/
|
86
147
|
(var\b)(\s+)
|
148
|
+
(?: (#{annotation_re}) (\s+) )?
|
149
|
+
(?: (#{builtin_types.join('|')}\b)|([\p{L}_][\p{L}\p{N}_\:]*) )
|
150
|
+
(\[)
|
151
|
+
/x do
|
152
|
+
groups(
|
153
|
+
Keyword, Text,
|
154
|
+
Name::Decorator, Text,
|
155
|
+
Keyword::Type, Name::Class,
|
156
|
+
Punctuation)
|
157
|
+
push :generic_start_var
|
158
|
+
end
|
159
|
+
|
160
|
+
rule %r/
|
161
|
+
(var\b)(\s+)
|
162
|
+
(?: (#{annotation_re}) (\s+) )?
|
87
163
|
(?: (#{builtin_types.join('|')}\b)|([\p{L}_][\p{L}\p{N}_\:]*) )
|
88
|
-
( \[ [^\(\)]* \] )?
|
89
164
|
(\**)
|
90
165
|
(\s+)
|
91
166
|
( ! | \** )?
|
92
167
|
( [\p{L}_][\p{L}\p{N}_]* )
|
93
|
-
/x do
|
168
|
+
/x do |m|
|
94
169
|
groups(
|
95
170
|
Keyword, Text,
|
171
|
+
Name::Decorator, Text,
|
96
172
|
Keyword::Type, Name::Class,
|
97
173
|
Text,
|
98
|
-
Text,
|
99
174
|
Text,
|
100
175
|
Keyword::Declaration,
|
101
176
|
Name::Variable)
|
@@ -103,22 +178,42 @@ module Rouge
|
|
103
178
|
|
104
179
|
# typed const
|
105
180
|
rule %r(
|
106
|
-
(const\b)
|
107
|
-
(\s+)
|
181
|
+
(const\b)(\s+)
|
182
|
+
(?: (#{annotation_re}) (\s+) )?
|
183
|
+
(?: (#{builtin_types.join('|')}\b)|([\p{L}_][\p{L}\p{N}_\:]*) )
|
184
|
+
(\[)
|
185
|
+
)x do
|
186
|
+
groups(
|
187
|
+
Keyword, Text,
|
188
|
+
Name::Decorator, Text,
|
189
|
+
Keyword::Type, Name::Class,
|
190
|
+
Punctuation)
|
191
|
+
push :generic_start_const
|
192
|
+
end
|
193
|
+
|
194
|
+
rule %r(
|
195
|
+
(const\b)(\s+)
|
196
|
+
(?: (#{annotation_re}) (\s+) )?
|
108
197
|
(?: (#{builtin_types.join('|')}\b)|([\p{L}_][\p{L}\p{N}_\:]*) )
|
109
|
-
( \[ [^\(\)]* \] )?
|
110
198
|
(\**)
|
111
199
|
(\s+)
|
112
200
|
( ! | \** )?
|
113
201
|
( [\p{L}_][\p{L}\p{N}_]* )
|
114
202
|
)x do
|
115
|
-
groups
|
203
|
+
groups(
|
204
|
+
Keyword, Text,
|
205
|
+
Name::Decorator, Text,
|
206
|
+
Keyword::Type, Name::Class,
|
207
|
+
Text,
|
208
|
+
Text,
|
209
|
+
Keyword::Declaration,
|
210
|
+
Name::Constant)
|
116
211
|
end
|
117
212
|
|
118
213
|
# typed prop
|
119
214
|
rule %r(
|
120
|
-
(prop\b)
|
121
|
-
(\s+)
|
215
|
+
(prop\b)(\s+)
|
216
|
+
(?: (#{annotation_re}) (\s+) )?
|
122
217
|
(?: (#{builtin_types.join('|')}\b)|([\p{L}_][\p{L}\p{N}_\:]*) )
|
123
218
|
( \[ [^\(\)]* \] )?
|
124
219
|
(\**)
|
@@ -126,27 +221,43 @@ module Rouge
|
|
126
221
|
( ! | \** )?
|
127
222
|
( [\p{L}_][\p{L}\p{N}_]* )
|
128
223
|
)x do
|
129
|
-
groups
|
224
|
+
groups(
|
225
|
+
Keyword, Text,
|
226
|
+
Name::Decorator, Text,
|
227
|
+
Keyword::Type, Name::Class,
|
228
|
+
Text,
|
229
|
+
Text,
|
230
|
+
Text,
|
231
|
+
Keyword::Declaration,
|
232
|
+
Name::Property)
|
130
233
|
end
|
131
234
|
|
132
235
|
# typeless var
|
133
236
|
rule %r(
|
134
|
-
(var\b)(\**)
|
135
|
-
(\s+)
|
237
|
+
(var\b)(\**)(\s+)
|
238
|
+
(?: (#{annotation_re}) (\s+) )?
|
136
239
|
( ! | \** )?
|
137
240
|
( [\p{L}_][\p{L}\p{N}_]* )
|
138
241
|
)x do
|
139
|
-
groups
|
242
|
+
groups(
|
243
|
+
Keyword, Text, Text,
|
244
|
+
Name::Decorator, Text,
|
245
|
+
Keyword::Declaration,
|
246
|
+
Name::Variable)
|
140
247
|
end
|
141
248
|
|
142
249
|
# typeless const
|
143
250
|
rule %r(
|
144
|
-
(const\b)(\**)
|
145
|
-
(\s+)
|
251
|
+
(const\b)(\**)(\s+)
|
252
|
+
(?: (#{annotation_re}) (\s+) )?
|
146
253
|
( ! | \** )?
|
147
254
|
( [\p{L}_][\p{L}\p{N}_]* )
|
148
255
|
)x do
|
149
|
-
groups
|
256
|
+
groups(
|
257
|
+
Keyword, Text, Text,
|
258
|
+
Name::Decorator, Text,
|
259
|
+
Keyword::Declaration,
|
260
|
+
Name::Constant)
|
150
261
|
end
|
151
262
|
end
|
152
263
|
|
@@ -162,6 +273,7 @@ module Rouge
|
|
162
273
|
switch case default
|
163
274
|
super shapeof cast
|
164
275
|
import as export
|
276
|
+
unit
|
165
277
|
)
|
166
278
|
builtins = %w(self arguments)
|
167
279
|
|
@@ -257,13 +369,62 @@ module Rouge
|
|
257
369
|
rule %r/static/, Keyword::Declaration
|
258
370
|
|
259
371
|
rule %r(
|
260
|
-
(?:
|
372
|
+
(?:
|
373
|
+
(?: (\() ([^\(\)]*) (\)) ) |
|
374
|
+
(?: ([^\(\)\{\}]*) (\s) )
|
375
|
+
)?
|
261
376
|
( \s* )
|
262
377
|
( ! | \** )?
|
263
378
|
( \~?[\p{L}_][\p{L}\p{N}_]* )
|
264
379
|
)x do |m|
|
265
|
-
puts "matches: #{m.inspect}" if @debug
|
266
|
-
|
380
|
+
puts "matches: #{m[0].inspect}" if @debug
|
381
|
+
|
382
|
+
# return tuple, opening bracket
|
383
|
+
token Punctuation, m[1]
|
384
|
+
|
385
|
+
# return tuple, content
|
386
|
+
if m[2] != nil then
|
387
|
+
# this is a tuple, we need to lex it seperatly to highlight builtin types in it
|
388
|
+
s = StringScanner.new(m[2])
|
389
|
+
|
390
|
+
until s.eos?
|
391
|
+
if (s.skip(%r/(?:#{builtin_types.join('|')})\b/)) then
|
392
|
+
token Keyword::Type, s[0]
|
393
|
+
elsif (s.skip(%r/#{annotation_re}/)) then
|
394
|
+
token Name::Decorator, s[0]
|
395
|
+
elsif (s.skip(/,/))
|
396
|
+
token Punctuation, s[0]
|
397
|
+
else
|
398
|
+
token Text, s.getch
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
else
|
403
|
+
token Text, m[2]
|
404
|
+
end
|
405
|
+
|
406
|
+
# return tuple, closing bracket
|
407
|
+
token Punctuation, m[3]
|
408
|
+
|
409
|
+
# plain return type
|
410
|
+
if m[4] =~ %r/(?:#{builtin_types.join('|')})\b/ then
|
411
|
+
token Keyword::Type, m[4]
|
412
|
+
else
|
413
|
+
token Text, m[4]
|
414
|
+
end
|
415
|
+
|
416
|
+
# mandatory whitespace after plain return type
|
417
|
+
token Text, m[5]
|
418
|
+
|
419
|
+
# whitespaces after return type
|
420
|
+
token Text, m[6]
|
421
|
+
|
422
|
+
# optional visibility modifier
|
423
|
+
token Keyword::Declaration, m[7]
|
424
|
+
|
425
|
+
# function / method name
|
426
|
+
token Name::Function, m[8]
|
427
|
+
|
267
428
|
pop!
|
268
429
|
end
|
269
430
|
|
@@ -276,10 +437,77 @@ module Rouge
|
|
276
437
|
rule %r(
|
277
438
|
( [\p{L}_][\p{L}\p{N}_]* )
|
278
439
|
(\s+)
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
440
|
+
)x do
|
441
|
+
groups Name::Class, Text
|
442
|
+
goto :shape_generics
|
443
|
+
end
|
444
|
+
|
445
|
+
rule(//) { pop! }
|
446
|
+
end
|
447
|
+
|
448
|
+
state :shape_generics do
|
449
|
+
rule %r/\s+/, Text
|
450
|
+
|
451
|
+
rule %r/
|
452
|
+
(of)(\s*)(\[)
|
453
|
+
/x do
|
454
|
+
groups Keyword, Text, Punctuation
|
455
|
+
push :shape_generic_inner
|
456
|
+
end
|
457
|
+
|
458
|
+
rule(//) { goto :shape_inheritance }
|
459
|
+
end
|
460
|
+
|
461
|
+
state :shape_generic_inner do
|
462
|
+
rule %r/\s+/, Text
|
463
|
+
|
464
|
+
rule /,/, Text
|
465
|
+
|
466
|
+
rule %r/#{annotation_re}/, Name::Decorator
|
467
|
+
|
468
|
+
rule %r/
|
469
|
+
(const) (\s+) ( [\p{L}_][\p{L}\p{N}_]* )
|
470
|
+
/x do
|
471
|
+
groups Keyword, Text, Name::Constant
|
472
|
+
end
|
473
|
+
|
474
|
+
rule %r/
|
475
|
+
(?: (#{builtin_types.join('|')}\b)|([\p{L}_][\p{L}\p{N}_\:]*) )
|
476
|
+
(\s+)
|
477
|
+
( [\p{L}_][\p{L}\p{N}_]* )
|
478
|
+
/x do |m|
|
479
|
+
groups Keyword::Type, Name::Class, Text, Name::Constant
|
480
|
+
end
|
481
|
+
|
482
|
+
rule %r/
|
483
|
+
( [\p{L}_][\p{L}\p{N}_]* ) (?: (\s*) (\=\>) (\s*) ( [\p{L}_][\p{L}\p{N}_]* ) )?
|
484
|
+
/x do
|
485
|
+
groups Name, Text, Text, Text, Name::Class
|
486
|
+
end
|
487
|
+
|
488
|
+
rule /\[/, Punctuation, :shape_generic_inner
|
489
|
+
|
490
|
+
rule /\]/ do |m|
|
491
|
+
token Punctuation, m[0]
|
492
|
+
|
493
|
+
if (stack[-2].name == :shape_generic_inner) then
|
494
|
+
pop!
|
495
|
+
else
|
496
|
+
pop!
|
497
|
+
goto :shape_inheritance
|
498
|
+
end
|
499
|
+
end
|
500
|
+
|
501
|
+
# TODO: generics of types used inside generic definitions, i.e. 'of [ Cache[12] c ]'
|
502
|
+
end
|
503
|
+
|
504
|
+
state :shape_inheritance do
|
505
|
+
rule %r/\s+/, Text
|
506
|
+
|
507
|
+
rule %r/
|
508
|
+
(use)(\s*\[[^\]]*\])
|
509
|
+
/x do
|
510
|
+
groups Keyword, Text
|
283
511
|
pop!
|
284
512
|
end
|
285
513
|
|
data/lib/lapyst-rouge/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lapyst-rouge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mai-Lapyst
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rouge
|