rouge 3.21.0 → 3.22.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/lexers/hack.rb +1 -1
- data/lib/rouge/lexers/php.rb +274 -128
- data/lib/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: 396a6131a5e69e3e00fb09222825549829caa264d19293cd6d02259bf95be12c
|
4
|
+
data.tar.gz: f2fcad9f0b5c506b5ac0bce887d27aa92c8f3f13f174e11412de5d570a00ac2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b717c871bbc6182964e52a2d07ee3203003887d4a8ff68574a869e68c65032bfa59f58b71c66dd69046b16a4ec345ac5ff228166912a2869f1e1d04a9ab09d50
|
7
|
+
data.tar.gz: 564109b16749415e78e218f60b6ff24e472da6c1e512e28df976c628ea3772374250c610e1ab9e46acccfdf24d7b07be63c40a0676b4e84971a37f6f8886c8c8
|
data/lib/rouge/lexers/hack.rb
CHANGED
data/lib/rouge/lexers/php.rb
CHANGED
@@ -28,6 +28,26 @@ module Rouge
|
|
28
28
|
@disabledmodules = list_option(:disabledmodules)
|
29
29
|
end
|
30
30
|
|
31
|
+
def self.detect?(text)
|
32
|
+
return true if text.shebang?('php')
|
33
|
+
return false if /^<\?hh/ =~ text
|
34
|
+
return true if /^<\?php/ =~ text
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.keywords
|
38
|
+
@keywords ||= Set.new %w(
|
39
|
+
old_function cfunction
|
40
|
+
__class__ __dir__ __file__ __function__ __halt_compiler __line__
|
41
|
+
__method__ __namespace__ __trait__ abstract and array as break case
|
42
|
+
catch clone continue declare default die do echo else elseif
|
43
|
+
enddeclare endfor endforeach endif endswitch endwhile eval exit
|
44
|
+
extends final finally fn for foreach global goto if implements
|
45
|
+
include include_once instanceof insteadof isset list new or parent
|
46
|
+
print private protected public require require_once return self
|
47
|
+
static switch throw try var while xor yield
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
31
51
|
def self.builtins
|
32
52
|
Kernel::load File.join(Lexers::BASE_DIR, 'php/keywords.rb')
|
33
53
|
builtins
|
@@ -44,188 +64,314 @@ module Rouge
|
|
44
64
|
end
|
45
65
|
end
|
46
66
|
|
47
|
-
# source: http://php.net/manual/en/language.variables.basics.php
|
48
|
-
# the given regex is invalid utf8, so... we're using the unicode
|
49
|
-
# "Letter" property instead.
|
50
67
|
id = /[\p{L}_][\p{L}\p{N}_]*/
|
51
|
-
|
68
|
+
ns = /(?:#{id}\\)+/
|
69
|
+
id_with_ns = /(?:#{ns})?#{id}/
|
52
70
|
|
53
71
|
start do
|
54
72
|
case @start_inline
|
55
73
|
when true
|
56
|
-
push :template
|
57
74
|
push :php
|
58
|
-
when false
|
59
|
-
push :template
|
60
75
|
when :guess
|
61
|
-
|
76
|
+
push :start
|
62
77
|
end
|
63
78
|
end
|
64
79
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
# - class is also listed here, in addition to the rule below, to handle anonymous classes
|
71
|
-
@keywords ||= Set.new %w(
|
72
|
-
old_function cfunction
|
73
|
-
__class__ __dir__ __file__ __function__ __halt_compiler
|
74
|
-
__line__ __method__ __namespace__ __trait__ abstract and
|
75
|
-
array as break callable case catch class clone continue
|
76
|
-
declare default die do echo else elseif enddeclare
|
77
|
-
endfor endforeach endif endswitch endwhile eval exit
|
78
|
-
extends final finally fn for foreach global goto if
|
79
|
-
implements include include_once instanceof insteadof
|
80
|
-
interface list new or parent print private protected
|
81
|
-
public require require_once return self static switch
|
82
|
-
throw trait try var while xor yield
|
83
|
-
)
|
80
|
+
state :escape do
|
81
|
+
rule %r/\?>/ do
|
82
|
+
token Comment::Preproc
|
83
|
+
reset_stack
|
84
|
+
end
|
84
85
|
end
|
85
86
|
|
86
|
-
|
87
|
-
|
88
|
-
return false if /^<\?hh/ =~ text
|
89
|
-
return true if /^<\?php/ =~ text
|
87
|
+
state :return do
|
88
|
+
rule(//) { pop! }
|
90
89
|
end
|
91
90
|
|
92
|
-
state :
|
93
|
-
#
|
94
|
-
|
95
|
-
|
91
|
+
state :start do
|
92
|
+
# We enter this state if we aren't sure whether the PHP in the text is
|
93
|
+
# delimited by <?php (or <?=) tags or not. These two rules check
|
94
|
+
# whether there is an opening angle bracket and, if there is, delegates
|
95
|
+
# the tokens before it to the HTML lexer.
|
96
|
+
rule(/\s*(?=<)/m) { delegate parent; pop! }
|
97
|
+
rule(/[^$]+(?=<\?(php|=))/i) { delegate parent; pop! }
|
96
98
|
|
97
|
-
rule(//) {
|
99
|
+
rule(//) { goto :php }
|
98
100
|
end
|
99
101
|
|
100
|
-
state :
|
101
|
-
rule %r
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
rule %r/#.*?$/, Comment::Single
|
111
|
-
rule %r(//.*?$), Comment::Single
|
112
|
-
rule %r(/\*\*(?!/).*?\*/)m, Comment::Doc
|
113
|
-
rule %r(/\*.*?\*/)m, Comment::Multiline
|
114
|
-
|
115
|
-
rule %r/(->|::)(\s*)(#{id})/ do
|
116
|
-
groups Operator, Text, Name::Attribute
|
102
|
+
state :names do
|
103
|
+
rule %r/#{id_with_ns}(?=\s*\()/ do |m|
|
104
|
+
name = m[0].downcase
|
105
|
+
if self.class.keywords.include? name
|
106
|
+
token Keyword
|
107
|
+
elsif self.builtins.include? name
|
108
|
+
token Name::Builtin
|
109
|
+
else
|
110
|
+
token Name::Function
|
111
|
+
end
|
117
112
|
end
|
118
113
|
|
119
|
-
rule
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
114
|
+
rule id_with_ns do |m|
|
115
|
+
name = m[0].downcase
|
116
|
+
if name == "use"
|
117
|
+
push :in_use
|
118
|
+
token Keyword::Namespace
|
119
|
+
elsif name == "const"
|
120
|
+
push :in_const
|
121
|
+
token Keyword
|
122
|
+
elsif name == "catch"
|
123
|
+
push :in_catch
|
124
|
+
token Keyword
|
125
|
+
elsif %w(public protected private).include? name
|
126
|
+
push :in_visibility
|
127
|
+
token Keyword
|
128
|
+
elsif name == "stdClass"
|
129
|
+
token Name::Class
|
130
|
+
elsif self.class.keywords.include? name
|
131
|
+
token Keyword
|
132
|
+
elsif m[0] =~ /^__.*?__$/
|
133
|
+
token Name::Builtin
|
134
|
+
elsif m[0] =~ /^(E|PHP)(_[[:upper:]]+)+$/
|
135
|
+
token Keyword::Constant
|
136
|
+
elsif m[0] =~ /(\\|^)[[:upper:]][[[:upper:]][[:digit:]]_]+$/
|
137
|
+
token Name::Constant
|
138
|
+
elsif m[0] =~ /(\\|^)[[:upper:]][[:alnum:]]*?$/
|
139
|
+
token Name::Class
|
140
|
+
else
|
141
|
+
token Name
|
142
|
+
end
|
136
143
|
end
|
144
|
+
end
|
137
145
|
|
138
|
-
|
139
|
-
rule %r/
|
140
|
-
|
141
|
-
push :funcname
|
142
|
-
end
|
146
|
+
state :operators do
|
147
|
+
rule %r/[~!%^&*+\|:.<>\/@-]+/, Operator
|
148
|
+
end
|
143
149
|
|
144
|
-
|
145
|
-
|
146
|
-
|
150
|
+
state :string do
|
151
|
+
rule %r/"/, Str::Double, :pop!
|
152
|
+
rule %r/[^\\{$"]+/, Str::Double
|
153
|
+
rule %r/\\u\{[0-9a-fA-F]+\}/, Str::Escape
|
154
|
+
rule %r/\\([efrntv\"$\\]|[0-7]{1,3}|[xX][0-9a-fA-F]{1,2})/, Str::Escape
|
155
|
+
rule %r/\$#{id}(\[\S+\]|->#{id})?/, Name::Variable
|
147
156
|
|
148
|
-
rule %r
|
149
|
-
rule %r
|
150
|
-
rule %r/(
|
151
|
-
|
152
|
-
rule %r/\$+#{id}/i, Name::Variable
|
153
|
-
rule %r/(yield)([ \n\r\t]+)(from)/i do
|
154
|
-
groups Keyword, Text, Keyword
|
157
|
+
rule %r/\{\$\{/, Str::Interpol, :string_interp_double
|
158
|
+
rule %r/\{(?=\$)/, Str::Interpol, :string_interp_single
|
159
|
+
rule %r/(\{)(\S+)(\})/ do
|
160
|
+
groups Str::Interpol, Name::Variable, Str::Interpol
|
155
161
|
end
|
156
162
|
|
157
|
-
|
158
|
-
|
159
|
-
name = m[0].downcase
|
163
|
+
rule %r/[${\\]+/, Str::Double
|
164
|
+
end
|
160
165
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
166
|
+
state :string_interp_double do
|
167
|
+
rule %r/\}\}/, Str::Interpol, :pop!
|
168
|
+
mixin :php
|
169
|
+
end
|
170
|
+
|
171
|
+
state :string_interp_single do
|
172
|
+
rule %r/\}/, Str::Interpol, :pop!
|
173
|
+
mixin :php
|
174
|
+
end
|
175
|
+
|
176
|
+
state :values do
|
177
|
+
# heredocs
|
178
|
+
rule %r/<<<(["']?)(#{id})\1\n.*?\n\s*\2;?/im, Str::Heredoc
|
169
179
|
|
180
|
+
# numbers
|
170
181
|
rule %r/(\d[_\d]*)?\.(\d[_\d]*)?(e[+-]?\d[_\d]*)?/i, Num::Float
|
171
182
|
rule %r/0[0-7][0-7_]*/, Num::Oct
|
172
183
|
rule %r/0b[01][01_]*/i, Num::Bin
|
173
184
|
rule %r/0x[a-f0-9][a-f0-9_]*/i, Num::Hex
|
174
185
|
rule %r/\d[_\d]*/, Num::Integer
|
186
|
+
|
187
|
+
# strings
|
175
188
|
rule %r/'([^'\\]*(?:\\.[^'\\]*)*)'/, Str::Single
|
176
189
|
rule %r/`([^`\\]*(?:\\.[^`\\]*)*)`/, Str::Backtick
|
177
190
|
rule %r/"/, Str::Double, :string
|
178
|
-
end
|
179
191
|
|
180
|
-
|
181
|
-
rule %r/(
|
182
|
-
|
183
|
-
:
|
192
|
+
# functions
|
193
|
+
rule %r/(function|fn)\b/i do
|
194
|
+
push :in_function_return
|
195
|
+
push :in_function_params
|
196
|
+
push :in_function_name
|
197
|
+
token Keyword
|
184
198
|
end
|
185
|
-
|
186
|
-
|
199
|
+
|
200
|
+
# constants
|
201
|
+
rule %r/(true|false|null)\b/i, Keyword::Constant
|
202
|
+
|
203
|
+
# objects
|
204
|
+
rule %r/new\b/i, Keyword, :in_new
|
205
|
+
end
|
206
|
+
|
207
|
+
state :variables do
|
208
|
+
rule %r/\$\{\$+#{id}\}/, Name::Variable
|
209
|
+
rule %r/\$+#{id}/, Name::Variable
|
187
210
|
end
|
188
211
|
|
189
|
-
state :
|
212
|
+
state :whitespace do
|
190
213
|
rule %r/\s+/, Text
|
191
|
-
rule %r
|
192
|
-
rule %r
|
193
|
-
rule %r
|
194
|
-
|
195
|
-
end
|
196
|
-
rule %r/#{id}/, Name::Namespace
|
214
|
+
rule %r/#.*?$/, Comment::Single
|
215
|
+
rule %r(//.*?$), Comment::Single
|
216
|
+
rule %r(/\*\*(?!/).*?\*/)m, Comment::Doc
|
217
|
+
rule %r(/\*.*?\*/)m, Comment::Multiline
|
197
218
|
end
|
198
219
|
|
199
|
-
state :
|
200
|
-
rule %r
|
220
|
+
state :root do
|
221
|
+
rule %r/<\?(php|=)?/i, Comment::Preproc, :php
|
222
|
+
rule(/.*?(?=<\?)|.*/m) { delegate parent }
|
201
223
|
end
|
202
224
|
|
203
|
-
state :
|
204
|
-
|
205
|
-
rule %r/[^\\{$"]+/, Str::Double
|
206
|
-
rule %r/\\u\{[0-9a-fA-F]+\}/, Str::Escape
|
207
|
-
rule %r/\\([efrntv\"$\\]|[0-7]{1,3}|[xX][0-9a-fA-F]{1,2})/,
|
208
|
-
Str::Escape
|
209
|
-
rule %r/\$#{id}(\[\S+\]|->#{id})?/, Name::Variable
|
225
|
+
state :php do
|
226
|
+
mixin :escape
|
210
227
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
228
|
+
mixin :whitespace
|
229
|
+
mixin :variables
|
230
|
+
mixin :values
|
231
|
+
|
232
|
+
rule %r/(namespace)
|
233
|
+
(\s+)
|
234
|
+
(#{id_with_ns})/ix do |m|
|
235
|
+
groups Keyword::Namespace, Text, Name::Namespace
|
215
236
|
end
|
216
237
|
|
217
|
-
rule %r/
|
238
|
+
rule %r/(class|interface|trait|extends|implements)
|
239
|
+
(\s+)
|
240
|
+
(#{id_with_ns})/ix do |m|
|
241
|
+
groups Keyword::Declaration, Text, Name::Class
|
242
|
+
end
|
243
|
+
|
244
|
+
mixin :names
|
245
|
+
|
246
|
+
rule %r/[;,\(\)\{\}\[\]]/, Punctuation
|
247
|
+
|
248
|
+
mixin :operators
|
249
|
+
rule %r/[=?]/, Operator
|
218
250
|
end
|
219
251
|
|
220
|
-
state :
|
221
|
-
rule %r
|
252
|
+
state :in_assign do
|
253
|
+
rule %r/,/, Punctuation, :pop!
|
254
|
+
rule %r/[\[\]]/, Punctuation
|
255
|
+
rule %r/\(/, Punctuation, :in_assign_function
|
256
|
+
mixin :escape
|
257
|
+
mixin :whitespace
|
258
|
+
mixin :values
|
259
|
+
mixin :variables
|
260
|
+
mixin :names
|
261
|
+
mixin :operators
|
262
|
+
mixin :return
|
263
|
+
end
|
264
|
+
|
265
|
+
state :in_assign_function do
|
266
|
+
rule %r/\)/, Punctuation, :pop!
|
267
|
+
rule %r/,/, Punctuation
|
268
|
+
mixin :in_assign
|
269
|
+
end
|
270
|
+
|
271
|
+
state :in_catch do
|
272
|
+
rule %r/\(/, Punctuation
|
273
|
+
rule %r/\|/, Operator
|
274
|
+
rule id, Name::Class
|
275
|
+
mixin :escape
|
276
|
+
mixin :whitespace
|
277
|
+
mixin :return
|
278
|
+
end
|
279
|
+
|
280
|
+
state :in_const do
|
281
|
+
rule id, Name::Constant
|
282
|
+
rule %r/=/, Operator, :in_assign
|
283
|
+
mixin :escape
|
284
|
+
mixin :whitespace
|
285
|
+
mixin :return
|
286
|
+
end
|
287
|
+
|
288
|
+
state :in_function_body do
|
289
|
+
rule %r/{/, Punctuation, :push
|
290
|
+
rule %r/}/, Punctuation, :pop!
|
222
291
|
mixin :php
|
223
292
|
end
|
224
293
|
|
225
|
-
state :
|
226
|
-
rule %r
|
294
|
+
state :in_function_name do
|
295
|
+
rule %r/&/, Operator
|
296
|
+
rule id, Name
|
297
|
+
rule %r/\(/, Punctuation, :pop!
|
298
|
+
mixin :escape
|
299
|
+
mixin :whitespace
|
300
|
+
mixin :return
|
301
|
+
end
|
302
|
+
|
303
|
+
state :in_function_params do
|
304
|
+
rule %r/\)/, Punctuation, :pop!
|
305
|
+
rule %r/,/, Punctuation
|
306
|
+
rule %r/[.]{3}/, Punctuation
|
307
|
+
rule %r/=/, Operator, :in_assign
|
308
|
+
rule %r/\??#{id}/, Keyword::Type, :in_assign
|
309
|
+
mixin :escape
|
310
|
+
mixin :whitespace
|
311
|
+
mixin :variables
|
312
|
+
mixin :return
|
313
|
+
end
|
314
|
+
|
315
|
+
state :in_function_return do
|
316
|
+
rule %r/:/, Punctuation
|
317
|
+
rule %r/use\b/i, Keyword, :in_function_use
|
318
|
+
rule %r/\??#{id}/, Keyword::Type, :in_assign
|
319
|
+
rule %r/\{/ do
|
320
|
+
token Punctuation
|
321
|
+
goto :in_function_body
|
322
|
+
end
|
323
|
+
mixin :escape
|
324
|
+
mixin :whitespace
|
325
|
+
mixin :return
|
326
|
+
end
|
327
|
+
|
328
|
+
state :in_function_use do
|
329
|
+
rule %r/[,\(]/, Punctuation
|
330
|
+
rule %r/&/, Operator
|
331
|
+
rule %r/\)/, Punctuation, :pop!
|
332
|
+
mixin :escape
|
333
|
+
mixin :whitespace
|
334
|
+
mixin :variables
|
335
|
+
mixin :return
|
336
|
+
end
|
337
|
+
|
338
|
+
state :in_new do
|
339
|
+
rule %r/class\b/i do
|
340
|
+
token Keyword::Declaration
|
341
|
+
goto :in_new_class
|
342
|
+
end
|
343
|
+
rule id_with_ns, Name::Class, :pop!
|
344
|
+
mixin :escape
|
345
|
+
mixin :whitespace
|
346
|
+
mixin :return
|
347
|
+
end
|
348
|
+
|
349
|
+
state :in_new_class do
|
350
|
+
rule %r/\}/, Punctuation, :pop!
|
351
|
+
rule %r/\{/, Punctuation
|
227
352
|
mixin :php
|
228
353
|
end
|
354
|
+
|
355
|
+
state :in_use do
|
356
|
+
rule %r/[,\}]/, Punctuation
|
357
|
+
rule %r/(function|const)\b/i, Keyword
|
358
|
+
rule %r/(#{ns})(\{)/ do
|
359
|
+
groups Name::Namespace, Punctuation
|
360
|
+
end
|
361
|
+
rule %r/#{id_with_ns}(_#{id})+/, Name::Function
|
362
|
+
mixin :escape
|
363
|
+
mixin :whitespace
|
364
|
+
mixin :names
|
365
|
+
mixin :return
|
366
|
+
end
|
367
|
+
|
368
|
+
state :in_visibility do
|
369
|
+
rule %r/(?=(abstract|const|function|static)\b)/i, Keyword, :pop!
|
370
|
+
rule %r/\??#{id}/, Keyword::Type, :pop!
|
371
|
+
mixin :escape
|
372
|
+
mixin :whitespace
|
373
|
+
mixin :return
|
374
|
+
end
|
229
375
|
end
|
230
376
|
end
|
231
377
|
end
|
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.22.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-08-11 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:
|