rouge 3.3.0 → 3.4.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.
Files changed (49) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +14 -2
  3. data/lib/rouge.rb +45 -41
  4. data/lib/rouge/cli.rb +26 -2
  5. data/lib/rouge/demos/escape +3 -0
  6. data/lib/rouge/demos/supercollider +11 -0
  7. data/lib/rouge/demos/xojo +13 -0
  8. data/lib/rouge/formatter.rb +36 -0
  9. data/lib/rouge/formatters/html.rb +2 -0
  10. data/lib/rouge/formatters/html_linewise.rb +6 -11
  11. data/lib/rouge/formatters/html_table.rb +20 -31
  12. data/lib/rouge/formatters/terminal256.rb +1 -0
  13. data/lib/rouge/guessers/disambiguation.rb +13 -0
  14. data/lib/rouge/guessers/source.rb +1 -1
  15. data/lib/rouge/lexer.rb +44 -13
  16. data/lib/rouge/lexers/c.rb +6 -29
  17. data/lib/rouge/lexers/coffeescript.rb +14 -6
  18. data/lib/rouge/lexers/common_lisp.rb +1 -1
  19. data/lib/rouge/lexers/console.rb +2 -2
  20. data/lib/rouge/lexers/coq.rb +1 -1
  21. data/lib/rouge/lexers/csharp.rb +0 -1
  22. data/lib/rouge/lexers/diff.rb +8 -4
  23. data/lib/rouge/lexers/docker.rb +1 -1
  24. data/lib/rouge/lexers/escape.rb +55 -0
  25. data/lib/rouge/lexers/go.rb +1 -1
  26. data/lib/rouge/lexers/graphql.rb +10 -0
  27. data/lib/rouge/lexers/html.rb +1 -0
  28. data/lib/rouge/lexers/java.rb +4 -0
  29. data/lib/rouge/lexers/javascript.rb +12 -16
  30. data/lib/rouge/lexers/jinja.rb +15 -1
  31. data/lib/rouge/lexers/julia.rb +140 -17
  32. data/lib/rouge/lexers/kotlin.rb +11 -4
  33. data/lib/rouge/lexers/markdown.rb +21 -4
  34. data/lib/rouge/lexers/matlab.rb +9 -2
  35. data/lib/rouge/lexers/objective_c.rb +7 -12
  36. data/lib/rouge/lexers/perl.rb +38 -6
  37. data/lib/rouge/lexers/powershell.rb +1 -1
  38. data/lib/rouge/lexers/rust.rb +1 -1
  39. data/lib/rouge/lexers/scala.rb +28 -2
  40. data/lib/rouge/lexers/shell.rb +1 -1
  41. data/lib/rouge/lexers/slim.rb +2 -2
  42. data/lib/rouge/lexers/supercollider.rb +116 -0
  43. data/lib/rouge/lexers/xml.rb +1 -1
  44. data/lib/rouge/lexers/xojo.rb +61 -0
  45. data/lib/rouge/regex_lexer.rb +12 -12
  46. data/lib/rouge/themes/bw.rb +41 -0
  47. data/lib/rouge/token.rb +30 -22
  48. data/lib/rouge/version.rb +1 -1
  49. metadata +10 -4
@@ -183,18 +183,18 @@ module Rouge
183
183
  # Define a new state for this lexer with the given name.
184
184
  # The block will be evaluated in the context of a {StateDSL}.
185
185
  def self.state(name, &b)
186
- name = name.to_s
186
+ name = name.to_sym
187
187
  state_definitions[name] = StateDSL.new(name, &b)
188
188
  end
189
189
 
190
190
  def self.prepend(name, &b)
191
- name = name.to_s
191
+ name = name.to_sym
192
192
  dsl = state_definitions[name] or raise "no such state #{name.inspect}"
193
193
  replace_state(name, dsl.prepended(&b))
194
194
  end
195
195
 
196
196
  def self.append(name, &b)
197
- name = name.to_s
197
+ name = name.to_sym
198
198
  dsl = state_definitions[name] or raise "no such state #{name.inspect}"
199
199
  replace_state(name, dsl.appended(&b))
200
200
  end
@@ -204,7 +204,7 @@ module Rouge
204
204
  return name if name.is_a? State
205
205
 
206
206
  states[name.to_sym] ||= begin
207
- defn = state_definitions[name.to_s] or raise "unknown state: #{name.inspect}"
207
+ defn = state_definitions[name.to_sym] or raise "unknown state: #{name.inspect}"
208
208
  defn.to_state(self)
209
209
  end
210
210
  end
@@ -352,10 +352,10 @@ module Rouge
352
352
  end
353
353
  end
354
354
 
355
- # Delegate the lex to another lexer. The #lex method will be called
356
- # with `:continue` set to true, so that #reset! will not be called.
357
- # In this way, a single lexer can be repeatedly delegated to while
358
- # maintaining its own internal state stack.
355
+ # Delegate the lex to another lexer. We use the `continue_lex` method
356
+ # so that #reset! will not be called. In this way, a single lexer
357
+ # can be repeatedly delegated to while maintaining its own internal
358
+ # state stack.
359
359
  #
