rouge 3.23.0 → 3.26.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/lib/rouge/cli.rb +32 -2
  4. data/lib/rouge/demos/email +11 -0
  5. data/lib/rouge/demos/j +12 -0
  6. data/lib/rouge/demos/ocl +4 -0
  7. data/lib/rouge/demos/rescript +26 -0
  8. data/lib/rouge/formatter.rb +2 -2
  9. data/lib/rouge/formatters/html_line_highlighter.rb +24 -0
  10. data/lib/rouge/formatters/html_line_table.rb +1 -3
  11. data/lib/rouge/formatters/html_linewise.rb +2 -3
  12. data/lib/rouge/lexer.rb +38 -20
  13. data/lib/rouge/lexers/apex.rb +9 -7
  14. data/lib/rouge/lexers/batchfile.rb +2 -1
  15. data/lib/rouge/lexers/cmake.rb +10 -0
  16. data/lib/rouge/lexers/cpp.rb +2 -2
  17. data/lib/rouge/lexers/crystal.rb +14 -9
  18. data/lib/rouge/lexers/docker.rb +1 -1
  19. data/lib/rouge/lexers/elm.rb +5 -5
  20. data/lib/rouge/lexers/email.rb +39 -0
  21. data/lib/rouge/lexers/factor.rb +2 -2
  22. data/lib/rouge/lexers/ghc_core.rb +3 -2
  23. data/lib/rouge/lexers/graphql.rb +1 -1
  24. data/lib/rouge/lexers/http.rb +8 -2
  25. data/lib/rouge/lexers/isbl.rb +2 -2
  26. data/lib/rouge/lexers/j.rb +244 -0
  27. data/lib/rouge/lexers/janet.rb +9 -8
  28. data/lib/rouge/lexers/javascript.rb +8 -2
  29. data/lib/rouge/lexers/jsl.rb +25 -14
  30. data/lib/rouge/lexers/jsonnet.rb +4 -3
  31. data/lib/rouge/lexers/jsp.rb +2 -3
  32. data/lib/rouge/lexers/kotlin.rb +5 -4
  33. data/lib/rouge/lexers/ocaml/common.rb +1 -1
  34. data/lib/rouge/lexers/ocl.rb +85 -0
  35. data/lib/rouge/lexers/opentype_feature_file.rb +0 -1
  36. data/lib/rouge/lexers/perl.rb +6 -4
  37. data/lib/rouge/lexers/powershell.rb +39 -29
  38. data/lib/rouge/lexers/python.rb +1 -1
  39. data/lib/rouge/lexers/q.rb +1 -1
  40. data/lib/rouge/lexers/reasonml.rb +6 -5
  41. data/lib/rouge/lexers/rescript.rb +119 -0
  42. data/lib/rouge/lexers/rust.rb +4 -2
  43. data/lib/rouge/lexers/smarty.rb +1 -1
  44. data/lib/rouge/lexers/velocity.rb +1 -1
  45. data/lib/rouge/lexers/wollok.rb +0 -1
  46. data/lib/rouge/lexers/yaml.rb +1 -1
  47. data/lib/rouge/regex_lexer.rb +56 -1
  48. data/lib/rouge/themes/base16.rb +1 -0
  49. data/lib/rouge/themes/bw.rb +1 -0
  50. data/lib/rouge/themes/colorful.rb +1 -0
  51. data/lib/rouge/themes/github.rb +1 -0
  52. data/lib/rouge/themes/gruvbox.rb +2 -0
  53. data/lib/rouge/themes/igor_pro.rb +1 -0
  54. data/lib/rouge/themes/magritte.rb +1 -0
  55. data/lib/rouge/themes/monokai.rb +1 -0
  56. data/lib/rouge/themes/pastie.rb +1 -0
  57. data/lib/rouge/themes/thankful_eyes.rb +1 -0
  58. data/lib/rouge/themes/tulip.rb +1 -0
  59. data/lib/rouge/version.rb +1 -1
  60. data/lib/rouge.rb +1 -0
  61. metadata +12 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: abcc9751ef5e076b3765942693a8f098d83f746aa7527b683bf1b5772f700b48
