rouge 3.4.1 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rouge.rb +3 -0
  3. data/lib/rouge/cli.rb +19 -2
  4. data/lib/rouge/demos/bpf +7 -0
  5. data/lib/rouge/demos/brainfuck +5 -0
  6. data/lib/rouge/demos/magik +6 -0
  7. data/lib/rouge/formatter.rb +2 -2
  8. data/lib/rouge/formatters/tex.rb +90 -0
  9. data/lib/rouge/guessers/glob_mapping.rb +1 -1
  10. data/lib/rouge/lexer.rb +22 -10
  11. data/lib/rouge/lexers/abap.rb +11 -11
  12. data/lib/rouge/lexers/actionscript.rb +34 -34
  13. data/lib/rouge/lexers/apache.rb +8 -8
  14. data/lib/rouge/lexers/apple_script.rb +15 -14
  15. data/lib/rouge/lexers/awk.rb +25 -25
  16. data/lib/rouge/lexers/biml.rb +4 -4
  17. data/lib/rouge/lexers/bpf.rb +104 -0
  18. data/lib/rouge/lexers/brainfuck.rb +53 -0
  19. data/lib/rouge/lexers/bsl.rb +12 -12
  20. data/lib/rouge/lexers/c.rb +30 -30
  21. data/lib/rouge/lexers/ceylon.rb +1 -29
  22. data/lib/rouge/lexers/cfscript.rb +26 -26
  23. data/lib/rouge/lexers/clojure.rb +14 -14
  24. data/lib/rouge/lexers/cmake.rb +14 -14
  25. data/lib/rouge/lexers/coffeescript.rb +30 -30
  26. data/lib/rouge/lexers/common_lisp.rb +36 -36
  27. data/lib/rouge/lexers/conf.rb +6 -6
  28. data/lib/rouge/lexers/coq.rb +18 -18
  29. data/lib/rouge/lexers/cpp.rb +8 -8
  30. data/lib/rouge/lexers/crystal.rb +70 -70
  31. data/lib/rouge/lexers/csharp.rb +28 -28
  32. data/lib/rouge/lexers/css.rb +23 -23
  33. data/lib/rouge/lexers/d.rb +59 -59
  34. data/lib/rouge/lexers/dart.rb +33 -33
  35. data/lib/rouge/lexers/digdag.rb +1 -1
  36. data/lib/rouge/lexers/docker.rb +10 -10
  37. data/lib/rouge/lexers/dot.rb +16 -16
  38. data/lib/rouge/lexers/eiffel.rb +20 -20
  39. data/lib/rouge/lexers/elixir.rb +29 -28
  40. data/lib/rouge/lexers/elm.rb +29 -29
  41. data/lib/rouge/lexers/erb.rb +4 -4
  42. data/lib/rouge/lexers/factor.rb +40 -40
  43. data/lib/rouge/lexers/fortran.rb +32 -32
  44. data/lib/rouge/lexers/fsharp.rb +26 -26
  45. data/lib/rouge/lexers/gherkin.rb +13 -13
  46. data/lib/rouge/lexers/glsl.rb +0 -4
  47. data/lib/rouge/lexers/go.rb +1 -1
  48. data/lib/rouge/lexers/graphql.rb +62 -62
  49. data/lib/rouge/lexers/groovy.rb +23 -25
  50. data/lib/rouge/lexers/hack.rb +1 -1
  51. data/lib/rouge/lexers/haml.rb +25 -29
  52. data/lib/rouge/lexers/handlebars.rb +18 -18
  53. data/lib/rouge/lexers/haskell.rb +66 -65
  54. data/lib/rouge/lexers/hcl.rb +25 -25
  55. data/lib/rouge/lexers/html.rb +31 -31
  56. data/lib/rouge/lexers/http.rb +4 -4
  57. data/lib/rouge/lexers/hylang.rb +14 -14
  58. data/lib/rouge/lexers/idlang.rb +32 -32
  59. data/lib/rouge/lexers/igorpro.rb +30 -30
  60. data/lib/rouge/lexers/ini.rb +12 -12
  61. data/lib/rouge/lexers/io.rb +7 -7
  62. data/lib/rouge/lexers/irb.rb +5 -5
  63. data/lib/rouge/lexers/java.rb +24 -24
  64. data/lib/rouge/lexers/javascript.rb +51 -51
  65. data/lib/rouge/lexers/jinja.rb +22 -22
  66. data/lib/rouge/lexers/json.rb +11 -10
  67. data/lib/rouge/lexers/json_doc.rb +2 -2
  68. data/lib/rouge/lexers/jsonnet.rb +18 -18
  69. data/lib/rouge/lexers/jsp.rb +28 -28
  70. data/lib/rouge/lexers/jsx.rb +16 -16
  71. data/lib/rouge/lexers/julia.rb +44 -44
  72. data/lib/rouge/lexers/kotlin.rb +3 -3
  73. data/lib/rouge/lexers/lasso.rb +50 -50
  74. data/lib/rouge/lexers/liquid.rb +53 -53
  75. data/lib/rouge/lexers/literate_coffeescript.rb +2 -2
  76. data/lib/rouge/lexers/literate_haskell.rb +5 -5
  77. data/lib/rouge/lexers/llvm.rb +23 -16
  78. data/lib/rouge/lexers/lua.rb +3 -3
  79. data/lib/rouge/lexers/m68k.rb +18 -19
  80. data/lib/rouge/lexers/magik.rb +126 -0
  81. data/lib/rouge/lexers/make.rb +22 -28
  82. data/lib/rouge/lexers/markdown.rb +37 -37
  83. data/lib/rouge/lexers/mathematica.rb +11 -11
  84. data/lib/rouge/lexers/matlab.rb +20 -20
  85. data/lib/rouge/lexers/moonscript.rb +3 -3
  86. data/lib/rouge/lexers/mosel.rb +17 -17
  87. data/lib/rouge/lexers/mxml.rb +18 -18
  88. data/lib/rouge/lexers/nasm.rb +24 -25
  89. data/lib/rouge/lexers/nginx.rb +14 -14
  90. data/lib/rouge/lexers/nim.rb +1 -1
  91. data/lib/rouge/lexers/nix.rb +42 -42
  92. data/lib/rouge/lexers/objective_c.rb +38 -38
  93. data/lib/rouge/lexers/ocaml.rb +29 -29
  94. data/lib/rouge/lexers/pascal.rb +4 -4
  95. data/lib/rouge/lexers/perl.rb +68 -68
  96. data/lib/rouge/lexers/php.rb +38 -38
  97. data/lib/rouge/lexers/plist.rb +14 -14
  98. data/lib/rouge/lexers/pony.rb +19 -19
  99. data/lib/rouge/lexers/powershell.rb +25 -25
  100. data/lib/rouge/lexers/praat.rb +75 -75
  101. data/lib/rouge/lexers/prolog.rb +26 -20
  102. data/lib/rouge/lexers/prometheus.rb +30 -30
  103. data/lib/rouge/lexers/properties.rb +12 -12
  104. data/lib/rouge/lexers/protobuf.rb +22 -22
  105. data/lib/rouge/lexers/puppet.rb +31 -31
  106. data/lib/rouge/lexers/python.rb +52 -52
  107. data/lib/rouge/lexers/q.rb +12 -12
  108. data/lib/rouge/lexers/qml.rb +12 -12
  109. data/lib/rouge/lexers/r.rb +12 -12
  110. data/lib/rouge/lexers/racket.rb +22 -22
  111. data/lib/rouge/lexers/ruby.rb +71 -69
  112. data/lib/rouge/lexers/rust.rb +30 -30
  113. data/lib/rouge/lexers/sass.rb +8 -8
  114. data/lib/rouge/lexers/sass/common.rb +40 -40
  115. data/lib/rouge/lexers/scala.rb +43 -43
  116. data/lib/rouge/lexers/scheme.rb +18 -18
  117. data/lib/rouge/lexers/scss.rb +3 -3
  118. data/lib/rouge/lexers/sed.rb +29 -29
  119. data/lib/rouge/lexers/shell.rb +61 -52
  120. data/lib/rouge/lexers/sieve.rb +8 -8
  121. data/lib/rouge/lexers/slim.rb +24 -24
  122. data/lib/rouge/lexers/smalltalk.rb +33 -33
  123. data/lib/rouge/lexers/smarty.rb +12 -12
  124. data/lib/rouge/lexers/sml.rb +67 -67
  125. data/lib/rouge/lexers/sqf.rb +1 -1
  126. data/lib/rouge/lexers/sql.rb +21 -21
  127. data/lib/rouge/lexers/supercollider.rb +19 -19
  128. data/lib/rouge/lexers/swift.rb +42 -39
  129. data/lib/rouge/lexers/tap.rb +20 -20
  130. data/lib/rouge/lexers/tcl.rb +27 -27
  131. data/lib/rouge/lexers/terraform.rb +13 -13
  132. data/lib/rouge/lexers/tex.rb +19 -19
  133. data/lib/rouge/lexers/toml.rb +18 -18
  134. data/lib/rouge/lexers/tulip.rb +36 -36
  135. data/lib/rouge/lexers/turtle.rb +35 -38
  136. data/lib/rouge/lexers/vala.rb +17 -17
  137. data/lib/rouge/lexers/vb.rb +27 -27
  138. data/lib/rouge/lexers/verilog.rb +25 -27
  139. data/lib/rouge/lexers/vhdl.rb +10 -10
  140. data/lib/rouge/lexers/viml.rb +14 -14
  141. data/lib/rouge/lexers/vue.rb +9 -9
  142. data/lib/rouge/lexers/wollok.rb +25 -25
  143. data/lib/rouge/lexers/xml.rb +17 -21
  144. data/lib/rouge/lexers/xojo.rb +15 -15
  145. data/lib/rouge/lexers/yaml.rb +61 -61
  146. data/lib/rouge/plugins/redcarpet.rb +1 -1
  147. data/lib/rouge/tex_theme_renderer.rb +128 -0
  148. data/lib/rouge/theme.rb +4 -0
  149. data/lib/rouge/themes/magritte.rb +78 -0
  150. data/lib/rouge/version.rb +1 -1
  151. metadata +11 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8b2c941a57cd61fef299dd3c106785c4b417872ec6cc1a50034cfcbbbff3187
4
- data.tar.gz: 34ffb315c85b42b21e3a24a6ca0b7ea3ebbdbb8232057718da9c3cb355dbb693
3
+ metadata.gz: 6a707581ace0d0f142f14737abd3518c84efef2d858e3cc725b823fbfd766a98
4
+ data.tar.gz: fbfcc168600d0d5258cb9e1d8cf96fb640ee8f4fcb22b54742131bed418480ff
5
5
  SHA512:
6
- metadata.gz: 9b8c0b0109ce776e3744f03271adb71f8a486cff52c2df222eb69ece3a098aef9d7852b750629f8860007fae163274ea087208c22c821428b4a2757434a21b36
7
- data.tar.gz: 291ee2e3d738fcdb181ed61b35511ad4c1dff44a90c359fe508fd23cdc939820766d662a1bba0dbbbbff1a5959f3a18ba71d87736f0ee9df8a0cbaf842528dfd
6
+ metadata.gz: 28e0f79ea4d22e21a0d2feb1eca347e64f8fba09cf9091db5081a16b97ecdeadef1d9705a33fb03be7c0c0589ba9d17b6aa38254d0ee2a00389b80e76d04705f
7
+ data.tar.gz: c3a44152f51d67607b4c3cb465277ccee8100af5b9ca0b88121b8e0f0f7b558bdb8141c03a9b8b0e1c1c9ad5549ab6912a92e4a9496d02fd6e5a0d5551255150
data/lib/rouge.rb CHANGED
@@ -71,9 +71,11 @@ load_relative 'rouge/formatters/html_legacy'
71
71
  load_relative 'rouge/formatters/html_linewise'
