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
@@ -21,11 +21,11 @@ module Rouge
21
21
  start { markdown.reset!; coffee.reset! }
22
22
 
23
23
  state :root do
24
- rule /^( .*?\n)+/m do
24
+ rule %r/^( .*?\n)+/m do
25
25
  delegate coffee
26
26
  end
27
27
 
28
- rule /^([ ]{0,3}(\S.*?|)\n)*/m do
28
+ rule %r/^([ ]{0,3}(\S.*?|)\n)*/m do
29
29
  delegate markdown
30
30
  end
31
31
  end
@@ -19,18 +19,18 @@ module Rouge
19
19
 
20
20
  # TODO: support TeX versions as well.
21
21
  state :root do
22
- rule /\s*?\n(?=>)/, Text, :code
23
- rule /.*?\n/, Text
24
- rule /.+\z/, Text
22
+ rule %r/\s*?\n(?=>)/, Text, :code
23
+ rule %r/.*?\n/, Text
24
+ rule %r/.+\z/, Text
25
25
  end
26
26
 
27
27
  state :code do
28
- rule /(>)( .*?(\n|\z))/ do |m|
28
+ rule %r/(>)( .*?(\n|\z))/ do |m|
29
29
  token Name::Label, m[1]
30
30
  delegate haskell, m[2]
31
31
  end
32
32
 
33
- rule /\s*\n(?=\s*[^>])/, Text, :pop!
33
+ rule %r/\s*\n(?=\s*[^>])/, Text, :pop!
34
34
  end
35
35
  end
36
36
  end