4
- data.tar.gz: 06074e941ba684cbe5871dfcaeb1dafca415cd228e7223c679847a137d937693
3
+ metadata.gz: bf66ca242ee17857f0f67422e11b25a18f5638d57f54b50399d10983a899ec8b
4
+ data.tar.gz: 05d8673d6c6c1c84e4691137574b18f3a5bd251faa1e8d861a6fa342416be01b
5
5
  SHA512:
6
- metadata.gz: 2db089d9c952c5d79a93659bcb95f008630a60ea35b756f905a51f6d583dc7ab17470faa1a17f77c1165fa0ecee495c0d890a2bebdcc4aef5f03465620691283
7
- data.tar.gz: 8a161de0a32d5a3be6ae31d4112949bea3ffdbd9bd6408dc6b4a6fa3359d9b34c4b214c383c71f3927c9ed2f2431e1240de9cf0f4f02f9d098ebad1ba367dd66
6
+ metadata.gz: 105a0d4429dc9109c4029e7bb142c4e42fb670039b24e8a5aed8f249ba35a85fa8c3aa63ce3be996cc848f4ee54fff50bba5e5061d6e099c36137c0f60948221
7
+ data.tar.gz: a745067ac6959e3ea36ea20b9c73f2df54d75533125545ce4940489faab5cd2293bc123cceb4752cce451871de5702ab927e738a40cadfabc2525886db88715a
data/Gemfile CHANGED
@@ -8,6 +8,7 @@ gem 'rake'
8
8
 
9
9
  gem 'minitest', '>= 5.0'
10
10
  gem 'minitest-power_assert'
11
+ gem 'power_assert', '~> 1.2'
11
12
 
12
13
  gem 'parallel', '~> 1.13.0' if RUBY_VERSION < '2.2.0'
13
14
  gem 'rubocop', '~> 0.49.1'
data/lib/rouge/cli.rb CHANGED
@@ -44,6 +44,7 @@ module Rouge
44
44
  yield %||
45
45
  yield %|where <command> is one of:|
46
46
  yield %| highlight #{Highlight.desc}|
47
+ yield %| debug #{Debug.desc}|
47
48
  yield %| help #{Help.desc}|
48
49
  yield %| style #{Style.desc}|
49
50
  yield %| list #{List.desc}|
@@ -104,6 +105,8 @@ module Rouge
104
105
  Help
105
106
  when 'highlight', 'hi'
106
107
  Highlight
108
+ when 'debug'
109
+ Debug
107
110
  when 'style'
108
111
  Style
109
112
  when 'list'
@@ -215,7 +218,7 @@ module Rouge
215
218
  end
216
219
  end
217
220
 
218
- def self.parse(argv)
221
+ def self.parse_opts(argv)
219
222
  opts = {
220
223
  :formatter => supports_truecolor? ? 'terminal-truecolor' : 'terminal256',
221
224
  :theme => 'thankful_eyes',
@@ -256,7 +259,11 @@ module Rouge
256
259
  end
257
260
  end
258
261
 
259
- new(opts)
262
+ opts
263
+ end
264
+
265
+ def self.parse(argv)
266
+ new(parse_opts(argv))
260
267
  end
261
268
 
262
269
  def input_stream
@@ -344,6 +351,29 @@ module Rouge
344
351
  end
345
352
  end
346
353
 
354
+ class Debug < Highlight
355
+ def self.desc
356
+ end
357
+
358
+ def self.doc
359
+ return enum_for(:doc) unless block_given?
360
+
361
+ yield %|usage: rougify debug [<options>]|
362
+ yield %||
363
+ yield %|Debug a lexer. Similar options to `rougify highlight`, but|
364
+ yield %|defaults to the `null` formatter, and ensures the `debug`|
365
+ yield %|option is enabled, to print debugging information to stdout.|
366
+ end
367
+
368
+ def self.parse_opts(argv)
369
+ out = super(argv)
370
+ out[:lexer_opts]['debug'] = '1'
371
+ out[:formatter] = 'null'
372
+
373
+ out
374
+ end
375
+ end
376
+
347
377
  class Style < CLI
348
378
  def self.desc
349
379
  "print CSS styles"
@@ -0,0 +1,11 @@
1
+ From: Me <me@example.com>
2
+ To: You <you@example.com>
3
+ Date: Tue, 21 Jul 2020 15:14:03 +0000
4
+ Subject: A very important message
5
+
6
+ > Please investigate. Thank you.
7
+
8
+ I have investigated.
9
+
10
+ --
11
+ This message is highly confidential and will self-destruct.
data/lib/rouge/demos/j ADDED
@@ -0,0 +1,12 @@
1
+ NB. Procedural programming
2
+ fizzbuzz=: monad define
3
+ for_i. >:i.y do.
4
+ if. 0 = 15 | i do. echo'FizzBuzz'
5
+ elseif. 0 = 3 | i do. echo'Fizz'
6
+ elseif. 0 = 5 | i do. echo'Buzz'
7
+ else. echo i
8
+ end.
9
+ end.
10
+ )
11
+ NB. Loopless programming
12
+ fizzbuzz=: echo@(, ::] ('Fizz' ; 'Buzz') ;@#~ 0 = 3 5&|)@>:@i.
@@ -0,0 +1,4 @@
1
+ context Compagnie::toEuros() : Collection(Real)
2
+ body: self.employees->collect(each: Employee| each.salary/ 6.55957)
3
+ -- OR
4
+ body: self.employees->collect(salary) -> collect(x | x/6.55957)
@@ -0,0 +1,26 @@
1
+ module Person = {
2
+ type t = Teacher | Director | Student(string)
3
+
4
+ let greeting = person =>
5
+ switch person {
6
+ | Teacher => "Hey Professor!"
7
+ | Director => "Hello Director."
8
+ | Student("Richard") => "Still here Ricky?"
9
+ | Student(other) => "Hey, " ++ other ++ "."
10
+ }
11
+ }
12
+
13
+ module Button = {
14
+ @react.component
15
+ let make = (~count: int, ~onClick) => {
16
+ let times = switch count {
17
+ | 1 => "once"
18
+ | 2 => "twice"
19
+ | n => Belt.Int.toString(n) ++ " times"
20
+ }
21
+
22
+ let msg = "Click me " ++ times
23
+
24
+ <button onClick> {msg->React.string} </button>
25
+ }
26
+ }
@@ -42,8 +42,8 @@ module Rouge
42
42
  end
43
43
 
44
44
  # Format a token stream. Delegates to {#format}.
45
- def self.format(tokens, *a, &b)
46
- new(*a).format(tokens, &b)
45
+ def self.format(tokens, *args, **kwargs, &b)
46
+ new(*args, **kwargs).format(tokens, &b)
47
47
  end
48
48
 