360
360
  # @param [#lex] lexer
361
361
  # The lexer or lexer class to delegate to
@@ -365,7 +365,7 @@ module Rouge
365
365
  puts " delegating to #{lexer.inspect}" if @debug
366
366
  text ||= @current_stream[0]
367
367
 
368
- lexer.lex(text, :continue => true) do |tok, val|
368
+ lexer.continue_lex(text) do |tok, val|
369
369
  puts " delegated token: #{tok.inspect}, #{val.inspect}" if @debug
370
370
  yield_token(tok, val)
371
371
  end
@@ -421,15 +421,15 @@ module Rouge
421
421
 
422
422
  # Check if `state_name` is in the state stack.
423
423
  def in_state?(state_name)
424
- state_name = state_name.to_s
424
+ state_name = state_name.to_sym
425
425
  stack.any? do |state|
426
- state.name == state_name.to_s
426
+ state.name == state_name.to_sym
427
427
  end
428
428
  end
429
429
 
430
430
  # Check if `state_name` is the state on top of the state stack.
431
431
  def state?(state_name)
432
- state_name.to_s == state.name
432
+ state_name.to_sym == state.name
433
433
  end
434
434
 
435
435
  private
@@ -0,0 +1,41 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Themes
6
+ # A port of the bw style from Pygments.
7
+ # See https://bitbucket.org/birkenfeld/pygments-main/src/default/pygments/styles/bw.py
8
+ class BlackWhiteTheme < CSSTheme
9
+ name 'bw'
10
+
11
+ style Text, :fg => '#000000', :bg => '#ffffff'
12
+
13
+ style Comment, :italic => true
14
+ style Comment::Preproc, :italic => false
15
+
16
+ style Keyword, :bold => true
17
+ style Keyword::Pseudo, :bold => false
18
+ style Keyword::Type, :bold => false
19
+
20
+ style Operator, :bold => true
21
+
22
+ style Name::Class, :bold => true
23
+ style Name::Namespace, :bold => true
24
+ style Name::Exception, :bold => true
25
+ style Name::Entity, :bold => true
26
+ style Name::Tag, :bold => true
27
+
28
+ style Literal::String, :italic => true
29
+ style Literal::String::Interpol, :bold => true
30
+ style Literal::String::Escape, :bold => true
31
+
32
+ style Generic::Heading, :bold => true
33
+ style Generic::Subheading, :bold => true
34
+ style Generic::Emph, :italic => true
35
+ style Generic::Strong, :bold => true
36
+ style Generic::Prompt, :bold => true
37
+
38
+ style Error, :fg => '#FF0000'
39
+ end
40
+ end
41
+ end
@@ -80,8 +80,9 @@ module Rouge
80
80
  token :Whitespace, 'w'
81
81
  end
82
82
 
83
- token :Error, 'err'
84
- token :Other, 'x'
83
+ token :Escape, 'esc'
84
+ token :Error, 'err'
85
+ token :Other, 'x'
85
86
 
86
87
  token :Keyword, 'k' do
87
88
  token :Constant, 'kc'
@@ -103,7 +104,9 @@ module Rouge
103
104
  token :Decorator, 'nd'
104
105
  token :Entity, 'ni'
105
106
  token :Exception, 'ne'
106
- token :Function, 'nf'
107
+ token :Function, 'nf' do
108
+ token :Magic, 'fm'
109
+ end
107
110
  token :Property, 'py'
108
111
  token :Label, 'nl'
109
112
  token :Namespace, 'nn'
@@ -113,34 +116,37 @@ module Rouge
113
116
  token :Class, 'vc'
114
117
  token :Global, 'vg'
115
118
  token :Instance, 'vi'
119
+ token :Magic, 'vm'
116
120
  end
117
121
  end
118
122
 
119
123
  token :Literal, 'l' do
120
124
  token :Date, 'ld'
121
125
 
122
- token :String, 's' do
123
- token :Backtick, 'sb'
124
- token :Char, 'sc'
125
- token :Doc, 'sd'
126
- token :Double, 's2'
127
- token :Escape, 'se'
128
- token :Heredoc, 'sh'
129
- token :Interpol, 'si'
130
- token :Other, 'sx'
131
- token :Regex, 'sr'
132
- token :Single, 's1'
133
- token :Symbol, 'ss'
126
+ token :String, 's' do
127
+ token :Affix, 'sa'
128
+ token :Backtick, 'sb'
129
+ token :Char, 'sc'
130
+ token :Delimiter, 'dl'
131
+ token :Doc, 'sd'
132
+ token :Double, 's2'
133
+ token :Escape, 'se'
134
+ token :Heredoc, 'sh'
135
+ token :Interpol, 'si'
136
+ token :Other, 'sx'
137
+ token :Regex, 'sr'
138
+ token :Single, 's1'
139
+ token :Symbol, 'ss'
134
140
  end
