rouge 4.1.3 → 4.7.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/Gemfile +10 -7
- data/LICENSE +2 -1
- data/lib/rouge/cli.rb +4 -5
- data/lib/rouge/demos/bicep +10 -0
- data/lib/rouge/demos/cobol +103 -0
- data/lib/rouge/demos/codeowners +6 -0
- data/lib/rouge/demos/gjs +23 -0
- data/lib/rouge/demos/gts +36 -0
- data/lib/rouge/demos/iecst +21 -0
- data/lib/rouge/demos/json5 +12 -0
- data/lib/rouge/demos/mojo +10 -0
- data/lib/rouge/demos/p4 +99 -0
- data/lib/rouge/demos/svelte +29 -0
- data/lib/rouge/formatters/html_legacy.rb +0 -3
- data/lib/rouge/guessers/disambiguation.rb +24 -3
- data/lib/rouge/lexer.rb +8 -6
- data/lib/rouge/lexers/ada.rb +5 -5
- data/lib/rouge/lexers/bicep.rb +111 -0
- data/lib/rouge/lexers/bpf.rb +10 -10
- data/lib/rouge/lexers/brainfuck.rb +1 -0
- data/lib/rouge/lexers/clean.rb +4 -4
- data/lib/rouge/lexers/cobol.rb +137 -0
- data/lib/rouge/lexers/codeowners.rb +30 -0
- data/lib/rouge/lexers/cpp.rb +5 -4
- data/lib/rouge/lexers/crystal.rb +17 -17
- data/lib/rouge/lexers/csharp.rb +37 -34
- data/lib/rouge/lexers/css.rb +192 -150
- data/lib/rouge/lexers/dart.rb +1 -1
- data/lib/rouge/lexers/docker.rb +2 -2
- data/lib/rouge/lexers/ecl.rb +2 -2
- data/lib/rouge/lexers/eiffel.rb +1 -1
- data/lib/rouge/lexers/elixir.rb +5 -1
- data/lib/rouge/lexers/gdscript.rb +4 -4
- data/lib/rouge/lexers/ghc_cmm.rb +3 -3
- data/lib/rouge/lexers/gjs.rb +39 -0
- data/lib/rouge/lexers/go.rb +7 -5
- data/lib/rouge/lexers/groovy.rb +6 -4
- data/lib/rouge/lexers/gts.rb +39 -0
- data/lib/rouge/lexers/hcl.rb +1 -0
- data/lib/rouge/lexers/html.rb +1 -1
- data/lib/rouge/lexers/iecst.rb +92 -0
- data/lib/rouge/lexers/ini.rb +7 -5
- data/lib/rouge/lexers/java.rb +1 -1
- data/lib/rouge/lexers/javascript.rb +4 -4
- data/lib/rouge/lexers/json5.rb +74 -0
- data/lib/rouge/lexers/julia.rb +3 -2
- data/lib/rouge/lexers/kotlin.rb +1 -1
- data/lib/rouge/lexers/lua.rb +24 -3
- data/lib/rouge/lexers/make.rb +5 -1
- data/lib/rouge/lexers/markdown.rb +2 -1
- data/lib/rouge/lexers/mathematica.rb +1 -1
- data/lib/rouge/lexers/meson.rb +0 -1
- data/lib/rouge/lexers/mojo.rb +35 -0
- data/lib/rouge/lexers/nasm.rb +5 -4
- data/lib/rouge/lexers/nginx.rb +1 -0
- data/lib/rouge/lexers/objective_c/common.rb +0 -2
- data/lib/rouge/lexers/objective_c.rb +1 -1
- data/lib/rouge/lexers/ocl.rb +2 -2
- data/lib/rouge/lexers/openedge.rb +0 -2
- data/lib/rouge/lexers/p4.rb +81 -0
- data/lib/rouge/lexers/php/keywords.rb +86 -136
- data/lib/rouge/lexers/php.rb +42 -2
- data/lib/rouge/lexers/plsql.rb +5 -5
- data/lib/rouge/lexers/python.rb +59 -32
- data/lib/rouge/lexers/robot_framework.rb +1 -1
- data/lib/rouge/lexers/ruby.rb +21 -21
- data/lib/rouge/lexers/sass/common.rb +1 -1
- data/lib/rouge/lexers/scala.rb +5 -2
- data/lib/rouge/lexers/sql.rb +1 -1
- data/lib/rouge/lexers/svelte.rb +91 -0
- data/lib/rouge/lexers/syzlang.rb +0 -1
- data/lib/rouge/lexers/tcl.rb +7 -2
- data/lib/rouge/lexers/terraform.rb +4 -3
- data/lib/rouge/lexers/toml.rb +56 -45
- data/lib/rouge/lexers/ttcn3.rb +0 -2
- data/lib/rouge/lexers/typescript/common.rb +9 -0
- data/lib/rouge/lexers/xojo.rb +6 -6
- data/lib/rouge/lexers/yang.rb +1 -1
- data/lib/rouge/regex_lexer.rb +13 -0
- data/lib/rouge/tex_theme_renderer.rb +1 -1
- data/lib/rouge/themes/base16.rb +23 -18
- data/lib/rouge/themes/bw.rb +1 -0
- data/lib/rouge/themes/colorful.rb +1 -0
- data/lib/rouge/themes/github.rb +1 -0
- data/lib/rouge/themes/gruvbox.rb +4 -1
- data/lib/rouge/themes/igor_pro.rb +3 -0
- data/lib/rouge/themes/magritte.rb +1 -0
- data/lib/rouge/themes/molokai.rb +2 -1
- data/lib/rouge/themes/monokai.rb +2 -1
- data/lib/rouge/themes/monokai_sublime.rb +4 -3
- data/lib/rouge/themes/pastie.rb +1 -0
- data/lib/rouge/themes/thankful_eyes.rb +1 -0
- data/lib/rouge/themes/tulip.rb +1 -0
- data/lib/rouge/token.rb +2 -1
- data/lib/rouge/version.rb +1 -1
- metadata +23 -6
data/lib/rouge/lexers/php.rb
CHANGED
|
@@ -100,6 +100,11 @@ module Rouge
|
|
|
100
100
|
end
|
|
101
101
|
|
|
102
102
|
state :names do
|
|
103
|
+
rule %r/(?:public|protected|private)\(set\)/i do
|
|
104
|
+
push :in_visibility
|
|
105
|
+
token Keyword
|
|
106
|
+
end
|
|
107
|
+
|
|
103
108
|
rule %r/#{id_with_ns}(?=\s*\()/ do |m|
|
|
104
109
|
name = m[0].downcase
|
|
105
110
|
if self.class.keywords.include? name
|
|
@@ -179,7 +184,7 @@ module Rouge
|
|
|
179
184
|
|
|
180
185
|
# numbers
|
|
181
186
|
rule %r/(\d[_\d]*)?\.(\d[_\d]*)?(e[+-]?\d[_\d]*)?/i, Num::Float
|
|
182
|
-
rule %r/
|
|
187
|
+
rule %r/0o?[0-7][0-7_]*/i, Num::Oct
|
|
183
188
|
rule %r/0b[01][01_]*/i, Num::Bin
|
|
184
189
|
rule %r/0x[a-f0-9][a-f0-9_]*/i, Num::Hex
|
|
185
190
|
rule %r/\d[_\d]*/, Num::Integer
|
|
@@ -243,6 +248,13 @@ module Rouge
|
|
|
243
248
|
groups Keyword::Declaration, Text, Name::Class
|
|
244
249
|
end
|
|
245
250
|
|
|
251
|
+
rule %r/(enum)
|
|
252
|
+
(\s+)
|
|
253
|
+
(#{id_with_ns})/ix do |m|
|
|
254
|
+
groups Keyword::Declaration, Text, Name::Class
|
|
255
|
+
push :in_enum
|
|
256
|
+
end
|
|
257
|
+
|
|
246
258
|
mixin :names
|
|
247
259
|
|
|
248
260
|
rule %r/[;,\(\)\{\}\[\]]/, Punctuation
|
|
@@ -280,6 +292,9 @@ module Rouge
|
|
|
280
292
|
end
|
|
281
293
|
|
|
282
294
|
state :in_const do
|
|
295
|
+
rule %r/(\??#{id})(\s+)(#{id})/i do
|
|
296
|
+
groups Keyword::Type, Text, Name::Constant
|
|
297
|
+
end
|
|
283
298
|
rule id, Name::Constant
|
|
284
299
|
rule %r/=/, Operator, :in_assign
|
|
285
300
|
mixin :escape
|
|
@@ -307,7 +322,8 @@ module Rouge
|
|
|
307
322
|
rule %r/,/, Punctuation
|
|
308
323
|
rule %r/[.]{3}/, Punctuation
|
|
309
324
|
rule %r/=/, Operator, :in_assign
|
|
310
|
-
rule %r/\b(?:public|protected|private|readonly)\b/i, Keyword
|
|
325
|
+
rule %r/\b(?:public|protected|private|readonly)(?:\(set\)|\b)/i, Keyword
|
|
326
|
+
rule %r/\breadonly\b/i, Keyword
|
|
311
327
|
rule %r/\??#{id}/, Keyword::Type, :in_assign
|
|
312
328
|
mixin :escape
|
|
313
329
|
mixin :whitespace
|
|
@@ -369,6 +385,7 @@ module Rouge
|
|
|
369
385
|
end
|
|
370
386
|
|
|
371
387
|
state :in_visibility do
|
|
388
|
+
rule %r/\b(?:public|protected|private)(?:\(set\)|\b)/i, Keyword
|
|
372
389
|
rule %r/\b(?:readonly|static)\b/i, Keyword
|
|
373
390
|
rule %r/(?=(abstract|const|function)\b)/i, Keyword, :pop!
|
|
374
391
|
rule %r/\??#{id}/, Keyword::Type, :pop!
|
|
@@ -376,6 +393,29 @@ module Rouge
|
|
|
376
393
|
mixin :whitespace
|
|
377
394
|
mixin :return
|
|
378
395
|
end
|
|
396
|
+
|
|
397
|
+
state :in_enum do
|
|
398
|
+
rule %r/:/, Punctuation, :in_enum_base_type
|
|
399
|
+
rule %r/\{/, Punctuation, :in_enum_body
|
|
400
|
+
mixin :escape
|
|
401
|
+
mixin :whitespace
|
|
402
|
+
mixin :return
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
state :in_enum_base_type do
|
|
406
|
+
rule id, Keyword::Type, :pop!
|
|
407
|
+
mixin :escape
|
|
408
|
+
mixin :whitespace
|
|
409
|
+
mixin :return
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
state :in_enum_body do
|
|
413
|
+
rule %r/\}/, Punctuation, :pop!
|
|
414
|
+
rule %r/(case)(\s+)(#{id})/i do
|
|
415
|
+
groups Keyword, Text, Name::Constant
|
|
416
|
+
end
|
|
417
|
+
mixin :php
|
|
418
|
+
end
|
|
379
419
|
end
|
|
380
420
|
end
|
|
381
421
|
end
|
data/lib/rouge/lexers/plsql.rb
CHANGED
|
@@ -472,7 +472,7 @@ module Rouge
|
|
|
472
472
|
# A double-quoted string refers to a database object in our default SQL
|
|
473
473
|
rule %r/"/, Operator, :double_string
|
|
474
474
|
# preprocessor directive treated as special comment
|
|
475
|
-
rule %r/(\$(?:IF|THEN|ELSE|ELSIF|ERROR|END|(
|
|
475
|
+
rule %r/(\$(?:IF|THEN|ELSE|ELSIF|ERROR|END|(?:\$\$?[a-z]\w*)))(\s+)/im do
|
|
476
476
|
groups Comment::Preproc, Text
|
|
477
477
|
end
|
|
478
478
|
|
|
@@ -503,7 +503,7 @@ module Rouge
|
|
|
503
503
|
# Special processing for keywords with multiple contexts
|
|
504
504
|
#
|
|
505
505
|
# this madness is to keep the word "replace" from being treated as a builtin function in this context
|
|
506
|
-
rule %r/(create)(\s+)(?:(or)(\s+)(replace)(\s+))?(package|function|procedure|type)(?:(\s+)(body))?(\s+)(
|
|
506
|
+
rule %r/(create)(\s+)(?:(or)(\s+)(replace)(\s+))?(package|function|procedure|type)(?:(\s+)(body))?(\s+)([a-z][\w$]*)/im do
|
|
507
507
|
groups Keyword::Reserved, Text, Keyword::Reserved, Text, Keyword::Reserved, Text, Keyword::Reserved, Text, Keyword::Reserved, Text, Name
|
|
508
508
|
end
|
|
509
509
|
# similar for MERGE keywords
|
|
@@ -515,7 +515,7 @@ module Rouge
|
|
|
515
515
|
# General keyword classification with sepcial attention to names
|
|
516
516
|
# in a chained "dot" notation.
|
|
517
517
|
#
|
|
518
|
-
rule %r/(
|
|
518
|
+
rule %r/([a-zA-Z][\w$]*)(\.(?=\w))?/ do |m|
|
|
519
519
|
if self.class.keywords_type.include? m[1].upcase
|
|
520
520
|
tok = Keyword::Type
|
|
521
521
|
elsif self.class.keywords_func.include? m[1].upcase
|
|
@@ -556,11 +556,11 @@ module Rouge
|
|
|
556
556
|
|
|
557
557
|
state :dotnames do
|
|
558
558
|
# if we are followed by a dot and another name, we are an ordinary name
|
|
559
|
-
rule %r/(
|
|
559
|
+
rule %r/([a-zA-Z][\w\$]*)(\.(?=\w))/ do
|
|
560
560
|
groups Name, Punctuation
|
|
561
561
|
end
|
|
562
562
|
# this rule WILL be true if something pushed into our state. That is our state contract
|
|
563
|
-
rule %r
|
|
563
|
+
rule %r/[a-zA-Z][\w\$]*/ do |m|
|
|
564
564
|
if self.class.keywords_func.include? m[0].upcase
|
|
565
565
|
# The Function lookup allows collection methods like COUNT, FIRST, LAST, etc.. to be
|
|
566
566
|
# classified correctly. Occasionally misidentifies ordinary names as builtin functions,
|
data/lib/rouge/lexers/python.rb
CHANGED
|
@@ -8,8 +8,8 @@ module Rouge
|
|
|
8
8
|
desc "The Python programming language (python.org)"
|
|
9
9
|
tag 'python'
|
|
10
10
|
aliases 'py'
|
|
11
|
-
filenames '*.py', '*.pyw', '*.sc', 'SConstruct', 'SConscript',
|
|
12
|
-
'*.bzl', 'BUCK', 'BUILD', 'BUILD.bazel', 'WORKSPACE'
|
|
11
|
+
filenames '*.py', '*.pyi', '*.pyw', '*.sc', 'SConstruct', 'SConscript',
|
|
12
|
+
'*.tac', '*.bzl', 'BUCK', 'BUILD', 'BUILD.bazel', 'WORKSPACE'
|
|
13
13
|
mimetypes 'text/x-python', 'application/x-python'
|
|
14
14
|
|
|
15
15
|
def self.detect?(text)
|
|
@@ -20,22 +20,24 @@ module Rouge
|
|
|
20
20
|
@keywords ||= %w(
|
|
21
21
|
assert break continue del elif else except exec
|
|
22
22
|
finally for global if lambda pass print raise
|
|
23
|
-
return try while yield as with from import
|
|
23
|
+
return try while yield as with from import
|
|
24
24
|
async await nonlocal
|
|
25
25
|
)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def self.builtins
|
|
29
29
|
@builtins ||= %w(
|
|
30
|
-
__import__ abs all any apply ascii
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
__import__ abs aiter all anext any apply ascii
|
|
31
|
+
basestring bin bool buffer breakpoint bytearray bytes
|
|
32
|
+
callable chr classmethod cmp coerce compile complex
|
|
33
|
+
delattr dict dir divmod enumerate eval exec execfile exit
|
|
34
|
+
file filter float format frozenset getattr globals
|
|
35
|
+
hasattr hash help hex
|
|
36
|
+
id input int intern isinstance issubclass iter len list locals long
|
|
37
|
+
map max memoryview min next object oct open ord pow print property
|
|
38
|
+
range raw_input reduce reload repr reversed round set setattr slice
|
|
39
|
+
sorted staticmethod str sum super tuple type unichr unicode vars
|
|
40
|
+
xrange zip
|
|
39
41
|
)
|
|
40
42
|
end
|
|
41
43
|
|
|
@@ -45,25 +47,26 @@ module Rouge
|
|
|
45
47
|
|
|
46
48
|
def self.exceptions
|
|
47
49
|
@exceptions ||= %w(
|
|
48
|
-
ArithmeticError AssertionError AttributeError
|
|
49
|
-
|
|
50
|
-
BytesWarning ChildProcessError ConnectionAbortedError
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
NotADirectoryError NotImplemented NotImplementedError
|
|
59
|
-
OverflowError OverflowWarning PendingDeprecationWarning
|
|
60
|
-
ProcessLookupError
|
|
61
|
-
RuntimeError RuntimeWarning
|
|
62
|
-
StopIteration SyntaxError SyntaxWarning
|
|
63
|
-
TabError TimeoutError TypeError
|
|
64
|
-
UnicodeEncodeError UnicodeError
|
|
65
|
-
UnicodeWarning UserWarning ValueError VMSError
|
|
66
|
-
WindowsError
|
|
50
|
+
ArithmeticError AssertionError AttributeError BaseException
|
|
51
|
+
BaseExceptionGroup BlockingIOError BrokenPipeError BufferError
|
|
52
|
+
BytesWarning ChildProcessError ConnectionAbortedError ConnectionError
|
|
53
|
+
ConnectionRefusedError ConnectionResetError DeprecationWarning
|
|
54
|
+
EOFError EnvironmentError EncodingWarning Exception ExceptionGroup
|
|
55
|
+
FileExistsError FileNotFoundError FloatingPointError FutureWarning
|
|
56
|
+
GeneratorExit IOError ImportError ImportWarning IndentationError
|
|
57
|
+
IndexError InterruptedError IsADirectoryError
|
|
58
|
+
KeyError KeyboardInterrupt LookupError
|
|
59
|
+
MemoryError ModuleNotFoundError
|
|
60
|
+
NameError NotADirectoryError NotImplemented NotImplementedError
|
|
61
|
+
OSError OverflowError OverflowWarning PendingDeprecationWarning
|
|
62
|
+
PermissionError ProcessLookupError PythonFinalizationError
|
|
63
|
+
RecursionError ReferenceError ResourceWarning RuntimeError RuntimeWarning
|
|
64
|
+
StandardError StopAsyncIteration StopIteration SyntaxError SyntaxWarning
|
|
65
|
+
SystemError SystemExit TabError TimeoutError TypeError
|
|
66
|
+
UnboundLocalError UnicodeDecodeError UnicodeEncodeError UnicodeError
|
|
67
|
+
UnicodeTranslateError UnicodeWarning UserWarning ValueError VMSError
|
|
68
|
+
Warning WindowsError
|
|
69
|
+
ZeroDivisionError
|
|
67
70
|
)
|
|
68
71
|
end
|
|
69
72
|
|
|
@@ -121,12 +124,14 @@ module Rouge
|
|
|
121
124
|
|
|
122
125
|
# TODO: not in python 3
|
|
123
126
|
rule %r/`.*?`/, Str::Backtick
|
|
124
|
-
rule %r/([
|
|
127
|
+
rule %r/([rtfbu]{0,2})('''|"""|['"])/i do |m|
|
|
125
128
|
groups Str::Affix, Str::Heredoc
|
|
126
129
|
current_string.register type: m[1].downcase, delim: m[2]
|
|
127
130
|
push :generic_string
|
|
128
131
|
end
|
|
129
132
|
|
|
133
|
+
mixin :soft_keywords
|
|
134
|
+
|
|
130
135
|
# using negative lookbehind so we don't match property names
|
|
131
136
|
rule %r/(?<!\.)#{identifier}/ do |m|
|
|
132
137
|
if self.class.keywords.include? m[0]
|
|
@@ -166,6 +171,28 @@ module Rouge
|
|
|
166
171
|
rule identifier, Name::Class, :pop!
|
|
167
172
|
end
|
|
168
173
|
|
|
174
|
+
state :soft_keywords do
|
|
175
|
+
rule %r/
|
|
176
|
+
(^[ \t]*)
|
|
177
|
+
(match|case)\b
|
|
178
|
+
(?![ \t]*
|
|
179
|
+
(?:[:,;=^&|@~)\]}] |
|
|
180
|
+
(?:#{Python.keywords.join('|')})\b))
|
|
181
|
+
/x do |m|
|
|
182
|
+
token Text::Whitespace, m[1]
|
|
183
|
+
token Keyword, m[2]
|
|
184
|
+
push :soft_keywords_inner
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
state :soft_keywords_inner do
|
|
189
|
+
rule %r((\s+)([^\n_]*)(_\b)) do |m|
|
|
190
|
+
groups Text::Whitespace, Text, Keyword
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
rule(//) { pop! }
|
|
194
|
+
end
|
|
195
|
+
|
|
169
196
|
state :raise do
|
|
170
197
|
rule %r/from\b/, Keyword
|
|
171
198
|
rule %r/raise\b/, Keyword
|
|
@@ -10,7 +10,7 @@ module Rouge
|
|
|
10
10
|
title "Robot Framework"
|
|
11
11
|
desc 'Robot Framework is a generic open source automation testing framework (robotframework.org)'
|
|
12
12
|
|
|
13
|
-
filenames '*.robot'
|
|
13
|
+
filenames '*.robot', '*.resource'
|
|
14
14
|
mimetypes 'text/x-robot'
|
|
15
15
|
|
|
16
16
|
def initialize(opts = {})
|
data/lib/rouge/lexers/ruby.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Rouge
|
|
|
11
11
|
filenames '*.rb', '*.ruby', '*.rbw', '*.rake', '*.gemspec', '*.podspec',
|
|
12
12
|
'Rakefile', 'Guardfile', 'Gemfile', 'Capfile', 'Podfile',
|
|
13
13
|
'Vagrantfile', '*.ru', '*.prawn', 'Berksfile', '*.arb',
|
|
14
|
-
'Dangerfile', 'Fastfile', 'Deliverfile', 'Appfile'
|
|
14
|
+
'Dangerfile', 'Fastfile', 'Deliverfile', 'Appfile', '*.thor', 'Thorfile'
|
|
15
15
|
|
|
16
16
|
mimetypes 'text/x-ruby', 'application/x-ruby'
|
|
17
17
|
|
|
@@ -24,7 +24,7 @@ module Rouge
|
|
|
24
24
|
rule %r(
|
|
25
25
|
: # initial :
|
|
26
26
|
@{0,2} # optional ivar, for :@foo and :@@foo
|
|
27
|
-
[
|
|
27
|
+
[\p{Ll}_]\p{Word}*[!?]? # the symbol
|
|
28
28
|
)xi, Str::Symbol
|
|
29
29
|
|
|
30
30
|
# special symbols
|
|
@@ -39,7 +39,7 @@ module Rouge
|
|
|
39
39
|
# %-sigiled strings
|
|
40
40
|
# %(abc), %[abc], %<abc>, %.abc., %r.abc., etc
|
|
41
41
|
delimiter_map = { '{' => '}', '[' => ']', '(' => ')', '<' => '>' }
|
|
42
|
-
rule %r/%([rqswQWxiI])?([^\
|
|
42
|
+
rule %r/%([rqswQWxiI])?([^\p{Word}\s])/ do |m|
|
|
43
43
|
open = Regexp.escape(m[2])
|
|
44
44
|
close = Regexp.escape(delimiter_map[m[2]] || m[2])
|
|
45
45
|
interp = /[rQWxI]/ === m[1] || !m[1]
|
|
@@ -57,7 +57,7 @@ module Rouge
|
|
|
57
57
|
token toktype
|
|
58
58
|
|
|
59
59
|
push do
|
|
60
|
-
uniq_chars =
|
|
60
|
+
uniq_chars = [open, close].uniq.join
|
|
61
61
|
uniq_chars = '' if open == close && open == "\\#"
|
|
62
62
|
rule %r/\\[##{uniq_chars}\\]/, Str::Escape
|
|
63
63
|
# nesting rules only with asymmetric delimiters
|
|
@@ -83,7 +83,7 @@ module Rouge
|
|
|
83
83
|
|
|
84
84
|
state :strings do
|
|
85
85
|
mixin :symbols
|
|
86
|
-
rule %r/\b[
|
|
86
|
+
rule %r/\b[\p{Ll}_]\p{Word}*?[?!]?:\s+/, Str::Symbol, :expr_start
|
|
87
87
|
rule %r/'(\\\\|\\'|[^'])*'/, Str::Single
|
|
88
88
|
rule %r/"/, Str::Double, :simple_string
|
|
89
89
|
rule %r/(?<!\.)`/, Str::Backtick, :simple_backtick
|
|
@@ -177,9 +177,9 @@ module Rouge
|
|
|
177
177
|
rule decimal, Num::Integer
|
|
178
178
|
|
|
179
179
|
# names
|
|
180
|
-
rule %r/@@[
|
|
181
|
-
rule %r/@[
|
|
182
|
-
rule %r/\$\
|
|
180
|
+
rule %r/@@[\p{Ll}_]\p{Word}*/i, Name::Variable::Class
|
|
181
|
+
rule %r/@[\p{Ll}_]\p{Word}*/i, Name::Variable::Instance
|
|
182
|
+
rule %r/\$\p{Word}+/, Name::Variable::Global
|
|
183
183
|
rule %r(\$[!@&`'+~=/\\,;.<>_*\$?:"]), Name::Variable::Global
|
|
184
184
|
rule %r/\$-[0adFiIlpvw]/, Name::Variable::Global
|
|
185
185
|
rule %r/::/, Operator
|
|
@@ -193,7 +193,7 @@ module Rouge
|
|
|
193
193
|
rule %r(
|
|
194
194
|
(module)
|
|
195
195
|
(\s+)
|
|
196
|
-
([
|
|
196
|
+
([\p{L}_][\p{L}0-9_]*(::[\p{L}_][\p{L}0-9_]*)*)
|
|
197
197
|
)x do
|
|
198
198
|
groups Keyword, Text, Name::Namespace
|
|
199
199
|
end
|
|
@@ -219,14 +219,14 @@ module Rouge
|
|
|
219
219
|
# Otherwise, they will be parsed as :method_call
|
|
220
220
|
rule %r/\.{2,3}/, Operator, :expr_start
|
|
221
221
|
|
|
222
|
-
rule %r/[
|
|
223
|
-
rule %r/(\.|::)(\s*)([
|
|
222
|
+
rule %r/[\p{Lu}][\p{L}0-9_]*/, Name::Constant, :method_call
|
|
223
|
+
rule %r/(\.|::)(\s*)([\p{Ll}_]\p{Word}*[!?]?|[*%&^`~+-\/\[<>=])/ do
|
|
224
224
|
groups Punctuation, Text, Name::Function
|
|
225
225
|
push :method_call
|
|
226
226
|
end
|
|
227
227
|
|
|
228
|
-
rule %r/[
|
|
229
|
-
rule %r/[
|
|
228
|
+
rule %r/[\p{L}_]\p{Word}*[?!]/, Name, :expr_start
|
|
229
|
+
rule %r/[\p{L}_]\p{Word}*/, Name, :method_call
|
|
230
230
|
rule %r/\*\*|<<?|>>?|>=|<=|<=>|=~|={3}|!~|&&?|\|\||\./,
|
|
231
231
|
Operator, :expr_start
|
|
232
232
|
rule %r/[-+\/*%=<>&!^|~]=?/, Operator, :expr_start
|
|
@@ -236,7 +236,7 @@ module Rouge
|
|
|
236
236
|
end
|
|
237
237
|
|
|
238
238
|
state :has_heredocs do
|
|
239
|
-
rule %r/(?<!\
|
|
239
|
+
rule %r/(?<!\p{Word})(<<[-~]?)(["`']?)([\p{L}_]\p{Word}*)(\2)/ do |m|
|
|
240
240
|
token Operator, m[1]
|
|
241
241
|
token Name::Constant, "#{m[2]}#{m[3]}#{m[4]}"
|
|
242
242
|
@heredoc_queue << [['<<-', '<<~'].include?(m[1]), m[3]]
|
|
@@ -293,11 +293,11 @@ module Rouge
|
|
|
293
293
|
rule %r/\s+/, Text
|
|
294
294
|
rule %r/\(/, Punctuation, :defexpr
|
|
295
295
|
rule %r(
|
|
296
|
-
(?:([
|
|
296
|
+
(?:([\p{L}_]\p{Word}*)(\.))?
|
|
297
297
|
(
|
|
298
|
-
[
|
|
298
|
+
[\p{L}_]\p{Word}*[!?]? |
|
|
299
299
|
\*\*? | [-+]@? | [/%&\|^`~] | \[\]=? |
|
|
300
|
-
|
|
300
|
+
<=>? | <<? | >>? | >= | ===?
|
|
301
301
|
)
|
|
302
302
|
)x do |m|
|
|
303
303
|
puts "matches: #{[m[0], m[1], m[2], m[3]].inspect}" if @debug
|
|
@@ -310,7 +310,7 @@ module Rouge
|
|
|
310
310
|
|
|
311
311
|
state :classname do
|
|
312
312
|
rule %r/\s+/, Text
|
|
313
|
-
rule %r/\
|
|
313
|
+
rule %r/\p{Word}+(::\p{Word}+)+/, Name::Class
|
|
314
314
|
|
|
315
315
|
rule %r/\(/ do
|
|
316
316
|
token Punctuation
|
|
@@ -324,7 +324,7 @@ module Rouge
|
|
|
324
324
|
goto :expr_start
|
|
325
325
|
end
|
|
326
326
|
|
|
327
|
-
rule %r/[
|
|
327
|
+
rule %r/[\p{Lu}_]\p{Word}*/, Name::Class, :pop!
|
|
328
328
|
|
|
329
329
|
rule(//) { pop! }
|
|
330
330
|
end
|
|
@@ -364,7 +364,7 @@ module Rouge
|
|
|
364
364
|
|
|
365
365
|
state :string_intp do
|
|
366
366
|
rule %r/[#][{]/, Str::Interpol, :in_interp
|
|
367
|
-
rule %r/#(@@?|\$)[
|
|
367
|
+
rule %r/#(@@?|\$)[\p{Ll}_]\p{Word}*/i, Str::Interpol
|
|
368
368
|
end
|
|
369
369
|
|
|
370
370
|
state :string_intp_escaped do
|
|
@@ -419,7 +419,7 @@ module Rouge
|
|
|
419
419
|
rule %r(
|
|
420
420
|
[?](\\[MC]-)* # modifiers
|
|
421
421
|
(\\([\\abefnrstv\#"']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})|\S)
|
|
422
|
-
(?!\
|
|
422
|
+
(?!\p{Word})
|
|
423
423
|
)x, Str::Char, :pop!
|
|
424
424
|
|
|
425
425
|
# special case for using a single space. Ruby demands that
|
data/lib/rouge/lexers/scala.rb
CHANGED
|
@@ -13,7 +13,8 @@ module Rouge
|
|
|
13
13
|
mimetypes 'text/x-scala', 'application/x-scala'
|
|
14
14
|
|
|
15
15
|
# As documented in the ENBF section of the scala specification
|
|
16
|
-
#
|
|
16
|
+
# https://scala-lang.org/files/archive/spec/2.13/13-syntax-summary.html
|
|
17
|
+
# https://en.wikipedia.org/wiki/Unicode_character_property#General_Category
|
|
17
18
|
whitespace = /\p{Space}/
|
|
18
19
|
letter = /[\p{L}$_]/
|
|
19
20
|
upper = /[\p{Lu}$_]/
|
|
@@ -24,8 +25,10 @@ module Rouge
|
|
|
24
25
|
# negative lookahead to filter out other classes
|
|
25
26
|
op = %r(
|
|
26
27
|
(?!#{whitespace}|#{letter}|#{digits}|#{parens}|#{delims})
|
|
27
|
-
[
|
|
28
|
+
[-!#%&*/:?@\\^\p{Sm}\p{So}]
|
|
28
29
|
)x
|
|
30
|
+
# manually removed +<=>|~ from regexp because they're in property Sm
|
|
31
|
+
# pp CHRS:(0x00..0x7f).map(&:chr).grep(/\p{Sm}/)
|
|
29
32
|
|
|
30
33
|
idrest = %r(#{letter}(?:#{letter}|#{digits})*(?:(?<=_)#{op}+)?)x
|
|
31
34
|
|
data/lib/rouge/lexers/sql.rb
CHANGED
|
@@ -115,7 +115,7 @@ module Rouge
|
|
|
115
115
|
rule %r/"/, Name::Variable, :double_string
|
|
116
116
|
rule %r/`/, Name::Variable, :backtick
|
|
117
117
|
|
|
118
|
-
rule %r/\w
|
|
118
|
+
rule %r/\w+/ do |m|
|
|
119
119
|
if self.class.keywords_type.include? m[0].upcase
|
|
120
120
|
token Name::Builtin
|
|
121
121
|
elsif self.class.keywords.include? m[0].upcase
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Rouge
|
|
5
|
+
module Lexers
|
|
6
|
+
load_lexer 'html.rb'
|
|
7
|
+
|
|
8
|
+
class Svelte < HTML
|
|
9
|
+
desc 'Svelte single-file components (https://svelte.dev/)'
|
|
10
|
+
tag 'svelte'
|
|
11
|
+
filenames '*.svelte'
|
|
12
|
+
mimetypes 'text/x-svelte', 'application/x-svelte'
|
|
13
|
+
|
|
14
|
+
def initialize(*)
|
|
15
|
+
super
|
|
16
|
+
# todo add support for typescript script blocks
|
|
17
|
+
@js = Javascript.new(options)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Shorthand syntax for passing attributes - ex, `{src}` instead of `src={src}`
|
|
21
|
+
prepend :tag do
|
|
22
|
+
rule %r/(\{)\s*([a-zA-Z0-9_]+)\s*(})/m do
|
|
23
|
+
groups Str::Interpol, Name::Variable, Str::Interpol
|
|
24
|
+
pop!
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
prepend :attr do
|
|
29
|
+
# Duplicate template_start mixin here with a pop!
|
|
30
|
+
# Because otherwise we'll never exit the attr state
|
|
31
|
+
rule %r/\{/ do
|
|
32
|
+
token Str::Interpol
|
|
33
|
+
pop!
|
|
34
|
+
push :template
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# handle templates within attribute single/double quotes
|
|
39
|
+
prepend :dq do
|
|
40
|
+
mixin :template_start
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
prepend :sq do
|
|
44
|
+
mixin :template_start
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
prepend :root do
|
|
48
|
+
# detect curly braces within HTML text (outside of tags/attributes)
|
|
49
|
+
rule %r/([^<&{]*)(\{)(\s*)/ do
|
|
50
|
+
groups Text, Str::Interpol, Text
|
|
51
|
+
push :template
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
state :template_start do
|
|
56
|
+
# open template
|
|
57
|
+
rule %r/\s*\{\s*/, Str::Interpol, :template
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
state :template do
|
|
61
|
+
# template end
|
|
62
|
+
rule %r/}/, Str::Interpol, :pop!
|
|
63
|
+
|
|
64
|
+
# Allow JS lexer to handle matched curly braces within template
|
|
65
|
+
rule(/(?<=^|[^\\])\{+.*?(?<=^|[^\\])\}+/) do
|
|
66
|
+
delegate @js
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# keywords
|
|
70
|
+
rule %r/@(debug|html)\b/, Keyword
|
|
71
|
+
rule %r/(#await)(.*)(then|catch)(\s+)(\w+)/ do |m|
|
|
72
|
+
token Keyword, m[1]
|
|
73
|
+
delegate @js, m[2]
|
|
74
|
+
token Keyword, m[3]
|
|
75
|
+
token Text, m[4]
|
|
76
|
+
delegate @js, m[5]
|
|
77
|
+
end
|
|
78
|
+
rule %r/([#\/])(await|each|if|key)\b/, Keyword
|
|
79
|
+
rule %r/(:else)(\s+)(if)?\b/ do
|
|
80
|
+
groups Keyword, Text, Keyword
|
|
81
|
+
end
|
|
82
|
+
rule %r/:?(catch|then)\b/, Keyword
|
|
83
|
+
|
|
84
|
+
# allow JS parser to handle anything that's not a curly brace
|
|
85
|
+
rule %r/[^{}]+/ do
|
|
86
|
+
delegate @js
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
data/lib/rouge/lexers/syzlang.rb
CHANGED
data/lib/rouge/lexers/tcl.rb
CHANGED
|
@@ -57,9 +57,9 @@ module Rouge
|
|
|
57
57
|
|
|
58
58
|
def self.gen_command_state(name='')
|
|
59
59
|
state(:"command#{name}") do
|
|
60
|
-
|
|
60
|
+
rule %r/#/, Comment, :comment
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
mixin :word
|
|
63
63
|
|
|
64
64
|
rule %r/(?=#{CHARS[END_WORD]})/ do
|
|
65
65
|
push :"params#{name}"
|
|
@@ -163,6 +163,11 @@ module Rouge
|
|
|
163
163
|
rule %r/\\./m, Str::Escape
|
|
164
164
|
end
|
|
165
165
|
|
|
166
|
+
state :comment do
|
|
167
|
+
rule %r/.*[^\\]\n/, Comment, :pop!
|
|
168
|
+
rule %r/.*\\\n/, Comment
|
|
169
|
+
end
|
|
170
|
+
|
|
166
171
|
state :string do
|
|
167
172
|
rule %r/"/, Str::Double, :pop!
|
|
168
173
|
mixin :interp
|
|
@@ -11,7 +11,7 @@ module Rouge
|
|
|
11
11
|
|
|
12
12
|
tag 'terraform'
|
|
13
13
|
aliases 'tf'
|
|
14
|
-
filenames '*.tf'
|
|
14
|
+
filenames '*.tf', '*.tfvars', '*.tofu'
|
|
15
15
|
|
|
16
16
|
def self.keywords
|
|
17
17
|
@keywords ||= Set.new %w(
|
|
@@ -39,8 +39,9 @@ module Rouge
|
|
|
39
39
|
|
|
40
40
|
state :strings do
|
|
41
41
|
rule %r/\\./, Str::Escape
|
|
42
|
+
rule %r/(\$[\$]+|%[%]+)(\{)/, Str
|
|
42
43
|
rule %r/\$\{/ do
|
|
43
|
-
token
|
|
44
|
+
token Punctuation
|
|
44
45
|
push :interpolation
|
|
45
46
|
end
|
|
46
47
|
end
|
|
@@ -66,7 +67,7 @@ module Rouge
|
|
|
66
67
|
|
|
67
68
|
state :interpolation do
|
|
68
69
|
rule %r/\}/ do
|
|
69
|
-
token
|
|
70
|
+
token Punctuation
|
|
70
71
|
pop!
|
|
71
72
|
end
|
|
72
73
|
|