rouge 3.20.0 → 3.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rouge.rb +1 -0
- data/lib/rouge/cli.rb +32 -2
- data/lib/rouge/demos/brightscript +6 -0
- data/lib/rouge/demos/email +11 -0
- data/lib/rouge/demos/j +12 -0
- data/lib/rouge/demos/janet +3 -0
- data/lib/rouge/demos/postscript +9 -0
- data/lib/rouge/demos/ssh +4 -0
- data/lib/rouge/demos/systemd +4 -0
- data/lib/rouge/formatters/html_line_highlighter.rb +24 -0
- data/lib/rouge/formatters/html_line_table.rb +1 -3
- data/lib/rouge/formatters/html_linewise.rb +2 -3
- data/lib/rouge/lexer.rb +38 -20
- data/lib/rouge/lexers/apex.rb +9 -7
- data/lib/rouge/lexers/batchfile.rb +3 -2
- data/lib/rouge/lexers/brightscript.rb +147 -0
- data/lib/rouge/lexers/cpp.rb +6 -5
- data/lib/rouge/lexers/css.rb +3 -1
- data/lib/rouge/lexers/docker.rb +2 -2
- data/lib/rouge/lexers/elm.rb +5 -5
- data/lib/rouge/lexers/email.rb +39 -0
- data/lib/rouge/lexers/ghc_core.rb +2 -1
- data/lib/rouge/lexers/graphql.rb +1 -1
- data/lib/rouge/lexers/hack.rb +1 -1
- data/lib/rouge/lexers/html.rb +6 -6
- data/lib/rouge/lexers/http.rb +8 -2
- data/lib/rouge/lexers/isbl.rb +2 -2
- data/lib/rouge/lexers/j.rb +244 -0
- data/lib/rouge/lexers/janet.rb +218 -0
- data/lib/rouge/lexers/javascript.rb +11 -3
- data/lib/rouge/lexers/jinja.rb +22 -7
- data/lib/rouge/lexers/jsl.rb +1 -1
- data/lib/rouge/lexers/jsonnet.rb +4 -3
- data/lib/rouge/lexers/jsp.rb +2 -3
- data/lib/rouge/lexers/julia.rb +4 -2
- data/lib/rouge/lexers/kotlin.rb +8 -4
- data/lib/rouge/lexers/opentype_feature_file.rb +0 -1
- data/lib/rouge/lexers/perl.rb +27 -7
- data/lib/rouge/lexers/php.rb +274 -128
- data/lib/rouge/lexers/postscript.rb +93 -0
- data/lib/rouge/lexers/powershell.rb +41 -29
- data/lib/rouge/lexers/q.rb +1 -1
- data/lib/rouge/lexers/rego.rb +27 -12
- data/lib/rouge/lexers/ruby.rb +1 -1
- data/lib/rouge/lexers/rust.rb +5 -3
- data/lib/rouge/lexers/sass/common.rb +1 -0
- data/lib/rouge/lexers/smarty.rb +1 -1
- data/lib/rouge/lexers/ssh.rb +33 -0
- data/lib/rouge/lexers/systemd.rb +34 -0
- data/lib/rouge/lexers/twig.rb +4 -4
- data/lib/rouge/lexers/velocity.rb +1 -1
- data/lib/rouge/lexers/wollok.rb +0 -1
- data/lib/rouge/lexers/xml.rb +5 -3
- data/lib/rouge/lexers/yaml.rb +5 -3
- data/lib/rouge/regex_lexer.rb +56 -1
- data/lib/rouge/version.rb +1 -1
- metadata +17 -2
data/lib/rouge/lexers/wollok.rb
CHANGED
data/lib/rouge/lexers/xml.rb
CHANGED
@@ -12,6 +12,8 @@ module Rouge
|
|
12
12
|
mimetypes 'text/xml', 'application/xml', 'image/svg+xml',
|
13
13
|
'application/rss+xml', 'application/atom+xml'
|
14
14
|
|
15
|
+
# Documentation: https://www.w3.org/TR/xml11/#charsets and https://www.w3.org/TR/xml11/#sec-suggested-names
|
16
|
+
|
15
17
|
def self.detect?(text)
|
16
18
|
return false if text.doctype?(/html/)
|
17
19
|
return true if text =~ /\A<\?xml\b/
|
@@ -27,10 +29,10 @@ module Rouge
|
|
27
29
|
rule %r/<![^>]*>/, Comment::Preproc
|
28
30
|
|
29
31
|
# open tags
|
30
|
-
rule %r(<\s*[\
|
32
|
+
rule %r(<\s*[\p{L}:_][\p{Word}\p{Cf}:.·-]*)m, Name::Tag, :tag
|
31
33
|
|
32
34
|
# self-closing tags
|
33
|
-
rule %r(<\s*/\s*[\
|
35
|
+
rule %r(<\s*/\s*[\p{L}:_][\p{Word}\p{Cf}:.·-]*\s*>)m, Name::Tag
|
34
36
|
end
|
35
37
|
|
36
38
|
state :comment do
|
@@ -41,7 +43,7 @@ module Rouge
|
|
41
43
|
|
42
44
|
state :tag do
|
43
45
|
rule %r/\s+/m, Text
|
44
|
-
rule %r/[\
|
46
|
+
rule %r/[\p{L}:_][\p{Word}\p{Cf}:.·-]*\s*=/m, Name::Attribute, :attr
|
45
47
|
rule %r(/?\s*>), Name::Tag, :pop!
|
46
48
|
end
|
47
49
|
|
data/lib/rouge/lexers/yaml.rb
CHANGED
@@ -11,6 +11,8 @@ module Rouge
|
|
11
11
|
aliases 'yml'
|
12
12
|
filenames '*.yaml', '*.yml'
|
13
13
|
|
14
|
+
# Documentation: https://yaml.org/spec/1.2/spec.html
|
15
|
+
|
14
16
|
def self.detect?(text)
|
15
17
|
# look for the %YAML directive
|
16
18
|
return true if text =~ /\A\s*%YAML/m
|
@@ -165,15 +167,15 @@ module Rouge
|
|
165
167
|
)x, Keyword::Type
|
166
168
|
|
167
169
|
# an anchor
|
168
|
-
rule %r/&[\
|
170
|
+
rule %r/&[\p{L}\p{Nl}\p{Nd}_-]+/, Name::Label
|
169
171
|
|
170
172
|
# an alias
|
171
|
-
rule %r/\*[\
|
173
|
+
rule %r/\*[\p{L}\p{Nl}\p{Nd}_-]+/, Name::Variable
|
172
174
|
end
|
173
175
|
|
174
176
|
state :block_nodes do
|
175
177
|
# implicit key
|
176
|
-
rule %r/((
|
178
|
+
rule %r/((?:[\p{L}\p{Nl}\p{Nd}_][\p{L}\p{Nl}\p{Nd}\p{Blank}_-]*)?)(:)(?=\s|$)/ do |m|
|
177
179
|
groups Name::Attribute, Punctuation::Indicator
|
178
180
|
set_indent m[0], :implicit => true
|
179
181
|
end
|
data/lib/rouge/regex_lexer.rb
CHANGED
@@ -6,6 +6,37 @@ module Rouge
|
|
6
6
|
# A stateful lexer that uses sets of regular expressions to
|
7
7
|
# tokenize a string. Most lexers are instances of RegexLexer.
|
8
8
|
class RegexLexer < Lexer
|
9
|
+
class InvalidRegex < StandardError
|
10
|
+
def initialize(re)
|
11
|
+
@re = re
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
"regex #{@re.inspect} matches empty string, but has no predicate!"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class ClosedState < StandardError
|
20
|
+
attr_reader :state
|
21
|
+
def initialize(state)
|
22
|
+
@state = state
|
23
|
+
end
|
24
|
+
|
25
|
+
def rule
|
26
|
+
@state.rules.last
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_s
|
30
|
+
rule = @state.rules.last
|
31
|
+
msg = "State :#{state.name} cannot continue after #{rule.inspect}, which will always match."
|
32
|
+
if rule.re.source.include?('*')
|
33
|
+
msg += " Consider replacing * with +."
|
34
|
+
end
|
35
|
+
|
36
|
+
msg
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
9
40
|
# A rule is a tuple of a regular expression to test, and a callback
|
10
41
|
# to perform if the test succeeds.
|
11
42
|
#
|
@@ -42,12 +73,13 @@ module Rouge
|
|
42
73
|
end
|
43
74
|
|
44
75
|
class StateDSL
|
45
|
-
attr_reader :rules
|
76
|
+
attr_reader :rules, :name
|
46
77
|
def initialize(name, &defn)
|
47
78
|
@name = name
|
48
79
|
@defn = defn
|
49
80
|
@rules = []
|
50
81
|
@loaded = false
|
82
|
+
@closed = false
|
51
83
|
end
|
52
84
|
|
53
85
|
def to_state(lexer_class)
|
@@ -95,10 +127,14 @@ module Rouge
|
|
95
127
|
# {RegexLexer#token}, and {RegexLexer#delegate}. The first
|
96
128
|
# argument can be used to access the match groups.
|
97
129
|
def rule(re, tok=nil, next_state=nil, &callback)
|
130
|
+
raise ClosedState.new(self) if @closed
|
131
|
+
|
98
132
|
if tok.nil? && callback.nil?
|
99
133
|
raise "please pass `rule` a token to yield or a callback"
|
100
134
|
end
|
101
135
|
|
136
|
+
matches_empty = re =~ ''
|
137
|
+
|
102
138
|
callback ||= case next_state
|
103
139
|
when :pop!
|
104
140
|
proc do |stream|
|
@@ -123,6 +159,9 @@ module Rouge
|
|
123
159
|
@stack.push(state)
|
124
160
|
end
|
125
161
|
when nil
|
162
|
+
# cannot use an empty-matching regexp with no predicate
|
163
|
+
raise InvalidRegex.new(re) if matches_empty
|
164
|
+
|
126
165
|
proc do |stream|
|
127
166
|
puts " yielding: #{tok.qualname}, #{stream[0].inspect}" if @debug
|
128
167
|
@output_stream.call(tok, stream[0])
|
@@ -132,6 +171,22 @@ module Rouge
|
|
132
171
|
end
|
133
172
|
|
134
173
|
rules << Rule.new(re, callback)
|
174
|
+
|
175
|
+
close! if matches_empty && !context_sensitive?(re)
|
176
|
+
end
|
177
|
+
|
178
|
+
def context_sensitive?(re)
|
179
|
+
source = re.source
|
180
|
+
return true if source =~ /[(][?]<?[!=]/
|
181
|
+
|
182
|
+
# anchors count as lookahead/behind
|
183
|
+
return true if source =~ /[$^]/
|
184
|
+
|
185
|
+
false
|
186
|
+
end
|
187
|
+
|
188
|
+
def close!
|
189
|
+
@closed = true
|
135
190
|
end
|
136
191
|
|
137
192
|
# Mix in the rules from another state into this state. The rules
|
data/lib/rouge/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rouge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.25.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeanine Adkisson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Rouge aims to a be a simple, easy-to-extend drop-in replacement for pygments.
|
14
14
|
email:
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- lib/rouge/demos/biml
|
40
40
|
- lib/rouge/demos/bpf
|
41
41
|
- lib/rouge/demos/brainfuck
|
42
|
+
- lib/rouge/demos/brightscript
|
42
43
|
- lib/rouge/demos/bsl
|
43
44
|
- lib/rouge/demos/c
|
44
45
|
- lib/rouge/demos/ceylon
|
@@ -72,6 +73,7 @@ files:
|
|
72
73
|
- lib/rouge/demos/eiffel
|
73
74
|
- lib/rouge/demos/elixir
|
74
75
|
- lib/rouge/demos/elm
|
76
|
+
- lib/rouge/demos/email
|
75
77
|
- lib/rouge/demos/epp
|
76
78
|
- lib/rouge/demos/erb
|
77
79
|
- lib/rouge/demos/erlang
|
@@ -108,6 +110,8 @@ files:
|
|
108
110
|
- lib/rouge/demos/irb
|
109
111
|
- lib/rouge/demos/irb_output
|
110
112
|
- lib/rouge/demos/isbl
|
113
|
+
- lib/rouge/demos/j
|
114
|
+
- lib/rouge/demos/janet
|
111
115
|
- lib/rouge/demos/java
|
112
116
|
- lib/rouge/demos/javascript
|
113
117
|
- lib/rouge/demos/jinja
|
@@ -156,6 +160,7 @@ files:
|
|
156
160
|
- lib/rouge/demos/plaintext
|
157
161
|
- lib/rouge/demos/plist
|
158
162
|
- lib/rouge/demos/pony
|
163
|
+
- lib/rouge/demos/postscript
|
159
164
|
- lib/rouge/demos/powershell
|
160
165
|
- lib/rouge/demos/praat
|
161
166
|
- lib/rouge/demos/prolog
|
@@ -190,8 +195,10 @@ files:
|
|
190
195
|
- lib/rouge/demos/sparql
|
191
196
|
- lib/rouge/demos/sqf
|
192
197
|
- lib/rouge/demos/sql
|
198
|
+
- lib/rouge/demos/ssh
|
193
199
|
- lib/rouge/demos/supercollider
|
194
200
|
- lib/rouge/demos/swift
|
201
|
+
- lib/rouge/demos/systemd
|
195
202
|
- lib/rouge/demos/tap
|
196
203
|
- lib/rouge/demos/tcl
|
197
204
|
- lib/rouge/demos/terraform
|
@@ -223,6 +230,7 @@ files:
|
|
223
230
|
- lib/rouge/formatters/html.rb
|
224
231
|
- lib/rouge/formatters/html_inline.rb
|
225
232
|
- lib/rouge/formatters/html_legacy.rb
|
233
|
+
- lib/rouge/formatters/html_line_highlighter.rb
|
226
234
|
- lib/rouge/formatters/html_line_table.rb
|
227
235
|
- lib/rouge/formatters/html_linewise.rb
|
228
236
|
- lib/rouge/formatters/html_pygments.rb
|
@@ -257,6 +265,7 @@ files:
|
|
257
265
|
- lib/rouge/lexers/biml.rb
|
258
266
|
- lib/rouge/lexers/bpf.rb
|
259
267
|
- lib/rouge/lexers/brainfuck.rb
|
268
|
+
- lib/rouge/lexers/brightscript.rb
|
260
269
|
- lib/rouge/lexers/bsl.rb
|
261
270
|
- lib/rouge/lexers/c.rb
|
262
271
|
- lib/rouge/lexers/ceylon.rb
|
@@ -290,6 +299,7 @@ files:
|
|
290
299
|
- lib/rouge/lexers/eiffel.rb
|
291
300
|
- lib/rouge/lexers/elixir.rb
|
292
301
|
- lib/rouge/lexers/elm.rb
|
302
|
+
- lib/rouge/lexers/email.rb
|
293
303
|
- lib/rouge/lexers/epp.rb
|
294
304
|
- lib/rouge/lexers/erb.rb
|
295
305
|
- lib/rouge/lexers/erlang.rb
|
@@ -327,6 +337,8 @@ files:
|
|
327
337
|
- lib/rouge/lexers/irb.rb
|
328
338
|
- lib/rouge/lexers/isbl.rb
|
329
339
|
- lib/rouge/lexers/isbl/builtins.rb
|
340
|
+
- lib/rouge/lexers/j.rb
|
341
|
+
- lib/rouge/lexers/janet.rb
|
330
342
|
- lib/rouge/lexers/java.rb
|
331
343
|
- lib/rouge/lexers/javascript.rb
|
332
344
|
- lib/rouge/lexers/jinja.rb
|
@@ -384,6 +396,7 @@ files:
|
|
384
396
|
- lib/rouge/lexers/plain_text.rb
|
385
397
|
- lib/rouge/lexers/plist.rb
|
386
398
|
- lib/rouge/lexers/pony.rb
|
399
|
+
- lib/rouge/lexers/postscript.rb
|
387
400
|
- lib/rouge/lexers/powershell.rb
|
388
401
|
- lib/rouge/lexers/praat.rb
|
389
402
|
- lib/rouge/lexers/prolog.rb
|
@@ -420,8 +433,10 @@ files:
|
|
420
433
|
- lib/rouge/lexers/sqf.rb
|
421
434
|
- lib/rouge/lexers/sqf/keywords.rb
|
422
435
|
- lib/rouge/lexers/sql.rb
|
436
|
+
- lib/rouge/lexers/ssh.rb
|
423
437
|
- lib/rouge/lexers/supercollider.rb
|
424
438
|
- lib/rouge/lexers/swift.rb
|
439
|
+
- lib/rouge/lexers/systemd.rb
|
425
440
|
- lib/rouge/lexers/tap.rb
|
426
441
|
- lib/rouge/lexers/tcl.rb
|
427
442
|
- lib/rouge/lexers/terraform.rb
|