135
141
 
136
142
  token :Number, 'm' do
143
+ token :Bin, 'mb'
137
144
  token :Float, 'mf'
138
145
  token :Hex, 'mh'
139
146
  token :Integer, 'mi' do
140
147
  token :Long, 'il'
141
148
  end
142
149
  token :Oct, 'mo'
143
- token :Bin, 'mb'
144
150
  token :Other, 'mx'
145
151
  end
146
152
  end
@@ -153,12 +159,14 @@ module Rouge
153
159
  token :Indicator, 'pi'
154
160
  end
155
161
 
156
- token :Comment, 'c' do
157
- token :Doc, 'cd'
158
- token :Multiline, 'cm'
159
- token :Preproc, 'cp'
160
- token :Single, 'c1'
161
- token :Special, 'cs'
162
+ token :Comment, 'c' do
163
+ token :Hashbang, 'ch'
164
+ token :Doc, 'cd'
165
+ token :Multiline, 'cm'
166
+ token :Preproc, 'cp'
167
+ token :PreprocFile, 'cpf'
168
+ token :Single, 'c1'
169
+ token :Special, 'cs'
162
170
  end
163
171
 
164
172
  token :Generic, 'g' do
@@ -3,6 +3,6 @@
3
3
 
4
4
  module Rouge
5
5
  def self.version
6
- "3.3.0"
6
+ "3.4.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.3.0
4
+ version: 3.4.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: 2018-10-01 00:00:00.000000000 Z
11
+ date: 2019-06-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:
@@ -56,6 +56,7 @@ files:
56
56
  - lib/rouge/demos/elm
57
57
  - lib/rouge/demos/erb
58
58
  - lib/rouge/demos/erlang
59
+ - lib/rouge/demos/escape
59
60
  - lib/rouge/demos/factor
60
61
  - lib/rouge/demos/fortran
61
62
  - lib/rouge/demos/fsharp
@@ -142,6 +143,7 @@ files:
142
143
  - lib/rouge/demos/sml
143
144
  - lib/rouge/demos/sqf
144
145
  - lib/rouge/demos/sql
146
+ - lib/rouge/demos/supercollider
145
147
  - lib/rouge/demos/swift
146
148
  - lib/rouge/demos/tap
147
149
  - lib/rouge/demos/tcl
@@ -161,6 +163,7 @@ files:
161
163
  - lib/rouge/demos/vue
162
164
  - lib/rouge/demos/wollok
163
165
  - lib/rouge/demos/xml
166
+ - lib/rouge/demos/xojo
164
167
  - lib/rouge/demos/yaml
165
168
  - lib/rouge/formatter.rb
166
169
  - lib/rouge/formatters/html.rb
@@ -214,6 +217,7 @@ files:
214
217
  - lib/rouge/lexers/elm.rb
215
218
  - lib/rouge/lexers/erb.rb
216
219
  - lib/rouge/lexers/erlang.rb
220
+ - lib/rouge/lexers/escape.rb
217
221
  - lib/rouge/lexers/factor.rb
218
222
  - lib/rouge/lexers/fortran.rb
219
223
  - lib/rouge/lexers/fsharp.rb
@@ -307,6 +311,7 @@ files:
307
311
  - lib/rouge/lexers/sqf.rb
308
312
  - lib/rouge/lexers/sqf/commands.rb
309
313
  - lib/rouge/lexers/sql.rb
314
+ - lib/rouge/lexers/supercollider.rb
310
315
  - lib/rouge/lexers/swift.rb
311
316
  - lib/rouge/lexers/tap.rb
312
317
  - lib/rouge/lexers/tcl.rb
@@ -328,6 +333,7 @@ files:
328
333
  - lib/rouge/lexers/vue.rb
329
334
  - lib/rouge/lexers/wollok.rb
330
335
  - lib/rouge/lexers/xml.rb
336
+ - lib/rouge/lexers/xojo.rb
331
337
  - lib/rouge/lexers/yaml.rb
332
338
  - lib/rouge/plugins/redcarpet.rb
333
339
  - lib/rouge/regex_lexer.rb
@@ -335,6 +341,7 @@ files:
335
341
  - lib/rouge/text_analyzer.rb
336
342
  - lib/rouge/theme.rb
337
343
  - lib/rouge/themes/base16.rb
344
+ - lib/rouge/themes/bw.rb
338
345
  - lib/rouge/themes/colorful.rb
339
346
  - lib/rouge/themes/github.rb
340
347
  - lib/rouge/themes/gruvbox.rb
@@ -371,8 +378,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
371
378
  - !ruby/object:Gem::Version
372
379
  version: '0'
373
380
  requirements: []
374
- rubyforge_project: rouge
375
- rubygems_version: 2.6.14.1
381
+ rubygems_version: 3.0.3
376
382
  signing_key:
377
383
  specification_version: 4
378
384
  summary: A pure-ruby colorizer based on pygments