@@ -15,21 +15,22 @@ module Rouge
15
15
  identifier = /([-a-zA-Z$._][-a-zA-Z$._0-9]*|#{string})/
16
16
 
17
17
  state :basic do
18
- rule /;.*?$/, Comment::Single
19
- rule /\s+/, Text
18
+ rule %r/;.*?$/, Comment::Single
19
+ rule %r/\s+/, Text
20
20
 
21
- rule /#{identifier}\s*:/, Name::Label
21
+ rule %r/#{identifier}\s*:/, Name::Label
22
22
 
23
- rule /@(#{identifier}|\d+)/, Name::Variable::Global
24
- rule /(%|!)#{identifier}/, Name::Variable
25
- rule /(%|!)\d+/, Name::Variable
23
+ rule %r/@(#{identifier}|\d+)/, Name::Variable::Global
24
+ rule %r/#\d+/, Name::Variable::Global
25
+ rule %r/(%|!)#{identifier}/, Name::Variable
26
+ rule %r/(%|!)\d+/, Name::Variable
26
27
 
27
- rule /c?#{string}/, Str
28
+ rule %r/c?#{string}/, Str
28
29
 
29
- rule /0[xX][a-fA-F0-9]+/, Num
30
- rule /-?\d+(?:[.]\d+)?(?:[eE][-+]?\d+(?:[.]\d+)?)?/, Num
30
+ rule %r/0[xX][a-fA-F0-9]+/, Num
31
+ rule %r/-?\d+(?:[.]\d+)?(?:[eE][-+]?\d+(?:[.]\d+)?)?/, Num
31
32
 
32
- rule /[=<>{}\[\]()*.,!]|x/, Punctuation
33
+ rule %r/[=<>{}\[\]()*.,!]|x/, Punctuation
33
34
  end
34
35
 
35
36
  builtin_types = %w(
@@ -37,12 +38,12 @@ module Rouge
37
38
  )
38
39
 
39
40
  state :types do
40
- rule /i[1-9]\d*/, Keyword::Type
41
- rule /#{builtin_types.join('|')}/, Keyword::Type
41
+ rule %r/i[1-9]\d*/, Keyword::Type
42
+ rule %r/#{builtin_types.join('|')}/, Keyword::Type
42
43
  end
43
44
 
44
45
  builtin_keywords = %w(
45
- begin end true false declare define global constant personality private
46
+ begin end true false declare define global constant alignstack private
46
47
  landingpad linker_private internal available_externally linkonce_odr
47
48
  linkonce weak weak_odr appending dllimport dllexport common default
48
49
  hidden protected extern_weak external thread_local zeroinitializer
@@ -54,7 +55,13 @@ module Rouge
54
55
  nest readnone readonly inlinehint noinline alwaysinline optsize ssp
55
56
  sspreq noredzone noimplicitfloat naked type opaque eq ne slt sgt sle
56
57
  sge ult ugt ule uge oeq one olt ogt ole oge ord uno unnamed_addr ueq
57
- une uwtable x
58
+ une uwtable x personality allocsize builtin cold convergent
59
+ inaccessiblememonly inaccessiblemem_or_argmemonly jumptable minsize
60
+ no-jump-tables nobuiltin noduplicate nonlazybind noredzone norecurse
61
+ optforfuzzing optnone writeonly argmemonly returns_twice safestack
62
+ sanitize_address sanitize_memory sanitize_thread sanitize_hwaddress
63
+ speculative_load_hardening speculatable sspstrong strictfp nocf_check
64
+ shadowcallstack attributes
58
65
  )
59
66
 
60
67
  builtin_instructions = %w(
@@ -67,8 +74,8 @@ module Rouge
67
74
  )
68
75
 
69
76
  state :keywords do
70
- rule /#{builtin_instructions.join('|')}/, Keyword
71
- rule /#{builtin_keywords.join('|')}/, Keyword
77
+ rule %r/#{builtin_instructions.join('|')}/, Keyword
78
+ rule %r/#{builtin_keywords.join('|')}/, Keyword
72
79
  end
73
80
 
74
81
  state :root do
@@ -25,7 +25,7 @@ module Rouge
25
25
  end
26
26
 
27
27
  def self.builtins
28
- load Pathname.new(__FILE__).dirname.join('lua/builtins.rb')
28
+ load File.join(__dir__, 'lua/builtins.rb')
29
29
  self.builtins
30
30
  end
31
31
 
@@ -43,7 +43,7 @@ module Rouge
43
43
  state :root do
44
44
  # lua allows a file to start with a shebang
45
45
  rule %r(#!(.*?)$), Comment::Preproc
46
- rule //, Text, :base
46
+ rule %r//, Text, :base
47
47
  end
48
48
 
49
49
  state :base do
@@ -89,7 +89,7 @@ module Rouge
89
89
  end
90
90
 
91
91
  state :function_name do
92
- rule /\s+/, Text
92
+ rule %r/\s+/, Text
93
93
  rule %r((?:([A-Za-z_][A-Za-z0-9_]*)(\.))?([A-Za-z_][A-Za-z0-9_]*)) do
94
94
  groups Name::Class, Punctuation, Name::Function
95
95
  pop!
@@ -9,7 +9,6 @@ module Rouge
9
9
  title "M68k"
10
10
  desc "Motorola 68k Assembler"
11
11
 
12
- ws = %r((?:\s|;.*?\n/)+)
13
12
  id = /[a-zA-Z_][a-zA-Z0-9_]*/
14
13
 
15
14
  def self.keywords
@@ -83,11 +82,11 @@ module Rouge
83
82
  end
84
83
 
85
84
  state :inline_whitespace do
86
- rule /[\s\t\r]+/, Text
85
+ rule %r/\s+/, Text
87
86
  end
88
87
 
89
88
  state :whitespace do
90
- rule /\n+/m, Text, :expr_bol
89
+ rule %r/\n+/m, Text, :expr_bol
91
90
  rule %r(^\*(\\.|.)*?\n), Comment::Single, :expr_bol
92
91
  rule %r(;(\\.|.)*?\n), Comment::Single, :expr_bol
93
92
  mixin :inline_whitespace
@@ -99,19 +98,19 @@ module Rouge
99
98
 
100
99
  state :statements do
101
100
  mixin :whitespace
102
- rule /"/, Str, :string
103
- rule /#/, Name::Decorator
104
- rule /^\.?[a-zA-Z0-9_]+:?/, Name::Label
105
- rule /\.[bswl]\s/i, Name::Decorator
101
+ rule %r/"/, Str, :string
102
+ rule %r/#/, Name::Decorator
103
+ rule %r/^\.?[a-zA-Z0-9_]+:?/, Name::Label
104
+ rule %r/\.[bswl]\s/i, Name::Decorator
106
105
  rule %r('(\\.|\\[0-7]{1,3}|\\x[a-f0-9]{1,2}|[^\\'\n])')i, Str::Char
107
- rule /\$[0-9a-f]+/i, Num::Hex
108
- rule /@[0-8]+/i, Num::Oct
109
- rule /%[01]+/i, Num::Bin
110
- rule /\d+/i, Num::Integer
106
+ rule %r/\$[0-9a-f]+/i, Num::Hex
107
+ rule %r/@[0-8]+/i, Num::Oct
108
+ rule %r/%[01]+/i, Num::Bin
109
+ rule %r/\d+/i, Num::Integer
111
110
  rule %r([*~&+=\|?:<>/-]), Operator
112
- rule /\\./, Comment::Preproc
113
- rule /[(),.]/, Punctuation
114
- rule /\[[a-zA-Z0-9]*\]/, Punctuation
111
+ rule %r/\\./, Comment::Preproc
112
+ rule %r/[(),.]/, Punctuation
113
+ rule %r/\[[a-zA-Z0-9]*\]/, Punctuation
115
114
 
116
115
  rule id do |m|
117
116
  name = m[0]
@@ -133,11 +132,11 @@ module Rouge
133
132
  end
134
133
 
135
134
  state :string do
136
- rule /"/, Str, :pop!
137
- rule /\\([\\abfnrtv"']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})/, Str::Escape
138
- rule /[^\\"\n]+/, Str
139
- rule /\\\n/, Str
140
- rule /\\/, Str # stray backslash
135
+ rule %r/"/, Str, :pop!
136
+ rule %r/\\([\\abfnrtv"']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})/, Str::Escape
137
+ rule %r/[^\\"\n]+/, Str
138
+ rule %r/\\\n/, Str
139
+ rule %r/\\/, Str # stray backslash
141
140
  end
142
141
  end
143
142
  end
@@ -0,0 +1,126 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class Magik < RegexLexer
7
+ title "Magik"
8
+ desc "Smallworld Magik"
9
+ tag 'magik'
10
+ filenames '*.magik'
11
+ mimetypes 'text/x-magik', 'application/x-magik'
12
+
13
+ def self.keywords
14
+ @keywords ||= %w(
15
+ _package
16
+ _pragma
17
+ _block _endblock
18
+ _handling _default
19
+ _protect _protection _endprotect
20
+ _try _with _when _endtry
21
+ _catch _endcatch
22
+ _throw
23
+ _lock _endlock
24
+ _if _then _elif _else _endif
25
+ _for _over _loop _endloop _loopbody _continue _leave
26
+ _return
27
+ _local _constant _recursive _global _dynamic _import
28
+ _private _iter _abstract _method _endmethod
29
+ _proc _endproc
30
+ _gather _scatter _allresults _optional
31
+ _thisthread _self _clone _super
32
+ _primitive
33
+ _unset _true _false _maybe
34
+ _is _isnt _not _and _or _xor _cf _andif _orif
35
+ _div _mod
36
+ )
37
+ end
38
+
39
+ def self.string_double
40
+ @string_double ||= /"[^"\n]*?"/
41
+ end
42
+ def self.string_single
43
+ @string_single ||= /'[^'\n]*?'/
44
+ end
45
+
46
+ def self.digits
47
+ @digits ||= /[0-9]+/
48
+ end
49
+ def self.radix
50
+ @radix ||= /r[0-9a-z]/i
51
+ end
52
+ def self.exponent
53
+ @exponent ||= /(e|&)[+-]?#{Magik.digits}/i
54
+ end
55
+ def self.decimal
56
+ @decimal ||= /\.#{Magik.digits}/
57
+ end
58
+ def self.number
59
+ @number = /#{Magik.digits}(#{Magik.radix}|#{Magik.exponent}|#{Magik.decimal})*/
60
+ end
61
+
62
+ def self.character
63
+ @character ||= /%u[0-9a-z]{4}|%[^\s]+/i
64
+ end
65
+
66
+ def self.simple_identifier
67
+ @simple_identifier ||= /(?>(?:[a-z0-9_!?]|\\.)+)/i
68
+ end
69
+ def self.piped_identifier
70
+ @piped_identifier ||= /\|[^\|\n]*\|/
71
+ end
72
+ def self.identifier
73
+ @identifier ||= /(?:#{Magik.simple_identifier}|#{Magik.piped_identifier})+/i
74
+ end
75
+ def self.package_identifier
76
+ @package_identifier ||= /#{Magik.identifier}:#{Magik.identifier}/
77
+ end
78
+ def self.symbol
79
+ @symbol ||= /:#{Magik.identifier}/i
80
+ end
81
+ def self.global_ref
82
+ @global_ref ||= /@[\s]*#{Magik.identifier}:#{Magik.identifier}/
83
+ end
84
+ def self.label
85
+ @label = /@[\s]*#{Magik.identifier}/
86
+ end
87
+
88
+ state :root do
89
+ rule %r/##(.*)?/, Comment::Doc
90
+ rule %r/#(.*)?/, Comment::Single
91
+
92
+ rule %r/(_method)(\s+)/ do
93
+ groups Keyword, Text::Whitespace
94
+ push :method_name
95
+ end
96
+
97
+ rule %r/(?:#{Magik.keywords.join('|')})\b/, Keyword
98
+
99
+ rule Magik.string_double, Literal::String
100
+ rule Magik.string_single, Literal::String
101
+ rule Magik.symbol, Str::Symbol
102
+ rule Magik.global_ref, Name::Label
103
+ rule Magik.label, Name::Label
104
+ rule Magik.character, Literal::String::Char
105
+ rule Magik.number, Literal::Number
106
+ rule Magik.package_identifier, Name
107
+ rule Magik.identifier, Name
108
+
109
+ rule %r/[\[\]{}()\.,;]/, Punctuation
110
+ rule %r/\$/, Punctuation
111
+ rule %r/(<<|^<<)/, Operator
112
+ rule %r/(>>)/, Operator
113
+ rule %r/[-~+\/*%=&^<>]|!=/, Operator
114
+
115
+ rule %r/[\s]+/, Text::Whitespace
116
+ end
117
+
118
+ state :method_name do
119
+ rule %r/(#{Magik.identifier})(\.)(#{Magik.identifier})/ do
120
+ groups Name::Class, Punctuation, Name::Function
121
+ pop!
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -15,12 +15,6 @@ module Rouge
15
15
  include undef error warning if else elif endif for endfor
16
16
  )
17
17
 
18
- gnu_special = %w(
19
- ifeq ifneq ifdef ifndef else endif include -include define endef :
20
- )
21
-
22
- line = /(?:\\.|\\\n|[^\\\n])*/m
23
-
24
18
  def initialize(opts={})
25
19
  super
26
20
  @shell = Shell.new(opts)
@@ -29,53 +23,53 @@ module Rouge
29
23
  start { @shell.reset! }
30
24
 
31
25
  state :root do
32
- rule /\s+/, Text
26
+ rule %r/\s+/, Text
33
27
 
34
- rule /#.*?\n/, Comment
28
+ rule %r/#.*?\n/, Comment
35
29
 
36
- rule /(export)(\s+)(?=[a-zA-Z0-9_\${}\t -]+\n)/ do
30
+ rule %r/(export)(\s+)(?=[a-zA-Z0-9_\${}\t -]+\n)/ do
37
31
  groups Keyword, Text
38
32
  push :export
39
33
  end
40
34
 
41
- rule /export\s+/, Keyword
35
+ rule %r/export\s+/, Keyword
42
36
 
43
37
  # assignment
44
- rule /([a-zA-Z0-9_${}.-]+)(\s*)([!?:+]?=)/m do |m|
38
+ rule %r/([a-zA-Z0-9_${}.-]+)(\s*)([!?:+]?=)/m do |m|
45
39
  token Name::Variable, m[1]
46
40
  token Text, m[2]
47
41
  token Operator, m[3]
48
42
  push :shell_line
49
43
  end
50
44
 
51
- rule /"(\\\\|\\.|[^"\\])*"/, Str::Double
52
- rule /'(\\\\|\\.|[^'\\])*'/, Str::Single
53
- rule /([^\n:]+)(:+)([ \t]*)/ do
45
+ rule %r/"(\\\\|\\.|[^"\\])*"/, Str::Double
46
+ rule %r/'(\\\\|\\.|[^'\\])*'/, Str::Single
47
+ rule %r/([^\n:]+)(:+)([ \t]*)/ do
54
48
  groups Name::Label, Operator, Text
55
49
  push :block_header
56
50
  end
57
51
  end
58
52
 
59
53
  state :export do
60
- rule /[\w\${}-]/, Name::Variable
61
- rule /\n/, Text, :pop!
62
- rule /\s+/, Text
54
+ rule %r/[\w\${}-]/, Name::Variable
55
+ rule %r/\n/, Text, :pop!
56
+ rule %r/\s+/, Text
63
57
  end
64
58
 
65
59
  state :block_header do
66
- rule /[^,\\\n#]+/, Name::Function
67
- rule /,/, Punctuation
68
- rule /#.*?/, Comment
69
- rule /\\\n/, Text
70
- rule /\\./, Text
71
- rule /\n/ do
60
+ rule %r/[^,\\\n#]+/, Name::Function
61
+ rule %r/,/, Punctuation
62
+ rule %r/#.*?/, Comment
63
+ rule %r/\\\n/, Text
64
+ rule %r/\\./, Text
65
+ rule %r/\n/ do
72
66
  token Text
73
67
  goto :block_body
74
68
  end
75
69
  end
76
70
 
77
71
  state :block_body do
78
- rule /(\t[\t ]*)([@-]?)/ do |m|
72
+ rule %r/(\t[\t ]*)([@-]?)/ do |m|
79
73
  groups Text, Punctuation
80
74
  push :shell_line
81
75
  end
@@ -85,9 +79,9 @@ module Rouge
85
79
 
86
80
  state :shell do
87
81
  # macro interpolation
88
- rule /\$\(\s*[a-z_]\w*\s*\)/i, Name::Variable
82
+ rule %r/\$\(\s*[a-z_]\w*\s*\)/i, Name::Variable
89
83
  # $(shell ...)
90
- rule /(\$\()(\s*)(shell)(\s+)/m do
84
+ rule %r/(\$\()(\s*)(shell)(\s+)/m do
91
85
  groups Name::Function, Text, Name::Builtin, Text
92
86
  push :shell_expr
93
87
  end
@@ -100,12 +94,12 @@ module Rouge
100
94
 
101
95
  state :shell_expr do
102
96
  rule(/\(/) { delegate @shell; push }
103
- rule /\)/, Name::Variable, :pop!
97
+ rule %r/\)/, Name::Variable, :pop!
104
98
  mixin :shell
105
99
  end
106
100
 
107
101
  state :shell_line do
108
- rule /\n/, Text, :pop!
102
+ rule %r/\n/, Text, :pop!
109
103
  mixin :shell
110
104
  end
111
105
  end
@@ -24,15 +24,15 @@ module Rouge
24
24
  # YAML frontmatter
25
25
  rule(/\A(---\s*\n.*?\n?)^(---\s*$\n?)/m) { delegate YAML }
26
26
 
27
- rule /\\./, Str::Escape
27
+ rule %r/\\./, Str::Escape
28
28
 
29
- rule /^[\S ]+\n(?:---*)\n/, Generic::Heading
30
- rule /^[\S ]+\n(?:===*)\n/, Generic::Subheading
29
+ rule %r/^[\S ]+\n(?:---*)\n/, Generic::Heading
30
+ rule %r/^[\S ]+\n(?:===*)\n/, Generic::Subheading
31
31
 
32
- rule /^#(?=[^#]).*?$/, Generic::Heading
33
- rule /^##*.*?$/, Generic::Subheading
32
+ rule %r/^#(?=[^#]).*?$/, Generic::Heading
33
+ rule %r/^##*.*?$/, Generic::Subheading
34
34
 
35
- rule /^([ \t]*)(```|~~~)([^\n]*\n)((.*?)(\2))?/m do |m|
35
+ rule %r/^([ \t]*)(```|~~~)([^\n]*\n)((.*?)(\2))?/m do |m|
36
36
  name = m[3].strip
37
37
  sublexer = Lexer.find_fancy(name.empty? ? "guess" : name, m[5], @options)
38
38
  sublexer ||= PlainText.new(@options.merge(:token => Str::Backtick))
@@ -49,36 +49,36 @@ module Rouge
49
49
  token Punctuation, m[6]
50
50
  else
51
51
  push do
52
- rule /^([ \t]*)(#{m[2]})/ do |mb|
52
+ rule %r/^([ \t]*)(#{m[2]})/ do |mb|
53
53
  pop!
54
54
  token Text, mb[1]
55
55
  token Punctuation, mb[2]
56
56
  end
57
- rule /^.*\n/ do |mb|
57
+ rule %r/^.*\n/ do |mb|
58
58
  delegate sublexer, mb[1]
59
59
  end
60
60
  end
61
61
  end
62
62
  end
63
63
 
64
- rule /\n\n(( |\t).*?\n|\n)+/, Str::Backtick
64
+ rule %r/\n\n(( |\t).*?\n|\n)+/, Str::Backtick
65
65
 
66
- rule /(`+)(?:#{edot}|\n)+?\1/, Str::Backtick
66
+ rule %r/(`+)(?:#{edot}|\n)+?\1/, Str::Backtick
67
67
 
68
68
  # various uses of * are in order of precedence
69
69
 
70
70
  # line breaks
71
- rule /^(\s*[*]){3,}\s*$/, Punctuation
72
- rule /^(\s*[-]){3,}\s*$/, Punctuation
71
+ rule %r/^(\s*[*]){3,}\s*$/, Punctuation
72
+ rule %r/^(\s*[-]){3,}\s*$/, Punctuation
73
73
 
74
74
  # bulleted lists
75
- rule /^\s*[*+-](?=\s)/, Punctuation
75
+ rule %r/^\s*[*+-](?=\s)/, Punctuation
76
76
 
77
77
  # numbered lists
78
- rule /^\s*\d+\./, Punctuation
78
+ rule %r/^\s*\d+\./, Punctuation
79
79
 
80
80
  # blockquotes
81
- rule /^\s*>.*?$/, Generic::Traceback
81
+ rule %r/^\s*>.*?$/, Generic::Traceback
82
82
 
83
83
  # link references
84
84
  # [foo]: bar "baz"
@@ -94,77 +94,77 @@ module Rouge
94
94
  end
95
95
 
96
96
  # links and images
97
- rule /(!?\[)(#{edot}*?)(\])/ do
97
+ rule %r/(!?\[)(#{edot}*?)(\])/ do
98
98
  groups Punctuation, Name::Variable, Punctuation
99
99
  push :link
100
100
  end
101
101
 
102
- rule /[*][*]#{edot}*?[*][*]/, Generic::Strong
103
- rule /__#{edot}*?__/, Generic::Strong
102
+ rule %r/[*][*]#{edot}*?[*][*]/, Generic::Strong
103
+ rule %r/__#{edot}*?__/, Generic::Strong
104
104
 
105
- rule /[*]#{edot}*?[*]/, Generic::Emph
106
- rule /_#{edot}*?_/, Generic::Emph
105
+ rule %r/[*]#{edot}*?[*]/, Generic::Emph
106
+ rule %r/_#{edot}*?_/, Generic::Emph
107
107
 
108
108
  # Automatic links
109
- rule /<.*?@.+[.].+>/, Name::Variable
109
+ rule %r/<.*?@.+[.].+>/, Name::Variable
110
110
  rule %r[<(https?|mailto|ftp)://#{edot}*?>], Name::Variable
111
111
 
112
112
 
113
- rule /[^\\`\[*\n&<]+/, Text
113
+ rule %r/[^\\`\[*\n&<]+/, Text
114
114
 
115
115
  # inline html
116
116
  rule(/&\S*;/) { delegate html }
117
117
  rule(/<#{edot}*?>/) { delegate html }
118
- rule /[&<]/, Text
118
+ rule %r/[&<]/, Text
119
119
 
120
- rule /\n/, Text
120
+ rule %r/\n/, Text
121
121
  end
122
122
 
123
123
  state :link do
124
- rule /(\[)(#{edot}*?)(\])/ do
124
+ rule %r/(\[)(#{edot}*?)(\])/ do
125
125
  groups Punctuation, Str::Symbol, Punctuation
126
126
  pop!
127
127
  end
128
128
 
129
- rule /[(]/ do
129
+ rule %r/[(]/ do
130
130
  token Punctuation
131
131
  push :inline_title
132
132
  push :inline_url
133
133
  end
134
134
 
135
- rule /[ \t]+/, Text
135
+ rule %r/[ \t]+/, Text
136
136
 
137
137
  rule(//) { pop! }
138
138
  end
139
139
 
140
140
  state :url do
141
- rule /[ \t]+/, Text
141
+ rule %r/[ \t]+/, Text
142
142
 
143
143
  # the url
144
- rule /(<)(#{edot}*?)(>)/ do
144
+ rule %r/(<)(#{edot}*?)(>)/ do
145
145
  groups Name::Tag, Str::Other, Name::Tag
146
146
  pop!
147
147
  end
148
148
 
149
- rule /\S+/, Str::Other, :pop!
149
+ rule %r/\S+/, Str::Other, :pop!
150
150
  end
151
151
 
152
152
  state :title do
153
- rule /"#{edot}*?"/, Name::Namespace
154
- rule /'#{edot}*?'/, Name::Namespace
155
- rule /[(]#{edot}*?[)]/, Name::Namespace
156
- rule /\s*(?=["'()])/, Text
153
+ rule %r/"#{edot}*?"/, Name::Namespace
154
+ rule %r/'#{edot}*?'/, Name::Namespace
155
+ rule %r/[(]#{edot}*?[)]/, Name::Namespace
156
+ rule %r/\s*(?=["'()])/, Text
157
157
  rule(//) { pop! }
158
158
  end
159
159
 
160
160
  state :inline_title do
161
- rule /[)]/, Punctuation, :pop!
161
+ rule %r/[)]/, Punctuation, :pop!
162
162
  mixin :title
163
163
  end
164
164
 
165
165
  state :inline_url do
166
- rule /[^<\s)]+/, Str::Other, :pop!
167
- rule /\s+/m, Text
166
+ rule %r/[^<\s)]+/, Str::Other, :pop!
167
+ rule %r/\s+/m, Text
168
168
  mixin :url
169
169
  end
170
170
  end