72
72
  load_relative 'rouge/formatters/html_inline'
73
73
  load_relative 'rouge/formatters/terminal256'
74
+ load_relative 'rouge/formatters/tex'
74
75
  load_relative 'rouge/formatters/null'
75
76
 
76
77
  load_relative 'rouge/theme'
78
+ load_relative 'rouge/tex_theme_renderer'
77
79
  load_relative 'rouge/themes/thankful_eyes'
78
80
  load_relative 'rouge/themes/colorful'
79
81
  load_relative 'rouge/themes/base16'
@@ -86,3 +88,4 @@ load_relative 'rouge/themes/gruvbox'
86
88
  load_relative 'rouge/themes/tulip'
87
89
  load_relative 'rouge/themes/pastie'
88
90
  load_relative 'rouge/themes/bw'
91
+ load_relative 'rouge/themes/magritte'
data/lib/rouge/cli.rb CHANGED
@@ -299,6 +299,7 @@ module Rouge
299
299
  when 'html-inline' then Formatters::HTMLInline.new(theme)
300
300
  when 'html-table' then Formatters::HTMLTable.new(Formatters::HTML.new)
301
301
  when 'null', 'raw', 'tokens' then Formatters::Null.new
302
+ when 'tex' then Formatters::Tex.new
302
303
  else
