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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ef1072cc2523dba637a191d195865b0b2fb9f38c4f6d9961fb58748306f6cd1
4
- data.tar.gz: 4cd1b0d5262fa8a1d4ddb564cf4e9a185d6e8043bee0261f119e7a8ccb81e1fd
3
+ metadata.gz: 396a6131a5e69e3e00fb09222825549829caa264d19293cd6d02259bf95be12c
4
+ data.tar.gz: f2fcad9f0b5c506b5ac0bce887d27aa92c8f3f13f174e11412de5d570a00ac2c
5
5
  SHA512:
6
- metadata.gz: 04a39cda7513ce8084b6cdddd3016e7ca679218688dfb2dcb6f6fd8a0e627ec189f38a31ba2c44bd2a8c5b16191e24d0f343f860db5dfbcbb7ca49b92aaff197
7
- data.tar.gz: 50172d87860fa9fb4b187dee66c72954ce926e0d73f3e78e1a15a7f3437e749d48b2f935fa6ad08be457a6dd317a3c5c20340a7f7cc1621825b97887e82822c1
6
+ metadata.gz: b717c871bbc6182964e52a2d07ee3203003887d4a8ff68574a869e68c65032bfa59f58b71c66dd69046b16a4ec345ac5ff228166912a2869f1e1d04a9ab09d50
7
+ data.tar.gz: 564109b16749415e78e218f60b6ff24e472da6c1e512e28df976c628ea3772374250c610e1ab9e46acccfdf24d7b07be63c40a0676b4e84971a37f6f8886c8c8
@@ -32,7 +32,7 @@ module Rouge
32
32
  )
33
33
  end
34
34
 
35
- prepend :template do
35
+ prepend :root do
36
36
  rule %r/<\?hh(\s*\/\/\s*(strict|decl|partial))?$/, Comment::Preproc, :php
37
37
  end
38
38
 
@@ -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
- nsid = /#{id}(?:\\#{id})*/
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
- # pass
76
+ push :start
62
77
  end
63
78
  end
64
79
 
65
- def self.keywords
66
- # (echo parent ; echo self ; sed -nE 's/<ST_IN_SCRIPTING>"((__)?[[:alpha:]_]+(__)?)".*/\1/p' zend_language_scanner.l | tr '[A-Z]' '[a-z]') | sort -u | grep -Fwv -e isset -e unset -e empty -e const -e use -e function -e namespace
67
- # - isset, unset and empty are actually keywords (directly handled by PHP's lexer but let's pretend these are functions, you use them like so)
68
- # - self and parent are kind of keywords, they are not handled by PHP's lexer
69
- # - use, const, namespace and function are handled by specific rules to highlight what's next to the keyword
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
- def self.detect?(text)
87
- return true if text.shebang?('php')
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 :root do
93
- # some extremely rough heuristics to decide whether to start inline or not
94
- rule(/\s*(?=<)/m) { delegate parent; push :template }
95
- rule(/[^$]+(?=<\?(php|=))/i) { delegate parent; push :template }
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(//) { push :template; push :php }
99
+ rule(//) { goto :php }
98
100
  end
99
101
 
100
- state :template do
101
- rule %r/<\?(php|=)?/i, Comment::Preproc, :php
102
- rule(/.*?(?=<\?)|.*/m) { delegate parent }
103
- end
104
-
105
- state :php do
106
- rule %r/\?>/, Comment::Preproc, :pop!
107
- # heredocs
108
- rule %r/<<<(["']?)(#{id})\1\n.*?\n\s*\2;?/im, Str::Heredoc
109
- rule %r/\s+/, Text
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 %r/(void|\??(int|float|bool|string|iterable|self|callable))\b/i, Keyword::Type
120
- rule %r/[~!%^&*+=\|:.<>\/@-]+/, Operator
121
- rule %r/\?/, Operator
122
- rule %r/[\[\]{}();,]/, Punctuation
123
- rule %r/(class|interface|trait)(\s+)(#{nsid})/i do
124
- groups Keyword::Declaration, Text, Name::Class
125
- end
126
- rule %r/(use)(\s+)(function|const|)(\s*)(#{nsid})/i do
127
- groups Keyword::Namespace, Text, Keyword::Namespace, Text, Name::Namespace
128
- push :use
129
- end
130
- rule %r/(namespace)(\s+)(#{nsid})/i do
131
- groups Keyword::Namespace, Text, Name::Namespace
132
- end
133
- # anonymous functions
134
- rule %r/(function)(\s*)(?=\()/i do
135
- groups Keyword, Text
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
- # named functions
139
- rule %r/(function)(\s+)(&?)(\s*)/i do
140
- groups Keyword, Text, Operator, Text
141
- push :funcname
142
- end
146
+ state :operators do
147
+ rule %r/[~!%^&*+\|:.<>\/@-]+/, Operator
148
+ end
143
149
 
144
- rule %r/(const)(\s+)(#{id})/i do
145
- groups Keyword, Text, Name::Constant
146
- end
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/stdClass\b/i, Name::Class
149
- rule %r/(true|false|null)\b/i, Keyword::Constant
150
- rule %r/(E|PHP)(_[[:upper:]]+)+\b/, Keyword::Constant
151
- rule %r/\$\{\$+#{id}\}/i, Name::Variable
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
- # may be intercepted for builtin highlighting
158
- rule %r/\\?#{nsid}/i do |m|
159
- name = m[0].downcase
163
+ rule %r/[${\\]+/, Str::Double
164
+ end
160
165
 
161
- if self.class.keywords.include? name
162
- token Keyword
163
- elsif self.builtins.include? name
164
- token Name::Builtin
165
- else
166
- token Name::Other
167
- end
168
- end
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
- state :use do
181
- rule %r/(\s+)(as)(\s+)(#{id})/i do
182
- groups Text, Keyword, Text, Name
183
- :pop!
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
- rule %r/\\\{/, Operator, :uselist
186
- rule %r/;/, Punctuation, :pop!
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 :uselist do
212
+ state :whitespace do
190
213
  rule %r/\s+/, Text
191
- rule %r/,/, Operator
192
- rule %r/\}/, Operator, :pop!
193
- rule %r/(as)(\s+)(#{id})/i do
194
- groups Keyword, Text, Name
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 :funcname do
200
- rule %r/#{id}/, Name::Function, :pop!
220
+ state :root do
221
+ rule %r/<\?(php|=)?/i, Comment::Preproc, :php
222
+ rule(/.*?(?=<\?)|.*/m) { delegate parent }
201
223
  end
202
224
 
203
- state :string do
204
- rule %r/"/, Str::Double, :pop!
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
- rule %r/\{\$\{/, Str::Interpol, :interp_double
212
- rule %r/\{(?=\$)/, Str::Interpol, :interp_single
213
- rule %r/(\{)(\S+)(\})/ do
214
- groups Str::Interpol, Name::Variable, Str::Interpol
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/[${\\]+/, Str::Double
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 :interp_double do
221
- rule %r/\}\}/, Str::Interpol, :pop!
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 :interp_single do
226
- rule %r/\}/, Str::Interpol, :pop!
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
@@ -3,6 +3,6 @@
3
3
 
4
4
  module Rouge
5
5
  def self.version
6
- "3.21.0"
6
+ "3.22.0"
7
7
  end
8
8
  end
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.21.0
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-07-14 00:00:00.000000000 Z
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: