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
@@ -10,8 +10,6 @@ module Rouge
10
10
  filenames '*.groovy', 'Jenkinsfile'
11
11
  mimetypes 'text/x-groovy'
12
12
 
13
- ws = %r((?:\s|//.*?\n|/[*].*?[*]/)+)
14
-
15
13
  def self.detect?(text)
16
14
  return true if text.shebang?(/groovy/)
17
15
  end
@@ -43,8 +41,8 @@ module Rouge
43
41
 
44
42
  state :root do
45
43
  rule %r(^
46
- (\s*(?:\w[\w\d.\[\]]*\s+)+?) # return arguments
47
- (\w[\w\d]*) # method name
44
+ (\s*(?:\w[\w.\[\]]*\s+)+?) # return arguments
45
+ (\w\w*) # method name
48
46
  (\s*) (\() # signature start
49
47
  )x do |m|
50
48
  delegate self.clone, m[1]
@@ -54,29 +52,29 @@ module Rouge
54
52
  end
55
53
 
56
54
  # whitespace
57
- rule /[^\S\n]+/, Text
55
+ rule %r/[^\S\n]+/, Text
58
56
  rule %r(//.*?$), Comment::Single
59
57
  rule %r(/[*].*?[*]/)m, Comment::Multiline
60
- rule /@\w[\w\d.]*/, Name::Decorator
61
- rule /(class|interface|trait)\b/, Keyword::Declaration, :class
62
- rule /package\b/, Keyword::Namespace, :import
63
- rule /import\b/, Keyword::Namespace, :import
58
+ rule %r/@\w[\w.]*/, Name::Decorator
59
+ rule %r/(class|interface|trait)\b/, Keyword::Declaration, :class
60
+ rule %r/package\b/, Keyword::Namespace, :import
61
+ rule %r/import\b/, Keyword::Namespace, :import
64
62
 
65
63
  # TODO: highlight backslash escapes
66
- rule /""".*?"""/m, Str::Double
67
- rule /'''.*?'''/m, Str::Single
64
+ rule %r/""".*?"""/m, Str::Double
65
+ rule %r/'''.*?'''/m, Str::Single
68
66
 
69
- rule /"(\\.|\\\n|.)*?"/, Str::Double
70
- rule /'(\\.|\\\n|.)*?'/, Str::Single
67
+ rule %r/"(\\.|\\\n|.)*?"/, Str::Double
68
+ rule %r/'(\\.|\\\n|.)*?'/, Str::Single
71
69
  rule %r(\$/(\$.|.)*?/\$)m, Str
72
70
  rule %r(/(\\.|\\\n|.)*?/), Str
73
- rule /'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'/, Str::Char
74
- rule /(\.)([a-zA-Z_][a-zA-Z0-9_]*)/ do
71
+ rule %r/'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'/, Str::Char
72
+ rule %r/(\.)([a-zA-Z_][a-zA-Z0-9_]*)/ do
75
73
  groups Operator, Name::Attribute
76
74
  end
77
75
 
78
- rule /[a-zA-Z_][a-zA-Z0-9_]*:/, Name::Label
79
- rule /[a-zA-Z_\$][a-zA-Z0-9_]*/ do |m|
76
+ rule %r/[a-zA-Z_][a-zA-Z0-9_]*:/, Name::Label
77
+ rule %r/[a-zA-Z_\$][a-zA-Z0-9_]*/ do |m|
80
78
  if self.class.keywords.include? m[0]
81
79
  token Keyword
82
80
  elsif self.class.declarations.include? m[0]
@@ -93,20 +91,20 @@ module Rouge
93
91
  rule %r([~^*!%&\[\](){}<>\|+=:;,./?-]), Operator
94
92
 
95
93
  # numbers
96
- rule /\d+\.\d+([eE]\d+)?[fd]?/, Num::Float
97
- rule /0x[0-9a-f]+/, Num::Hex
98
- rule /[0-9]+L?/, Num::Integer
99
- rule /\n/, Text
94
+ rule %r/\d+\.\d+([eE]\d+)?[fd]?/, Num::Float
95
+ rule %r/0x[0-9a-f]+/, Num::Hex
96
+ rule %r/[0-9]+L?/, Num::Integer
97
+ rule %r/\n/, Text
100
98
  end
101
99
 
102
100
  state :class do
103
- rule /\s+/, Text
104
- rule /\w[\w\d]*/, Name::Class, :pop!
101
+ rule %r/\s+/, Text
102
+ rule %r/\w\w*/, Name::Class, :pop!
105
103
  end
106
104
 
107
105
  state :import do
108
- rule /\s+/, Text
109
- rule /[\w\d.]+[*]?/, Name::Namespace, :pop!
106
+ rule %r/\s+/, Text
107
+ rule %r/[\w.]+[*]?/, Name::Namespace, :pop!
110
108
  end
111
109
  end
112
110
  end
@@ -33,7 +33,7 @@ module Rouge
33
33
  end
34
34
 
35
35
  prepend :template do
36
- rule /<\?hh(\s*\/\/\s*(strict|decl|partial))?$/, Comment::Preproc, :php
36
+ rule %r/<\?hh(\s*\/\/\s*(strict|decl|partial))?$/, Comment::Preproc, :php
37
37
  end
38
38
 
39
39
  prepend :php do
@@ -66,19 +66,15 @@ module Rouge
66
66
  # To accomodate this, use this custom faux dot instead.
67
67
  dot = /[ ]\|\n(?=.*[ ]\|)|./
68
68
 
69
- # In certain places, a comma at the end of the line
70
- # allows line wrapping as well.
71
- comma_dot = /,\s*\n|#{dot}/
72
-
73
69
  state :root do
74
- rule /\s*\n/, Text
70
+ rule %r/\s*\n/, Text
75
71
  rule(/\s*/) { |m| token Text; indentation(m[0]) }
76
72
  end
77
73
 
78
74
  state :content do
79
75
  mixin :css
80
76
  rule(/%#{identifier}/) { token Name::Tag; goto :tag }
81
- rule /!!!#{dot}*\n/, Name::Namespace, :pop!
77
+ rule %r/!!!#{dot}*\n/, Name::Namespace, :pop!
82
78
  rule %r(
83
79
  (/) (\[#{dot}*?\]) (#{dot}*\n)
84
80
  )x do
@@ -92,20 +88,20 @@ module Rouge
92
88
  starts_block :html_comment_block
93
89
  end
94
90
 
95
- rule /-##{dot}*\n/ do
91
+ rule %r/-##{dot}*\n/ do
96
92
  token Comment
97
93
  pop!
98
94
  starts_block :haml_comment_block
99
95
  end
100
96
 
101
- rule /-/ do
97
+ rule %r/-/ do
102
98
  token Punctuation
103
99
  reset_stack
104
100
  ruby! :ruby_line
105
101
  end
106
102
 
107
103
  # filters
108
- rule /:(#{dot}*)\n/ do |m|
104
+ rule %r/:(#{dot}*)\n/ do |m|
109
105
  token Name::Decorator
110
106
  pop!
111
107
  starts_block :filter_block
@@ -131,11 +127,11 @@ module Rouge
131
127
  rule(/[{]/) { token Punctuation; ruby! :ruby_tag }
132
128
  rule(/\[#{dot}*?\]/) { delegate ruby }
133
129
 
134
- rule /\(/, Punctuation, :html_attributes
135
- rule /\s*\n/, Text, :pop!
130
+ rule %r/\(/, Punctuation, :html_attributes
131
+ rule %r/\s*\n/, Text, :pop!
136
132
 
137
133
  # whitespace chompers
138
- rule /[<>]{1,2}(?=[ \t=])/, Punctuation
134
+ rule %r/[<>]{1,2}(?=[ \t=])/, Punctuation
139
135
 
140
136
  mixin :eval_or_plain
141
137
  end
@@ -147,8 +143,8 @@ module Rouge
147
143
  end
148
144
 
149
145
  state :eval_or_plain do
150
- rule /[&!]?==/, Punctuation, :plain
151
- rule /[&!]?[=!]/ do
146
+ rule %r/[&!]?==/, Punctuation, :plain
147
+ rule %r/[&!]?[=!]/ do
152
148
  token Punctuation
153
149
  reset_stack
154
150
  ruby! :ruby_line
@@ -158,9 +154,9 @@ module Rouge
158
154
  end
159
155
 
160
156
  state :ruby_line do
161
- rule /\n/, Text, :pop!
157
+ rule %r/\n/, Text, :pop!
162
158
  rule(/,[ \t]*\n/) { delegate ruby }
163
- rule /[ ]\|[ \t]*\n/, Str::Escape
159
+ rule %r/[ ]\|[ \t]*\n/, Str::Escape
164
160
  rule(/.*?(?=(,$| \|)?[ \t]*$)/) { delegate ruby }
165
161
  end
166
162
 
@@ -169,33 +165,33 @@ module Rouge
169
165
  end
170
166
 
171
167
  state :html_attributes do
172
- rule /\s+/, Text
173
- rule /#{identifier}\s*=/, Name::Attribute, :html_attribute_value
168
+ rule %r/\s+/, Text
169
+ rule %r/#{identifier}\s*=/, Name::Attribute, :html_attribute_value
174
170
  rule identifier, Name::Attribute
175
- rule /\)/, Text, :pop!
171
+ rule %r/\)/, Text, :pop!
176
172
  end
177
173
 
178
174
  state :html_attribute_value do
179
- rule /\s+/, Text
175
+ rule %r/\s+/, Text
180
176
  rule ruby_var, Name::Variable, :pop!
181
- rule /@#{ruby_var}/, Name::Variable::Instance, :pop!
182
- rule /\$#{ruby_var}/, Name::Variable::Global, :pop!
183
- rule /'(\\\\|\\'|[^'\n])*'/, Str, :pop!
184
- rule /"(\\\\|\\"|[^"\n])*"/, Str, :pop!
177
+ rule %r/@#{ruby_var}/, Name::Variable::Instance, :pop!
178
+ rule %r/\$#{ruby_var}/, Name::Variable::Global, :pop!
179
+ rule %r/'(\\\\|\\'|[^'\n])*'/, Str, :pop!
180
+ rule %r/"(\\\\|\\"|[^"\n])*"/, Str, :pop!
185
181
  end
186
182
 
187
183
  state :html_comment_block do
188
- rule /#{dot}+/, Comment
184
+ rule %r/#{dot}+/, Comment
189
185
  mixin :indented_block
190
186
  end
191
187
 
192
188
  state :haml_comment_block do
193
- rule /#{dot}+/, Comment::Preproc
189
+ rule %r/#{dot}+/, Comment::Preproc
194
190
  mixin :indented_block
195
191
  end
196
192
 
197
193
  state :filter_block do
198
- rule /([^#\n]|#[^{\n]|(\\\\)*\\#\{)+/ do
194
+ rule %r/([^#\n]|#[^{\n]|(\\\\)*\\#\{)+/ do
199
195
  if @filter_lexer
200
196
  delegate @filter_lexer
201
197
  else
@@ -208,11 +204,11 @@ module Rouge
208
204
  end
209
205
 
210
206
  state :interpolation do
211
- rule /#[{]/, Str::Interpol, :ruby
207
+ rule %r/#[{]/, Str::Interpol, :ruby
212
208
  end
213
209
 
214
210
  state :ruby do
215
- rule /[}]/, Str::Interpol, :pop!
211
+ rule %r/[}]/, Str::Interpol, :pop!
216
212
  mixin :ruby_inner
217
213
  end
218
214
 
@@ -18,10 +18,10 @@ module Rouge
18
18
  rule(/\\{+/) { delegate parent }
19
19
 
20
20
  # block comments
21
- rule /{{!--/, Comment, :comment
22
- rule /{{!.*?}}/, Comment
21
+ rule %r/{{!--/, Comment, :comment
22
+ rule %r/{{!.*?}}/, Comment
23
23
 
24
- rule /{{{?/ do
24
+ rule %r/{{{?/ do
25
25
  token Keyword
26
26
  push :stache
27
27
  push :open_sym
@@ -42,20 +42,20 @@ module Rouge
42
42
  end
43
43
 
44
44
  state :stache do
45
- rule /}}}?/, Keyword, :pop!
46
- rule /\s+/m, Text
47
- rule /[=]/, Operator
48
- rule /[\[\]]/, Punctuation
49
- rule /[.](?=[}\s])/, Name::Variable
50
- rule /[.][.]/, Name::Variable
45
+ rule %r/}}}?/, Keyword, :pop!
46
+ rule %r/\s+/m, Text
47
+ rule %r/[=]/, Operator
48
+ rule %r/[\[\]]/, Punctuation
49
+ rule %r/[.](?=[}\s])/, Name::Variable
50
+ rule %r/[.][.]/, Name::Variable
51
51
  rule %r([/.]), Punctuation
52
- rule /"(\\.|.)*?"/, Str::Double
53
- rule /'(\\.|.)*?'/, Str::Single
54
- rule /\d+(?=}\s)/, Num
55
- rule /(true|false)(?=[}\s])/, Keyword::Constant
56
- rule /else(?=[}\s])/, Keyword
57
- rule /this(?=[}\s])/, Name::Builtin::Pseudo
58
- rule /@#{id}/, Name::Attribute
52
+ rule %r/"(\\.|.)*?"/, Str::Double
53
+ rule %r/'(\\.|.)*?'/, Str::Single
54
+ rule %r/\d+(?=}\s)/, Num
55
+ rule %r/(true|false)(?=[}\s])/, Keyword::Constant
56
+ rule %r/else(?=[}\s])/, Keyword
57
+ rule %r/this(?=[}\s])/, Name::Builtin::Pseudo
58
+ rule %r/@#{id}/, Name::Attribute
59
59
  rule id, Name::Variable
60
60
  end
61
61
 
@@ -65,13 +65,13 @@ module Rouge
65
65
  goto :block_name
66
66
  end
67
67
 
68
- rule /[>^&]/, Keyword
68
+ rule %r/[>^&]/, Keyword
69
69
 
70
70
  rule(//) { pop! }
71
71
  end
72
72
 
73
73
  state :block_name do
74
- rule /if(?=[}\s])/, Keyword
74
+ rule %r/if(?=[}\s])/, Keyword
75
75
  rule id, Name::Namespace, :pop!
76
76
  rule(//) { pop! }
77
77
  end
@@ -9,7 +9,7 @@ module Rouge
9
9
 
10
10
  tag 'haskell'
11
11
  aliases 'hs'
12
- filenames '*.hs'
12
+ filenames '*.hs', '*.hs-boot'
13
13
  mimetypes 'text/x-haskell'
14
14
 
15
15
  def self.detect?(text)
@@ -27,40 +27,41 @@ module Rouge
27
27
  )
28
28
 
29
29
  state :basic do
30
- rule /\s+/m, Text
31
- rule /{-#/, Comment::Preproc, :comment_preproc
32
- rule /{-/, Comment::Multiline, :comment
33
- rule /^--\s+\|.*?$/, Comment::Doc
30
+ rule %r/\s+/m, Text
31
+ rule %r/{-#/, Comment::Preproc, :comment_preproc
32
+ rule %r/{-/, Comment::Multiline, :comment
33
+ rule %r/^--\s+\|.*?$/, Comment::Doc
34
34
  # this is complicated in order to support custom symbols
35
35
  # like -->
36
- rule /--(?![!#\$\%&*+.\/<=>?@\^\|_~]).*?$/, Comment::Single
36
+ rule %r/--(?![!#\$\%&*+.\/<=>?@\^\|_~]).*?$/, Comment::Single
37
37
  end
38
38
 
39
39
  # nested commenting
40
40
  state :comment do
41
- rule /-}/, Comment::Multiline, :pop!
42
- rule /{-/, Comment::Multiline, :comment
43
- rule /[^-{}]+/, Comment::Multiline
44
- rule /[-{}]/, Comment::Multiline
41
+ rule %r/-}/, Comment::Multiline, :pop!
42
+ rule %r/{-/, Comment::Multiline, :comment
43
+ rule %r/[^-{}]+/, Comment::Multiline
44
+ rule %r/[-{}]/, Comment::Multiline
45
45
  end
46
46
 
47
47
  state :comment_preproc do
48
- rule /-}/, Comment::Preproc, :pop!
49
- rule /{-/, Comment::Preproc, :comment
50
- rule /[^-{}]+/, Comment::Preproc
51
- rule /[-{}]/, Comment::Preproc
48
+ rule %r/-}/, Comment::Preproc, :pop!
49
+ rule %r/{-/, Comment::Preproc, :comment
50
+ rule %r/[^-{}]+/, Comment::Preproc
51
+ rule %r/[-{}]/, Comment::Preproc
52
52
  end
53
53
 
54
54
  state :root do
55
55
  mixin :basic
56
56
 
57
- rule /\bimport\b/, Keyword::Reserved, :import
58
- rule /\bmodule\b/, Keyword::Reserved, :module
59
- rule /\b(?:#{reserved.join('|')})\b/, Keyword::Reserved
57
+ rule %r/\bimport\b/, Keyword::Reserved, :import
58
+ rule %r/\bmodule\b/, Keyword::Reserved, :module
59
+ rule %r/\b(?:#{reserved.join('|')})\b/, Keyword::Reserved
60
60
  # not sure why, but ^ doesn't work here
61
- # rule /^[_a-z][\w']*/, Name::Function
62
- rule /[_a-z][\w']*/, Name
63
- rule /[A-Z][\w']*/, Keyword::Type
61
+ # rule %r/^[_a-z][\w']*/, Name::Function
62
+ rule %r/[_a-z][\w']*/, Name
63
+ rule %r/[A-Z][\w']*/, Keyword::Type
64
+ rule %r/'[A-Z]\w+'?/, Keyword::Type # promoted data constructor
64
65
 
65
66
  # lambda operator
66
67
  rule %r(\\(?![:!#\$\%&*+.\\/<=>?@^\|~-]+)), Name::Function
@@ -71,35 +72,35 @@ module Rouge
71
72
  # other operators
72
73
  rule %r([:!#\$\%&*+.\\/<=>?@^\|~-]+), Operator
73
74
 
74
- rule /\d+e[+-]?\d+/i, Num::Float
75
- rule /\d+\.\d+(e[+-]?\d+)?/i, Num::Float
76
- rule /0o[0-7]+/i, Num::Oct
77
- rule /0x[\da-f]+/i, Num::Hex
78
- rule /\d+/, Num::Integer
75
+ rule %r/\d+e[+-]?\d+/i, Num::Float
76
+ rule %r/\d+\.\d+(e[+-]?\d+)?/i, Num::Float
77
+ rule %r/0o[0-7]+/i, Num::Oct
78
+ rule %r/0x[\da-f]+/i, Num::Hex
79
+ rule %r/\d+/, Num::Integer
79
80
 
80
- rule /'/, Str::Char, :character
81
- rule /"/, Str, :string
81
+ rule %r/'/, Str::Char, :character
82
+ rule %r/"/, Str, :string
82
83
 
83
- rule /\[\s*\]/, Keyword::Type
84
- rule /\(\s*\)/, Name::Builtin
84
+ rule %r/\[\s*\]/, Keyword::Type
85
+ rule %r/\(\s*\)/, Name::Builtin
85
86
 
86
87
  # Quasiquotations
87
- rule /(\[)([_a-z][\w']*)(\|)/ do |m|
88
+ rule %r/(\[)([_a-z][\w']*)(\|)/ do |m|
88
89
  token Operator, m[1]
89
90
  token Name, m[2]
90
91
  token Operator, m[3]
91
92
  push :quasiquotation
92
93
  end
93
94
 
94
- rule /[\[\](),;`{}]/, Punctuation
95
+ rule %r/[\[\](),;`{}]/, Punctuation
95
96
  end
96
97
 
97
98
  state :import do
98
- rule /\s+/, Text
99
- rule /"/, Str, :string
100
- rule /\bqualified\b/, Keyword
99
+ rule %r/\s+/, Text
100
+ rule %r/"/, Str, :string
101
+ rule %r/\bqualified\b/, Keyword
101
102
  # import X as Y
102
- rule /([A-Z][\w.]*)(\s+)(as)(\s+)([A-Z][a-zA-Z0-9_.]*)/ do
103
+ rule %r/([A-Z][\w.]*)(\s+)(as)(\s+)([A-Z][a-zA-Z0-9_.]*)/ do
103
104
  groups(
104
105
  Name::Namespace, # X
105
106
  Text, Keyword, # as
@@ -109,7 +110,7 @@ module Rouge
109
110
  end
110
111
 
111
112
  # import X hiding (functions)
112
- rule /([A-Z][\w.]*)(\s+)(hiding)(\s+)(\()/ do
113
+ rule %r/([A-Z][\w.]*)(\s+)(hiding)(\s+)(\()/ do
113
114
  groups(
114
115
  Name::Namespace, # X
115
116
  Text, Keyword, # hiding
@@ -119,7 +120,7 @@ module Rouge
119
120
  end
120
121
 
121
122
  # import X (functions)
122
- rule /([A-Z][\w.]*)(\s+)(\()/ do
123
+ rule %r/([A-Z][\w.]*)(\s+)(\()/ do
123
124
  groups(
124
125
  Name::Namespace, # X
125
126
  Text,
@@ -128,70 +129,70 @@ module Rouge
128
129
  goto :funclist
129
130
  end
130
131
 
131
- rule /[\w.]+/, Name::Namespace, :pop!
132
+ rule %r/[\w.]+/, Name::Namespace, :pop!
132
133
  end
133
134
 
134
135
  state :module do
135
- rule /\s+/, Text
136
+ rule %r/\s+/, Text
136
137
  # module Foo (functions)
137
- rule /([A-Z][\w.]*)(\s+)(\()/ do
138
+ rule %r/([A-Z][\w.]*)(\s+)(\()/ do
138
139
  groups Name::Namespace, Text, Punctuation
139
140
  push :funclist
140
141
  end
141
142
 
142
- rule /\bwhere\b/, Keyword::Reserved, :pop!
143
+ rule %r/\bwhere\b/, Keyword::Reserved, :pop!
143
144
 
144
- rule /[A-Z][a-zA-Z0-9_.]*/, Name::Namespace, :pop!
145
+ rule %r/[A-Z][a-zA-Z0-9_.]*/, Name::Namespace, :pop!
145
146
  end
146
147
 
147
148
  state :funclist do
148
149
  mixin :basic
149
- rule /[A-Z]\w*/, Keyword::Type
150
- rule /(_[\w\']+|[a-z][\w\']*)/, Name::Function
151
- rule /,/, Punctuation
152
- rule /[:!#\$\%&*+.\\\/<=>?@^\|~-]+/, Operator
153
- rule /\(/, Punctuation, :funclist
154
- rule /\)/, Punctuation, :pop!
150
+ rule %r/[A-Z]\w*/, Keyword::Type
151
+ rule %r/(_[\w\']+|[a-z][\w\']*)/, Name::Function
152
+ rule %r/,/, Punctuation
153
+ rule %r/[:!#\$\%&*+.\\\/<=>?@^\|~-]+/, Operator
154
+ rule %r/\(/, Punctuation, :funclist
155
+ rule %r/\)/, Punctuation, :pop!
155
156
  end
156
157
 
157
158
  state :character do
158
- rule /\\/ do
159
+ rule %r/\\/ do
159
160
  token Str::Escape
160
161
  goto :character_end
161
162
  push :escape
162
163
  end
163
164
 
164
- rule /./ do
165
+ rule %r/./ do
165
166
  token Str::Char
166
167
  goto :character_end
167
168
  end
168
169
  end
169
170
 
170
171
  state :character_end do
171
- rule /'/, Str::Char, :pop!
172
- rule /./, Error, :pop!
172
+ rule %r/'/, Str::Char, :pop!
173
+ rule %r/./, Error, :pop!
173
174
  end
174
175
 
175
176
  state :quasiquotation do
176
- rule /\|\]/, Operator, :pop!
177
- rule /[^\|]+/m, Text
178
- rule /\|/, Text
177
+ rule %r/\|\]/, Operator, :pop!
178
+ rule %r/[^\|]+/m, Text
179
+ rule %r/\|/, Text
179
180
  end
180
181
 
181
182
  state :string do
182
- rule /"/, Str, :pop!
183
- rule /\\/, Str::Escape, :escape
184
- rule /[^\\"]+/, Str
183
+ rule %r/"/, Str, :pop!
184
+ rule %r/\\/, Str::Escape, :escape
185
+ rule %r/[^\\"]+/, Str
185
186
  end
186
187
 
187
188
  state :escape do
188
- rule /[abfnrtv"'&\\]/, Str::Escape, :pop!
189
- rule /\^[\]\[A-Z@\^_]/, Str::Escape, :pop!
190
- rule /#{ascii.join('|')}/, Str::Escape, :pop!
191
- rule /o[0-7]+/i, Str::Escape, :pop!
192
- rule /x[\da-f]+/i, Str::Escape, :pop!
193
- rule /\d+/, Str::Escape, :pop!
194
- rule /\s+\\/, Str::Escape, :pop!
189
+ rule %r/[abfnrtv"'&\\]/, Str::Escape, :pop!
190
+ rule %r/\^[\]\[A-Z@\^_]/, Str::Escape, :pop!
191
+ rule %r/#{ascii.join('|')}/, Str::Escape, :pop!
192
+ rule %r/o[0-7]+/i, Str::Escape, :pop!
193
+ rule %r/x[\da-f]+/i, Str::Escape, :pop!
194
+ rule %r/\d+/, Str::Escape, :pop!
195
+ rule %r/\s+\\/, Str::Escape, :pop!
195
196
  end
196
197
  end
197
198
  end