303
304
  error! "unknown formatter preset #{opts[:formatter]}"
304
305
  end
@@ -334,18 +335,30 @@ module Rouge
334
335
  yield %|respectively. Theme defaults to thankful_eyes.|
335
336
  yield %||
336
337
  yield %|options:|
337
- yield %| --scope (default: .highlight) a css selector to scope by|
338
+ yield %| --scope (default: .highlight) a css selector to scope by|
339
+ yield %| --tex (default: false) render as TeX|
340
+ yield %| --tex-prefix (default: RG) a command prefix for TeX|
341
+ yield %| implies --tex if specified|
338
342
  yield %||
339
343
  yield %|available themes:|
340
344
  yield %| #{Theme.registry.keys.sort.join(', ')}|
341
345
  end
342
346
 
343
347
  def self.parse(argv)
344
- opts = { :theme_name => 'thankful_eyes' }
348
+ opts = {
349
+ :theme_name => 'thankful_eyes',
350
+ :tex => false,
351
+ :tex_prefix => 'RG'
352
+ }
345
353
 
346
354
  until argv.empty?
347
355
  arg = argv.shift
348
356
  case arg
357
+ when '--tex'
358
+ opts[:tex] = true
359
+ when '--tex-prefix'
360
+ opts[:tex] = true
361
+ opts[:tex_prefix] = argv.shift
349
362
  when /--(\w+)/
350
363
  opts[$1.tr('-', '_').to_sym] = argv.shift
351
364
  else
@@ -362,6 +375,10 @@ module Rouge
362
375
  or error! "unknown theme: #{theme_name}"
363
376
 
364
377
  @theme = theme_class.new(opts)
378
+ if opts[:tex]
379
+ tex_prefix = opts[:tex_prefix]
380
+ @theme = TexThemeRenderer.new(@theme, prefix: tex_prefix)
381
+ end
365
382
  end
366
383
 
367
384
  def run
@@ -0,0 +1,7 @@
1
+ r0 = *(u8 *)skb[23]
2
+ *(u32 *)(r10 - 4) = r0
3
+ r1 = *(u32 *)(r6 + 4)
4
+ r1 = 0 ll
5
+ call 1 /* lookup */
6
+ if r0 == 0 goto +2 <LBB0_3>
7
+ lock *(u64 *)(r0 + 0) += r1
@@ -0,0 +1,5 @@
1
+ [
2
+ This is a sample
3
+ comment.
4
+ ]
5
+ .[>+<-]>,
@@ -0,0 +1,6 @@
1
+ _private _method test_object.init()
2
+ ## initializer
3
+ .slot1 << _self.default_value
4
+ _return _self
5
+ _endmethod
6
+ $
@@ -29,7 +29,7 @@ module Rouge
29
29
  end