49
49
  def initialize(opts={})
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Formatters
6
+ class HTMLLineHighlighter < Formatter
7
+ tag 'html_line_highlighter'
8
+
9
+ def initialize(delegate, opts = {})
10
+ @delegate = delegate
11
+ @highlight_line_class = opts.fetch(:highlight_line_class, 'hll')
12
+ @highlight_lines = opts[:highlight_lines] || []
13
+ end
14
+
15
+ def stream(tokens)
16
+ token_lines(tokens).with_index(1) do |line_tokens, lineno|
17
+ line = %(#{@delegate.format(line_tokens)}\n)
18
+ line = %(<span class="#{@highlight_line_class}">#{line}</span>) if @highlight_lines.include? lineno
19
+ yield line
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -32,10 +32,8 @@ module Rouge
32
32
  end
33
33
 
34
34
  def stream(tokens, &b)
35
- lineno = @start_line - 1
36
35
  buffer = [%(<table class="#@table_class"><tbody>)]
37
- token_lines(tokens) do |line_tokens|
38
- lineno += 1
36
+ token_lines(tokens).with_index(@start_line) do |line_tokens, lineno|
39
37
  buffer << %(<tr id="#{sprintf @line_id, lineno}" class="#@line_class">)
40
38
  buffer << %(<td class="#@gutter_class gl" )
41
39
  buffer << %(style="-moz-user-select: none;-ms-user-select: none;)
@@ -11,9 +11,8 @@ module Rouge
11
11
  end
12
12
 
13
13
  def stream(tokens, &b)
14
- lineno = 0
15
- token_lines(tokens) do |line_tokens|
16
- yield %(<#{@tag_name} class="#{sprintf @class_format, lineno += 1}">)
14
+ token_lines(tokens).with_index(1) do |line_tokens, lineno|
15
+ yield %(<#{@tag_name} class="#{sprintf @class_format, lineno}">)
17
16
  @formatter.stream(line_tokens) {|formatted| yield formatted }
18
17
  yield %(\n</#{@tag_name}>)
19
18
  end
data/lib/rouge/lexer.rb CHANGED
@@ -38,28 +38,15 @@ module Rouge
38
38
  registry[name.to_s]
39
39
  end
40
40
 
41
- # Find a lexer, with fancy shiny features.
42
- #
43
- # * The string you pass can include CGI-style options
44
- #
45
- # Lexer.find_fancy('erb?parent=tex')
46
- #
47
- # * You can pass the special name 'guess' so we guess for you,
48
- # and you can pass a second argument of the code to guess by
49
- #
50
- # Lexer.find_fancy('guess', "#!/bin/bash\necho Hello, world")
41
+ # Same as ::find_fancy, except instead of returning an instantiated
42
+ # lexer, returns a pair of [lexer_class, options], so that you can
43
+ # modify or provide additional options to the lexer.
51
44
  #
52
- # If the code matches more than one lexer then Guesser::Ambiguous
53
- # is raised.
54
- #
55
- # This is used in the Redcarpet plugin as well as Rouge's own
56
- # markdown lexer for highlighting internal code blocks.
57
- #
58
- def find_fancy(str, code=nil, additional_options={})
59
-
45
+ # Please note: the lexer class might be nil!
46
+ def lookup_fancy(str, code=nil, default_options={})
60
47
  if str && !str.include?('?') && str != 'guess'
61
48
  lexer_class = find(str)
62
- return lexer_class && lexer_class.new(additional_options)
49
+ return [lexer_class, default_options]
63
50
  end
64
51
 
65
52
  name, opts = str ? str.split('?', 2) : [nil, '']
@@ -75,7 +62,7 @@ module Rouge
75
62
  [ k.to_s, val ]
76
63
  end
77
64
 
78
- opts = additional_options.merge(Hash[opts])
65
+ opts = default_options.merge(Hash[opts])
79
66
 
80
67
  lexer_class = case name
81
68
  when 'guess', nil
@@ -84,6 +71,29 @@ module Rouge
84
71
  self.find(name)
85
72
  end
86
73
 
74
+ [lexer_class, opts]
75
+ end
76
+
77
+ # Find a lexer, with fancy shiny features.
78
+ #
79
+ # * The string you pass can include CGI-style options
80
+ #
81
+ # Lexer.find_fancy('erb?parent=tex')
82
+ #
83
+ # * You can pass the special name 'guess' so we guess for you,
84
+ # and you can pass a second argument of the code to guess by
85
+ #
86
+ # Lexer.find_fancy('guess', "#!/bin/bash\necho Hello, world")
87
+ #
88
+ # If the code matches more than one lexer then Guesser::Ambiguous
89
+ # is raised.
90
+ #
91
+ # This is used in the Redcarpet plugin as well as Rouge's own
92
+ # markdown lexer for highlighting internal code blocks.
93
+ #
94
+ def find_fancy(str, code=nil, default_options={})
95
+ lexer_class, opts = lookup_fancy(str, code, default_options)
96
+
87
97
  lexer_class && lexer_class.new(opts)
88
98
  end
89
99
 
@@ -317,6 +327,14 @@ module Rouge
317
327
  @debug = Lexer.debug_enabled? && bool_option('debug')
318
328
  end
319
329
 
330
+ # Returns a new lexer with the given options set. Useful for e.g. setting
331
+ # debug flags post hoc, or providing global overrides for certain options
332
+ def with(opts={})
333
+ new_options = @options.dup
334
+ opts.each { |k, v| new_options[k.to_s] = v }
335
+ self.class.new(new_options)
336
+ end
337
+
320
338
  def as_bool(val)
321
339
  case val
322
340
  when nil, false, 0, '0', 'false', 'off'
@@ -49,7 +49,7 @@ module Rouge
49
49
 
50
50
  state :root do
51
51
  rule %r/\s+/m, Text
52
-
52
+
53
53
  rule %r(//.*?$), Comment::Single
54
54
  rule %r(/\*.*?\*/)m, Comment::Multiline
55
55
 
@@ -57,17 +57,19 @@ module Rouge
57
57
  rule %r/import\b/, Keyword::Namespace, :import
58
58
 
59
59
  rule %r/([@$.]?)(#{id})([:(]?)/io do |m|
60
- if self.class.keywords.include? m[0].downcase
60
+ lowercased = m[0].downcase
61
+ uppercased = m[0].upcase
62
+ if self.class.keywords.include? lowercased
61
63
  token Keyword
62
- elsif self.class.soql.include? m[0].upcase
64
+ elsif self.class.soql.include? uppercased
63
65
  token Keyword
64
- elsif self.class.declarations.include? m[0].downcase
66
+ elsif self.class.declarations.include? lowercased
65
67
  token Keyword::Declaration
66
- elsif self.class.types.include? m[0].downcase
68
+ elsif self.class.types.include? lowercased
67
69
  token Keyword::Type
68
- elsif self.class.constants.include? m[0].downcase
70
+ elsif self.class.constants.include? lowercased
69
71
  token Keyword::Constant
70
- elsif 'package'.casecmp m[0]
72
+ elsif lowercased == 'package'
71
73
  token Keyword::Namespace
72
74
  elsif m[1] == "@"
73
75
  token Name::Decorator
@@ -79,6 +79,7 @@ module Rouge
79
79
  state :basic do
80
80
  # Comments
81
81
  rule %r/@?\brem\b.*$/i, Comment
82
+
82
83
  # Empty Labels
83
84
  rule %r/^::.*$/, Comment
84
85
 
@@ -105,7 +106,7 @@ module Rouge
105
106
  end
106
107
  end
107
108
 
108
- rule %r/([\/\-+][a-z]+)\s*/i, Name::Attribute
109
+ rule %r/((?:[\/\+]|--?)[a-z]+)\s*/i, Name::Attribute
109
110
 
110
111
  mixin :expansions
111
112
 
@@ -22,6 +22,7 @@ module Rouge
22
22
  }
23
23
 
24
24
  BUILTIN_COMMANDS = Set.new %w[
25
+ add_compile_definitions
25
26
  add_compile_options
26
27
  add_custom_command
27
28
  add_custom_target
@@ -29,6 +30,7 @@ module Rouge
29
30
  add_dependencies
30
31
  add_executable
31
32
  add_library
33
+ add_link_options
32
34
  add_subdirectory
33
35
  add_test
34
36
  aux_source_directory
@@ -36,7 +38,9 @@ module Rouge
36
38
  build_command
37
39
  build_name
38
40
  cmake_host_system_information
41
+ cmake_language
39
42
  cmake_minimum_required
43
+ cmake_parse_arguments
40
44
  cmake_policy
41
45
  configure_file
42
46
  create_test_sourcelist
@@ -74,6 +78,7 @@ module Rouge
74
78
  include
75
79
  include_directories
76
80
  include_external_msproject
81
+ include_guard
77
82
  include_regular_expression
78
83
  install
79
84
  install_files
@@ -110,9 +115,14 @@ module Rouge
110
115
  subdir_depends
111
116
  subdirs
112
117
  target_compile_definitions
118
+ target_compile_features
113
119
  target_compile_options
114
120
  target_include_directories
121
+ target_link_directories
115
122
  target_link_libraries
123
+ target_link_options
124
+ target_precompile_headers
125
+ target_sources
116
126
  try_compile
117
127
  try_run
118
128
  unset
@@ -59,11 +59,11 @@ module Rouge
59
59
  prepend :statements do
60
60
  rule %r/(class|struct)\b/, Keyword, :classname
61
61
  rule %r/template\b/, Keyword, :template
62
- rule %r/\d+(\.\d+)?(?:h|(?:min)|s|(?:ms)|(?:us)|(?:ns))/, Num::Other
62
+ rule %r/#{dq}(\.#{dq})?(?:y|d|h|(?:min)|s|(?:ms)|(?:us)|(?:ns)|i|(?:if)|(?:il))\b/, Num::Other
63
63
  rule %r((#{dq}[.]#{dq}?|[.]#{dq})(e[+-]?#{dq}[lu]*)?)i, Num::Float
64
64
  rule %r(#{dq}e[+-]?#{dq}[lu]*)i, Num::Float
65
65
  rule %r/0x\h('?\h)*[lu]*/i, Num::Hex
66
- rule %r/0b[01]+(?:_[01]+)*/, Num::Bin
66
+ rule %r/0b[01]+('[01]+)*/, Num::Bin
67
67
  rule %r/0[0-7]('?[0-7])*[lu]*/i, Num::Oct
68
68
  rule %r/#{dq}[lu]*/i, Num::Integer
69
69
  rule %r/\bnullptr\b/, Name::Builtin
@@ -25,8 +25,7 @@ module Rouge
25
25
  )xi, Str::Symbol
26
26
 
27
27
  # special symbols
28
- rule %r(:(?:\*\*|[-+]@|[/\%&\|^`~]|\[\]=?|<<|>>|<=?>|<=?|===?)),
29
- Str::Symbol
28
+ rule %r(:(?:===|=?~|\[\][=?]?|\*\*=?|\/\/=?|[=^*/+-]=?|&[&*+-]?=?|\|\|?=?|![=~]?|%=?|<=>|<<?=?|>>?=?|\.\.\.?)), Str::Symbol
30
29
 
31
30
  rule %r/:'(\\\\|\\'|[^'])*'/, Str::Symbol
32
31
  rule %r/:"/, Str::Symbol, :simple_sym
@@ -36,7 +35,7 @@ module Rouge
36
35
  # %-sigiled strings
37
36
  # %(abc), %[abc], %<abc>, %.abc., %r.abc., etc
38
37
  delimiter_map = { '{' => '}', '[' => ']', '(' => ')', '<' => '>' }
39
- rule %r/%([rqswQWxiI])?([^\w\s])/ do |m|
38
+ rule %r/%([rqswQWxiI])?([^\w\s}])/ do |m|
40
39
  open = Regexp.escape(m[2])
41
40
  close = Regexp.escape(delimiter_map[m[2]] || m[2])
42
41
  interp = /[rQWxI]/ === m[1]
@@ -79,9 +78,11 @@ module Rouge
79
78
  state :strings do
80
79
  mixin :symbols
81
80
  rule %r/\b[a-z_]\w*?[?!]?:\s+/, Str::Symbol, :expr_start
82
- rule %r/'(\\\\|\\'|[^'])*'/, Str::Single
83
81
  rule %r/"/, Str::Double, :simple_string
84
82
  rule %r/(?<!\.)`/, Str::Backtick, :simple_backtick
83
+ rule %r/(')(\\u[a-fA-F0-9]{4}|\\u\{[a-fA-F0-9]{1,6}\}|\\[abefnrtv])?(\\\\|\\'|[^'])*(')/ do
84
+ groups Str::Single, Str::Escape, Str::Single, Str::Single
85
+ end
85
86
  end
86
87
 
87
88
  state :regex_flags do
@@ -154,11 +155,13 @@ module Rouge
154
155
  mixin :whitespace
155
156
  rule %r/__END__/, Comment::Preproc, :end_part
156
157
 
157
- rule %r/0_?[0-7]+(?:_[0-7]+)*/, Num::Oct
158
+ rule %r/0o[0-7]+(?:_[0-7]+)*/, Num::Oct
158
159
  rule %r/0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*/, Num::Hex
159
160
  rule %r/0b[01]+(?:_[01]+)*/, Num::Bin
160
- rule %r/\d+\.\d+(e[\+\-]?\d+)?/, Num::Float
161
- rule %r/[\d]+(?:_\d+)*/, Num::Integer
161
+ rule %r/\d+\.\d+(e[\+\-]?\d+)?(_f32)?/i, Num::Float
162
+ rule %r/\d+(e[\+\-]?\d+)/i, Num::Float
163
+ rule %r/\d+_f32/i, Num::Float
164
+ rule %r/[\d]+(?:_\d+)*(_[iu]\d+)?/, Num::Integer
162
165
 
163
166
  rule %r/@\[([^\]]+)\]/, Name::Decorator
164
167
 
@@ -183,7 +186,7 @@ module Rouge
183
186
  groups Keyword, Text, Name::Namespace
184
187
  end
185
188
 
186
- rule %r/(def\b)(\s*)/ do
189
+ rule %r/(def|macro\b)(\s*)/ do
187
190
  groups Keyword, Text
188
191
  push :funcname
189
192
  end
@@ -212,8 +215,9 @@ module Rouge
212
215
 
213
216
  rule %r/[a-zA-Z_]\w*[?!]/, Name, :expr_start
214
217
  rule %r/[a-zA-Z_]\w*/, Name, :method_call
215
- rule %r/\*\*|<<?|>>?|>=|<=|<=>|=~|={3}|!~|&&?|\|\||\./,
218
+ rule %r/\*\*|\/\/|>=|<=|<=>|<<?|>>?|=~|={3}|!~|&&?|\|\||\./,
216
219
  Operator, :expr_start
220
+ rule %r/{%|%}/, Punctuation
217
221
  rule %r/[-+\/*%=<>&!^|~]=?/, Operator, :expr_start
218
222
  rule(/[?]/) { token Punctuation; push :ternary; push :expr_start }
219
223
  rule %r<[\[({,:\\;/]>, Punctuation, :expr_start
@@ -346,6 +350,7 @@ module Rouge
346
350
  mixin :string_intp
347
351
  rule %r/\\([\\abefnrstv#"']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})/,
348
352
  Str::Escape
353
+ rule %r/\\u([a-fA-F0-9]{4}|\{[^}]+\})/, Str::Escape
349
354
  rule %r/\\./, Str::Escape
350
355
  end
351
356
 
@@ -7,7 +7,7 @@ module Rouge
7
7
  title "Docker"
8
8
  desc "Dockerfile syntax"
9
9
  tag 'docker'
10
- aliases 'dockerfile'
10
+ aliases 'dockerfile', 'Dockerfile'
11
11
  filenames 'Dockerfile', '*.Dockerfile', '*.docker'
12
12
  mimetypes 'text/x-dockerfile-config'
13
13
 
@@ -78,13 +78,13 @@ module Rouge
78
78
  rule %r/"/, Str::Double, :pop!
79
79
  end
80
80
 
81
- # Multiple line string with tripple double quotes, e.g. """ multi """
81
+ # Multiple line string with triple double quotes, e.g. """ multi """
82
82
  state :multiline_string do
83
- rule %r/\s*"""/, Str, :pop!
84
- rule %r/.*/, Str
85
- rule %r/\s*/, Str
83
+ rule %r/\\"/, Str::Escape
84
+ rule %r/"""/, Str, :pop!
85
+ rule %r/[^"]+/, Str
86
+ rule %r/"/, Str
86
87
  end
87
-
88
88
  end
89
89
  end
90
90
  end
@@ -0,0 +1,39 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class Email < RegexLexer
7
+ tag 'email'
8
+ aliases 'eml', 'e-mail'
9
+ filenames '*.eml'
10
+ mimetypes 'message/rfc822'
11
+
12
+ title "Email"
13
+ desc "An email message"
14
+
15
+ start do
16
+ push :fields
17
+ end
18
+
19
+ state :fields do
20
+ rule %r/[:]/, Operator, :field_body
21
+ rule %r/[^\n\r:]+/, Name::Tag
22
+ rule %r/[\n\r]/, Name::Tag
23
+ end
24
+
25
+ state :field_body do
26
+ rule(/(\r?\n){2}/) { token Text; pop!(2) }
27
+ rule %r/\r?\n(?![ \v\t\f])/, Text, :pop!
28
+ rule %r/[^\n\r]+/, Name::Attribute
29
+ rule %r/[\n\r]/, Name::Attribute
30
+ end
31
+
32
+ state :root do
33
+ rule %r/\n/, Text
34
+ rule %r/^>.*/, Comment
35
+ rule %r/.+/, Text
36
+ end
37
+ end
38
+ end
39
+ end
@@ -243,8 +243,8 @@ module Rouge
243
243
  end
244
244
 
245
245
  # strings
246
- rule %r/"""\s+.*?\s+"""/, Str
247
- rule %r/"(\\.|[^\\])*?"/, Str
246
+ rule %r/"(?:\\\\|\\"|[^"])*"/, Str
247
+ rule %r/\S+"\s+(?:\\\\|\\"|[^"])*"/, Str
248
248
  rule %r/(CHAR:)(\s+)(\\[\\abfnrstv]*|\S)(?=\s)/, Str::Char
249
249
 
250
250
  # comments
@@ -17,7 +17,7 @@ module Rouge
17
17
  rule %r/^=====.*=====$/, Generic::Heading
18
18
  # timestamps
19
19
  rule %r/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ UTC$/, Comment::Single
20
- rule %r/^Result size of .+\s*.*}/, Comment::Multiline
20
+ rule %r/^Result size of .+\n.+{[^}]*}/, Comment::Multiline
21
21
  rule %r/--.*$/, Comment::Single
22
22
 
23
23
  rule %r/\[/, Comment::Special, :annotation
@@ -27,8 +27,9 @@ module Rouge
27
27
  mixin :function
28
28
 
29
29
  # rest is Text
30
+ # TODO: this is really inefficient
30
31
  rule %r/\s/m, Text
31
- rule %r/.*/, Text
32
+ rule %r/./, Text
32
33
  end
33
34
 
34
35
  state :expression do
@@ -20,7 +20,7 @@ module Rouge
20
20
  end
21
21
 
22
22
  rule %r/\bfragment\b/, Keyword, :fragment_definition
23
-
23
+
24
24
  rule %r/\bscalar\b/, Keyword, :value
25
25
 
26
26
  rule %r/\b(?:type|interface|enum)\b/, Keyword, :type_definition
@@ -8,16 +8,22 @@ module Rouge
8
8
  title "HTTP"
9
9
  desc 'http requests and responses'
10
10
 
11
+ option :content, "the language for the content (default: auto-detect)"
12
+
11
13
  def self.http_methods
12
14
  @http_methods ||= %w(GET POST PUT DELETE HEAD OPTIONS TRACE PATCH)
13
15
  end
14
16
 
15
17
  def content_lexer
18
+ @content_lexer ||= (lexer_option(:content) || guess_content_lexer)
19
+ end
20
+
21
+ def guess_content_lexer
16
22
  return Lexers::PlainText unless @content_type
17
23
 
18
- @content_lexer ||= Lexer.guess_by_mimetype(@content_type)
24
+ Lexer.guess_by_mimetype(@content_type)
19
25
  rescue Lexer::AmbiguousGuess
20
- @content_lexer = Lexers::PlainText
26
+ Lexers::PlainText
21
27
  end
22
28
 
23
29
  start { @content_type = 'text/plain' }
@@ -41,7 +41,7 @@ module Rouge
41
41
 
42
42
  state :dotted do
43
43
  mixin :whitespace
44
- rule %r/[a-zа-яё_0-9]*/i do |m|
44
+ rule %r/[a-zа-яё_0-9]+/i do |m|
45
45
  name = m[0]
46
46
  if self.class.constants.include? name.downcase
47
47
  token Name::Builtin
@@ -56,7 +56,7 @@ module Rouge
56
56
 
57
57
  state :type do
58
58
  mixin :whitespace
59
- rule %r/[a-zа-яё_0-9]*/i do |m|
59
+ rule %r/[a-zа-яё_0-9]+/i do |m|
60
60
  name = m[0]
61
61
  if self.class.interfaces.include? name.downcase
62
62
  token Keyword::Type