30
30
 
31
31
  def self.escape_enabled?
32
- !!(@escape_enabled || Thread.current[:'rouge/with-escape'])
32
+ !!(((defined? @escape_enabled) && @escape_enabled) || Thread.current[:'rouge/with-escape'])
33
33
  end
34
34
 
35
35
  def self.enable_escape!
@@ -94,7 +94,7 @@ module Rouge
94
94
 
95
95
  out = []
96
96
  tokens.each do |tok, val|
97
- val.scan /\n|[^\n]+/ do |s|
97
+ val.scan %r/\n|[^\n]+/ do |s|
98
98
  if s == "\n"
99
99
  yield out
100
100
  out = []
@@ -0,0 +1,90 @@
1
+ module Rouge
2
+ module Formatters
3
+ class Tex < Formatter
4
+ tag 'tex'
5
+
6
+ # A map of TeX escape characters.
7
+ # Newlines are handled specially by using #token_lines
8
+ # spaces are preserved as long as they aren't at the beginning
9
+ # of a line. see #tag_first for our initial-space strategy
10
+ ESCAPE = {
11
+ '&' => '\&',
12
+ '%' => '\%',
13
+ '$' => '\$',
14
+ '#' => '\#',
15
+ '_' => '\_',
16
+ '{' => '\{',
17
+ '}' => '\}',
18
+ '~' => '{\textasciitilde}',
19
+ '^' => '{\textasciicircum}',
20
+ '|' => '{\textbar}',
21
+ '\\' => '{\textbackslash}',
22
+ "\t" => '{\tab}',
23
+ }
24
+
25
+ ESCAPE_REGEX = /[#{ESCAPE.keys.map(&Regexp.method(:escape)).join}]/om
26
+
27
+ def initialize(opts={})
28
+ @prefix = opts.fetch(:prefix) { 'RG' }
29
+ end
30
+
31
+ def escape_tex(str)
32
+ str.gsub(ESCAPE_REGEX, ESCAPE)
33
+ end
34
+
35
+ def stream(tokens, &b)
36
+ # surround the output with \begin{RG*}...\end{RG*}
37
+ yield "\\begin{#{@prefix}*}%\n"
38
+
39
+ # we strip the newline off the last line to avoid
40
+ # an extra line being rendered. we do this by yielding
41
+ # the \newline tag *before* every line group except
42
+ # the first.
43
+ first = true
44
+
45
+ token_lines tokens do |line|
46
+ if first
47
+ first = false
48
+ else
49
+ yield "\\newline%\n"
50
+ end
51
+
52
+ render_line(line, &b)
53
+ end
54
+
55
+ yield "%\n\\end{#{@prefix}*}%\n"
56
+ end
57
+
58
+ def render_line(line, &b)
59
+ head, *rest = line
60
+ return unless head
61
+
62
+ tag_first(*head, &b)
63
+ rest.each do |(tok, val)|
64
+ yield tag(tok, val)
65
+ end
66
+ end
67
+
68
+ # special handling for the first token
69
+ # of a line. we replace all initial spaces
70
+ # with \hphantom{xxxx}, which renders an
71
+ # empty space equal to the size of the x's.
72
+ def tag_first(tok, val)
73
+ leading = nil
74
+ val.sub!(/^[ ]+/) { leading = $&.size; '' }
75
+ yield "\\hphantom{#{'x' * leading}}" if leading
76
+ yield tag(tok, val)
77
+ end
78
+
79
+ def tag(tok, val)
80
+ if escape?(tok)
81
+ val
82
+ elsif tok == Token::Tokens::Text
83
+ escape_tex(val)
84
+ else
85
+ "\\#@prefix{#{tok.shortname}}{#{escape_tex(val)}}"
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -32,7 +32,7 @@ module Rouge
32
32
  basename = File.basename(filename)
33
33
 
34
34
  collect_best(lexers) do |lexer|
35
- score = (@glob_map[lexer.name] || []).map do |pattern|
35
+ (@glob_map[lexer.name] || []).map do |pattern|
36
36
  if test_glob(pattern, basename)
37
37
  # specificity is better the fewer wildcards there are
38
38
  -pattern.scan(/[*?\[]/).size
data/lib/rouge/lexer.rb CHANGED
@@ -114,7 +114,7 @@ module Rouge
114
114
  def demo_file(arg=:absent)
115
115
  return @demo_file = Pathname.new(arg) unless arg == :absent
116
116
 
117
- @demo_file = Pathname.new(__FILE__).dirname.join('demos', tag)
117
+ @demo_file = Pathname.new(File.join(__dir__, 'demos', tag))
118
118
  end
119
119
 
120
120
  # Specify or get a small demo string for this lexer
@@ -196,7 +196,7 @@ module Rouge
196
196
  end
197
197
 
198
198
  def disable_debug!
199
- remove_instance_variable :@debug_enabled
199
+ remove_instance_variable :@debug_enabled if defined? @debug_enabled
200
200
  end
201
201
 
202
202
  def debug_enabled?
@@ -213,7 +213,7 @@ module Rouge
213
213
  # @private
214
214
  def register(name, lexer)
215
215
  # reset an existing list of lexers
216
- @all = nil if @all
216
+ @all = nil if defined?(@all)
217
217
  registry[name.to_s] = lexer
218
218
  end
219
219
 
@@ -421,17 +421,29 @@ module Rouge
421
421
  # @option opts :continue
422
422
  # Continue the lex from the previous state (i.e. don't call #reset!)
423
423
  #
424
- # @note The use of `opts` has been deprecated. A warning is issued if run
425
- # with `$VERBOSE` set to true.
426
- def lex(string, opts={}, &b)
427
- unless opts.nil?
428
- warn 'The use of opts with Lexer.lex is deprecated' if $VERBOSE
424
+ # @note The use of :continue => true has been deprecated. A warning is
425
+ # issued if run with `$VERBOSE` set to true.
426
+ #
427
+ # @note The use of arbitrary `opts` has never been supported, but we
428
+ # previously ignored them with no error. We now warn unconditionally.
429
+ def lex(string, opts=nil, &b)
430
+ if opts
431
+ if (opts.keys - [:continue]).size > 0
432
+ # improper use of options hash
433
+ warn('Improper use of Lexer#lex - this method does not receive options.' +
434
+ ' This will become an error in a future version.')
435
+ end
436
+
437
+ if opts[:continue]
438
+ warn '`lex :continue => true` is deprecated, please use #continue_lex instead'
439
+ return continue_lex(string, &b)
440
+ end
429
441
  end
430
442
 
431
- return enum_for(:lex, string, opts) unless block_given?
443
+ return enum_for(:lex, string) unless block_given?
432
444
 
433
445
  Lexer.assert_utf8!(string)
434
- reset! unless opts[:continue]
446
+ reset!
435
447
 
436
448
  continue_lex(string, &b)
437
449
  end
@@ -182,16 +182,16 @@ module Rouge
182
182
  end
183
183
 
184
184
  state :root do
185
- rule /\s+/m, Text
185
+ rule %r/\s+/m, Text
186
186
 
187
- rule /".*/, Comment::Single
187
+ rule %r/".*/, Comment::Single
188
188
  rule %r(^\*.*), Comment::Multiline
189
- rule /\d+/, Num::Integer
190
- rule /('|`)/, Str::Single, :single_string
191
- rule /[\[\]\(\)\{\}\[\]\.,:\|]/, Punctuation
189
+ rule %r/\d+/, Num::Integer
190
+ rule %r/('|`)/, Str::Single, :single_string
191
+ rule %r/[\[\]\(\)\{\}\.,:\|]/, Punctuation
192
192
 
193
193
  # builtins / new ABAP 7.40 keywords (@DATA(), ...)
194
- rule /(->|=>)?([A-Za-z][A-Za-z0-9_\-]*)(\()/ do |m|
194
+ rule %r/(->|=>)?([A-Za-z][A-Za-z0-9_\-]*)(\()/ do |m|
195
195
  if m[1] != ''
196
196
  token Operator, m[1]
197
197
  end
@@ -207,7 +207,7 @@ module Rouge
207
207
  end
208
208
 
209
209
  # keywords, types and normal text
210
- rule /\w[\w\d]*/ do |m|
210
+ rule %r/\w\w*/ do |m|
211
211
  if self.class.keywords.include? m[0].upcase
212
212
  token Keyword
213
213
  elsif self.class.types.include? m[0].downcase
@@ -229,10 +229,10 @@ module Rouge
229
229
  end
230
230
 
231
231
  state :single_string do
232
- rule /\\./, Str::Escape
233
- rule /(''|``)/, Str::Escape
234
- rule /['`]/, Str::Single, :pop!
235
- rule /[^\\'`]+/, Str::Single
232
+ rule %r/\\./, Str::Escape
233
+ rule %r/(''|``)/, Str::Escape
234
+ rule %r/['`]/, Str::Single, :pop!
235
+ rule %r/[^\\'`]+/, Str::Single
236
236
  end
237
237
 
238
238
  end
@@ -13,7 +13,7 @@ module Rouge
13
13
  mimetypes 'application/x-actionscript'
14
14
 
15
15
  state :comments_and_whitespace do
16
- rule /\s+/, Text
16
+ rule %r/\s+/, Text
17
17
  rule %r(//.*?$), Comment::Single
18
18
  rule %r(/\*.*?\*/)m, Comment::Multiline
19
19
  end
@@ -26,9 +26,9 @@ module Rouge
26
26
  goto :regex
27
27
  end
28
28
 
29
- rule /[{]/, Punctuation, :object
29
+ rule %r/[{]/, Punctuation, :object
30
30
 
31
- rule //, Text, :pop!
31
+ rule %r//, Text, :pop!
32
32
  end
33
33
 
34
34
  state :regex do
@@ -39,38 +39,38 @@ module Rouge
39
39
 
40
40
  rule %r([^/]\n), Error, :pop!
41
41
 
42
- rule /\n/, Error, :pop!
43
- rule /\[\^/, Str::Escape, :regex_group
44
- rule /\[/, Str::Escape, :regex_group
45
- rule /\\./, Str::Escape
42
+ rule %r/\n/, Error, :pop!
43
+ rule %r/\[\^/, Str::Escape, :regex_group
44
+ rule %r/\[/, Str::Escape, :regex_group
45
+ rule %r/\\./, Str::Escape
46
46
  rule %r{[(][?][:=<!]}, Str::Escape
47
- rule /[{][\d,]+[}]/, Str::Escape
48
- rule /[()?]/, Str::Escape
49
- rule /./, Str::Regex
47
+ rule %r/[{][\d,]+[}]/, Str::Escape
48
+ rule %r/[()?]/, Str::Escape
49
+ rule %r/./, Str::Regex
50
50
  end
51
51
 
52
52
  state :regex_end do
53
- rule /[gim]+/, Str::Regex, :pop!
53
+ rule %r/[gim]+/, Str::Regex, :pop!
54
54
  rule(//) { pop! }
55
55
  end
56
56
 
57
57
  state :regex_group do
58
58
  # specially highlight / in a group to indicate that it doesn't
59
59
  # close the regex
60
- rule /\//, Str::Escape
60
+ rule %r(/), Str::Escape
61
61
 
62
62
  rule %r([^/]\n) do
63
63
  token Error
64
64
  pop! 2
65
65
  end
66
66
 
67
- rule /\]/, Str::Escape, :pop!
68
- rule /\\./, Str::Escape
69
- rule /./, Str::Regex
67
+ rule %r/\]/, Str::Escape, :pop!
68
+ rule %r/\\./, Str::Escape
69
+ rule %r/./, Str::Regex
70
70
  end
71
71
 
72
72
  state :bad_regex do
73
- rule /[^\n]+/, Error, :pop!
73
+ rule %r/[^\n]+/, Error, :pop!
74
74
  end
75
75
 
76
76
  def self.keywords
@@ -109,25 +109,25 @@ module Rouge
109
109
  id = /[$a-zA-Z_][a-zA-Z0-9_]*/
110
110
 
111
111
  state :root do
112
- rule /\A\s*#!.*?\n/m, Comment::Preproc, :statement
113
- rule /\n/, Text, :statement
112
+ rule %r/\A\s*#!.*?\n/m, Comment::Preproc, :statement
113
+ rule %r/\n/, Text, :statement
114
114
  rule %r((?<=\n)(?=\s|/|<!--)), Text, :expr_start
115
115
  mixin :comments_and_whitespace
116
116
  rule %r(\+\+ | -- | ~ | && | \|\| | \\(?=\n) | << | >>>? | ===
117
117
  | !== )x,
118
118
  Operator, :expr_start
119
119
  rule %r([:-<>+*%&|\^/!=]=?), Operator, :expr_start
120
- rule /[(\[,]/, Punctuation, :expr_start
121
- rule /;/, Punctuation, :statement
122
- rule /[)\].]/, Punctuation
120
+ rule %r/[(\[,]/, Punctuation, :expr_start
121
+ rule %r/;/, Punctuation, :statement
122
+ rule %r/[)\].]/, Punctuation
123
123
 
124
- rule /[?]/ do
124
+ rule %r/[?]/ do
125
125
  token Punctuation
126
126
  push :ternary
127
127
  push :expr_start
128
128
  end
129
129
 
130
- rule /[{}]/, Punctuation, :statement
130
+ rule %r/[{}]/, Punctuation, :statement
131
131
 
132
132
  rule id do |m|
133
133
  if self.class.keywords.include? m[0]
@@ -147,20 +147,20 @@ module Rouge
147
147
  end
148
148
  end
149
149
 
150
- rule /\-?[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?/, Num::Float
151
- rule /0x[0-9a-fA-F]+/, Num::Hex
152
- rule /\-?[0-9]+/, Num::Integer
153
- rule /"(\\\\|\\"|[^"])*"/, Str::Double
154
- rule /'(\\\\|\\'|[^'])*'/, Str::Single
150
+ rule %r/\-?[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?/, Num::Float
151
+ rule %r/0x[0-9a-fA-F]+/, Num::Hex
152
+ rule %r/\-?[0-9]+/, Num::Integer
153
+ rule %r/"(\\\\|\\"|[^"])*"/, Str::Double
154
+ rule %r/'(\\\\|\\'|[^'])*'/, Str::Single
155
155
  end
156
156
 
157
157
  # braced parts that aren't object literals
158
158
  state :statement do
159
- rule /(#{id})(\s*)(:)/ do
159
+ rule %r/(#{id})(\s*)(:)/ do
160
160
  groups Name::Label, Text, Punctuation
161
161
  end
162
162
 
163
- rule /[{}]/, Punctuation
163
+ rule %r/[{}]/, Punctuation
164
164
 
165
165
  mixin :expr_start
166
166
  end
@@ -168,23 +168,23 @@ module Rouge
168
168
  # object literals
169
169
  state :object do
170
170
  mixin :comments_and_whitespace
171
- rule /[}]/ do
171
+ rule %r/[}]/ do
172
172
  token Punctuation
173
173
  goto :statement
174
174
  end
175
175
 
176
- rule /(#{id})(\s*)(:)/ do
176
+ rule %r/(#{id})(\s*)(:)/ do
177
177
  groups Name::Attribute, Text, Punctuation
178
178
  push :expr_start
179
179
  end
180
180
 
181
- rule /:/, Punctuation
181
+ rule %r/:/, Punctuation
182
182
  mixin :root
183
183
  end
184
184
 
185
185
  # ternary expressions, where <id>: is not a label!
186
186
  state :ternary do
187
- rule /:/ do
187
+ rule %r/:/ do
188
188
  token Punctuation
189
189
  goto :expr_start
190
190
  end