rouge 3.1.0 → 3.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (318) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +17 -3
  3. data/bin/rougify +1 -0
  4. data/lib/rouge.rb +67 -42
  5. data/lib/rouge/cli.rb +87 -18
  6. data/lib/rouge/demos/ada +26 -0
  7. data/lib/rouge/demos/apex +9 -0
  8. data/lib/rouge/demos/armasm +12 -0
  9. data/lib/rouge/demos/batchfile +3 -0
  10. data/lib/rouge/demos/bbcbasic +6 -0
  11. data/lib/rouge/demos/bpf +7 -0
  12. data/lib/rouge/demos/brainfuck +5 -0
  13. data/lib/rouge/demos/clean +6 -0
  14. data/lib/rouge/demos/cmhg +8 -0
  15. data/lib/rouge/demos/crystal +45 -0
  16. data/lib/rouge/demos/csvs +8 -0
  17. data/lib/rouge/demos/cuda +11 -0
  18. data/lib/rouge/demos/cypher +5 -0
  19. data/lib/rouge/demos/cython +6 -0
  20. data/lib/rouge/demos/datastudio +21 -0
  21. data/lib/rouge/demos/ecl +18 -0
  22. data/lib/rouge/demos/eex +1 -0
  23. data/lib/rouge/demos/epp +4 -0
  24. data/lib/rouge/demos/escape +3 -0
  25. data/lib/rouge/demos/freefem +16 -0
  26. data/lib/rouge/demos/gdscript +18 -0
  27. data/lib/rouge/demos/ghc-cmm +23 -0
  28. data/lib/rouge/demos/ghc-core +26 -0
  29. data/lib/rouge/demos/haxe +5 -0
  30. data/lib/rouge/demos/hcl +7 -0
  31. data/lib/rouge/demos/hocon +8 -0
  32. data/lib/rouge/demos/hql +5 -0
  33. data/lib/rouge/demos/isbl +4 -0
  34. data/lib/rouge/demos/jsl +3 -0
  35. data/lib/rouge/demos/jsp +29 -0
  36. data/lib/rouge/demos/liquid +0 -1
  37. data/lib/rouge/demos/lustre +6 -0
  38. data/lib/rouge/demos/lutin +18 -0
  39. data/lib/rouge/demos/m68k +16 -0
  40. data/lib/rouge/demos/magik +6 -0
  41. data/lib/rouge/demos/mason +22 -0
  42. data/lib/rouge/demos/mathematica +8 -0
  43. data/lib/rouge/demos/minizinc +23 -0
  44. data/lib/rouge/demos/msgtrans +4 -0
  45. data/lib/rouge/demos/nasm +6 -6
  46. data/lib/rouge/demos/nesasm +11 -0
  47. data/lib/rouge/demos/objective_cpp +17 -0
  48. data/lib/rouge/demos/openedge +4 -0
  49. data/lib/rouge/demos/opentype_feature_file +6 -0
  50. data/lib/rouge/demos/plist +1 -132
  51. data/lib/rouge/demos/powershell +12 -48
  52. data/lib/rouge/demos/q +6 -0
  53. data/lib/rouge/demos/reasonml +12 -0
  54. data/lib/rouge/demos/rego +8 -0
  55. data/lib/rouge/demos/robot_framework +27 -0
  56. data/lib/rouge/demos/sas +13 -0
  57. data/lib/rouge/demos/slice +10 -0
  58. data/lib/rouge/demos/solidity +13 -0
  59. data/lib/rouge/demos/sparql +6 -0
  60. data/lib/rouge/demos/sqf +14 -0
  61. data/lib/rouge/demos/supercollider +11 -0
  62. data/lib/rouge/demos/terraform +16 -0
  63. data/lib/rouge/demos/ttcn3 +6 -0
  64. data/lib/rouge/demos/vcl +12 -0
  65. data/lib/rouge/demos/xojo +14 -0
  66. data/lib/rouge/demos/xpath +2 -0
  67. data/lib/rouge/demos/xquery +22 -0
  68. data/lib/rouge/demos/yang +17 -0
  69. data/lib/rouge/formatter.rb +39 -2
  70. data/lib/rouge/formatters/html.rb +21 -2
  71. data/lib/rouge/formatters/html_inline.rb +1 -0
  72. data/lib/rouge/formatters/html_legacy.rb +1 -0
  73. data/lib/rouge/formatters/html_line_table.rb +53 -0
  74. data/lib/rouge/formatters/html_linewise.rb +7 -11
  75. data/lib/rouge/formatters/html_pygments.rb +2 -0
  76. data/lib/rouge/formatters/html_table.rb +21 -31
  77. data/lib/rouge/formatters/null.rb +1 -0
  78. data/lib/rouge/formatters/terminal256.rb +23 -5
  79. data/lib/rouge/formatters/terminal_truecolor.rb +37 -0
  80. data/lib/rouge/formatters/tex.rb +92 -0
  81. data/lib/rouge/guesser.rb +2 -0
  82. data/lib/rouge/guessers/disambiguation.rb +35 -0
  83. data/lib/rouge/guessers/filename.rb +2 -0
  84. data/lib/rouge/guessers/glob_mapping.rb +3 -1
  85. data/lib/rouge/guessers/mimetype.rb +2 -0
  86. data/lib/rouge/guessers/modeline.rb +3 -1
  87. data/lib/rouge/guessers/source.rb +3 -1
  88. data/lib/rouge/guessers/util.rb +2 -0
  89. data/lib/rouge/lexer.rb +71 -15
  90. data/lib/rouge/lexers/abap.rb +13 -11
  91. data/lib/rouge/lexers/actionscript.rb +35 -34
  92. data/lib/rouge/lexers/ada.rb +162 -0
  93. data/lib/rouge/lexers/apache.rb +13 -15
  94. data/lib/rouge/lexers/apache/keywords.rb +15 -0
  95. data/lib/rouge/lexers/apex.rb +126 -0
  96. data/lib/rouge/lexers/apiblueprint.rb +2 -0
  97. data/lib/rouge/lexers/apple_script.rb +17 -14
  98. data/lib/rouge/lexers/armasm.rb +145 -0
  99. data/lib/rouge/lexers/awk.rb +26 -25
  100. data/lib/rouge/lexers/batchfile.rb +164 -0
  101. data/lib/rouge/lexers/bbcbasic.rb +112 -0
  102. data/lib/rouge/lexers/biml.rb +6 -4
  103. data/lib/rouge/lexers/bpf.rb +118 -0
  104. data/lib/rouge/lexers/brainfuck.rb +53 -0
  105. data/lib/rouge/lexers/bsl.rb +13 -12
  106. data/lib/rouge/lexers/c.rb +35 -57
  107. data/lib/rouge/lexers/ceylon.rb +7 -34
  108. data/lib/rouge/lexers/cfscript.rb +27 -26
  109. data/lib/rouge/lexers/clean.rb +156 -0
  110. data/lib/rouge/lexers/clojure.rb +15 -14
  111. data/lib/rouge/lexers/cmake.rb +16 -14
  112. data/lib/rouge/lexers/cmhg.rb +34 -0
  113. data/lib/rouge/lexers/coffeescript.rb +90 -49
  114. data/lib/rouge/lexers/common_lisp.rb +39 -38
  115. data/lib/rouge/lexers/conf.rb +7 -6
  116. data/lib/rouge/lexers/console.rb +92 -38
  117. data/lib/rouge/lexers/coq.rb +27 -23
  118. data/lib/rouge/lexers/cpp.rb +24 -13
  119. data/lib/rouge/lexers/crystal.rb +430 -0
  120. data/lib/rouge/lexers/csharp.rb +29 -29
  121. data/lib/rouge/lexers/css.rb +24 -23
  122. data/lib/rouge/lexers/csvs.rb +44 -0
  123. data/lib/rouge/lexers/cuda.rb +35 -0
  124. data/lib/rouge/lexers/cypher.rb +108 -0
  125. data/lib/rouge/lexers/cython.rb +151 -0
  126. data/lib/rouge/lexers/d.rb +64 -63
  127. data/lib/rouge/lexers/dart.rb +34 -33
  128. data/lib/rouge/lexers/datastudio.rb +138 -0
  129. data/lib/rouge/lexers/diff.rb +10 -4
  130. data/lib/rouge/lexers/digdag.rb +3 -1
  131. data/lib/rouge/lexers/docker.rb +12 -11
  132. data/lib/rouge/lexers/dot.rb +19 -18
  133. data/lib/rouge/lexers/ecl.rb +175 -0
  134. data/lib/rouge/lexers/eex.rb +52 -0
  135. data/lib/rouge/lexers/eiffel.rb +21 -20
  136. data/lib/rouge/lexers/elixir.rb +52 -36
  137. data/lib/rouge/lexers/elm.rb +30 -29
  138. data/lib/rouge/lexers/epp.rb +51 -0
  139. data/lib/rouge/lexers/erb.rb +5 -4
  140. data/lib/rouge/lexers/erlang.rb +1 -0
  141. data/lib/rouge/lexers/escape.rb +58 -0
  142. data/lib/rouge/lexers/factor.rb +41 -40
  143. data/lib/rouge/lexers/fortran.rb +36 -34
  144. data/lib/rouge/lexers/freefem.rb +240 -0
  145. data/lib/rouge/lexers/fsharp.rb +33 -31
  146. data/lib/rouge/lexers/gdscript.rb +171 -0
  147. data/lib/rouge/lexers/ghc_cmm.rb +340 -0
  148. data/lib/rouge/lexers/ghc_core.rb +151 -0
  149. data/lib/rouge/lexers/gherkin.rb +17 -14
  150. data/lib/rouge/lexers/gherkin/keywords.rb +2 -0
  151. data/lib/rouge/lexers/glsl.rb +2 -5
  152. data/lib/rouge/lexers/go.rb +3 -2
  153. data/lib/rouge/lexers/gradle.rb +1 -0
  154. data/lib/rouge/lexers/graphql.rb +78 -60
  155. data/lib/rouge/lexers/groovy.rb +24 -25
  156. data/lib/rouge/lexers/hack.rb +2 -1
  157. data/lib/rouge/lexers/haml.rb +26 -29
  158. data/lib/rouge/lexers/handlebars.rb +32 -20
  159. data/lib/rouge/lexers/haskell.rb +78 -61
  160. data/lib/rouge/lexers/haxe.rb +246 -0
  161. data/lib/rouge/lexers/hcl.rb +163 -0
  162. data/lib/rouge/lexers/hocon.rb +86 -0
  163. data/lib/rouge/lexers/hql.rb +139 -0
  164. data/lib/rouge/lexers/html.rb +36 -33
  165. data/lib/rouge/lexers/http.rb +10 -9
  166. data/lib/rouge/lexers/hylang.rb +15 -14
  167. data/lib/rouge/lexers/idlang.rb +34 -32
  168. data/lib/rouge/lexers/igorpro.rb +481 -225
  169. data/lib/rouge/lexers/ini.rb +13 -12
  170. data/lib/rouge/lexers/io.rb +10 -9
  171. data/lib/rouge/lexers/irb.rb +6 -5
  172. data/lib/rouge/lexers/isbl.rb +97 -0
  173. data/lib/rouge/lexers/isbl/builtins.rb +17 -0
  174. data/lib/rouge/lexers/java.rb +30 -26
  175. data/lib/rouge/lexers/javascript.rb +59 -61
  176. data/lib/rouge/lexers/jinja.rb +39 -22
  177. data/lib/rouge/lexers/jsl.rb +55 -0
  178. data/lib/rouge/lexers/json.rb +54 -11
  179. data/lib/rouge/lexers/json_doc.rb +8 -5
  180. data/lib/rouge/lexers/jsonnet.rb +19 -18
  181. data/lib/rouge/lexers/jsp.rb +120 -0
  182. data/lib/rouge/lexers/jsx.rb +18 -16
  183. data/lib/rouge/lexers/julia.rb +192 -74
  184. data/lib/rouge/lexers/kotlin.rb +79 -27
  185. data/lib/rouge/lexers/lasso.rb +54 -58
  186. data/lib/rouge/lexers/lasso/keywords.rb +14 -0
  187. data/lib/rouge/lexers/liquid.rb +116 -118
  188. data/lib/rouge/lexers/literate_coffeescript.rb +3 -2
  189. data/lib/rouge/lexers/literate_haskell.rb +6 -5
  190. data/lib/rouge/lexers/llvm.rb +66 -49
  191. data/lib/rouge/lexers/lua.rb +43 -4
  192. data/lib/rouge/lexers/lua/builtins.rb +2 -0
  193. data/lib/rouge/lexers/lustre.rb +79 -0
  194. data/lib/rouge/lexers/lutin.rb +33 -0
  195. data/lib/rouge/lexers/m68k.rb +143 -0
  196. data/lib/rouge/lexers/magik.rb +127 -0
  197. data/lib/rouge/lexers/make.rb +57 -34
  198. data/lib/rouge/lexers/markdown.rb +67 -39
  199. data/lib/rouge/lexers/mason.rb +110 -0
  200. data/lib/rouge/lexers/mathematica.rb +96 -0
  201. data/lib/rouge/lexers/mathematica/builtins.rb +13 -0
  202. data/lib/rouge/lexers/matlab.rb +26 -17
  203. data/lib/rouge/lexers/matlab/builtins.rb +4 -4
  204. data/lib/rouge/lexers/minizinc.rb +87 -0
  205. data/lib/rouge/lexers/moonscript.rb +4 -3
  206. data/lib/rouge/lexers/mosel.rb +64 -63
  207. data/lib/rouge/lexers/msgtrans.rb +26 -0
  208. data/lib/rouge/lexers/mxml.rb +19 -18
  209. data/lib/rouge/lexers/nasm.rb +43 -169
  210. data/lib/rouge/lexers/nesasm.rb +78 -0
  211. data/lib/rouge/lexers/nginx.rb +15 -14
  212. data/lib/rouge/lexers/nim.rb +4 -2
  213. data/lib/rouge/lexers/nix.rb +48 -42
  214. data/lib/rouge/lexers/objective_c.rb +5 -178
  215. data/lib/rouge/lexers/objective_c/common.rb +184 -0
  216. data/lib/rouge/lexers/objective_cpp.rb +31 -0
  217. data/lib/rouge/lexers/ocaml.rb +29 -64
  218. data/lib/rouge/lexers/ocaml/common.rb +53 -0
  219. data/lib/rouge/lexers/openedge.rb +429 -0
  220. data/lib/rouge/lexers/opentype_feature_file.rb +113 -0
  221. data/lib/rouge/lexers/pascal.rb +6 -5
  222. data/lib/rouge/lexers/perl.rb +103 -68
  223. data/lib/rouge/lexers/php.rb +91 -53
  224. data/lib/rouge/lexers/php/builtins.rb +183 -174
  225. data/lib/rouge/lexers/plain_text.rb +2 -1
  226. data/lib/rouge/lexers/plist.rb +16 -14
  227. data/lib/rouge/lexers/pony.rb +21 -20
  228. data/lib/rouge/lexers/powershell.rb +190 -638
  229. data/lib/rouge/lexers/praat.rb +76 -75
  230. data/lib/rouge/lexers/prolog.rb +27 -19
  231. data/lib/rouge/lexers/prometheus.rb +32 -30
  232. data/lib/rouge/lexers/properties.rb +13 -12
  233. data/lib/rouge/lexers/protobuf.rb +23 -22
  234. data/lib/rouge/lexers/puppet.rb +33 -32
  235. data/lib/rouge/lexers/python.rb +124 -99
  236. data/lib/rouge/lexers/q.rb +17 -14
  237. data/lib/rouge/lexers/qml.rb +13 -12
  238. data/lib/rouge/lexers/r.rb +13 -13
  239. data/lib/rouge/lexers/racket.rb +47 -22
  240. data/lib/rouge/lexers/reasonml.rb +65 -0
  241. data/lib/rouge/lexers/rego.rb +45 -0
  242. data/lib/rouge/lexers/robot_framework.rb +249 -0
  243. data/lib/rouge/lexers/ruby.rb +88 -71
  244. data/lib/rouge/lexers/rust.rb +45 -44
  245. data/lib/rouge/lexers/sas.rb +563 -0
  246. data/lib/rouge/lexers/sass.rb +9 -8
  247. data/lib/rouge/lexers/sass/common.rb +41 -40
  248. data/lib/rouge/lexers/scala.rb +67 -40
  249. data/lib/rouge/lexers/scheme.rb +19 -18
  250. data/lib/rouge/lexers/scss.rb +4 -3
  251. data/lib/rouge/lexers/sed.rb +31 -30
  252. data/lib/rouge/lexers/shell.rb +67 -55
  253. data/lib/rouge/lexers/sieve.rb +10 -9
  254. data/lib/rouge/lexers/slice.rb +32 -0
  255. data/lib/rouge/lexers/slim.rb +27 -26
  256. data/lib/rouge/lexers/smalltalk.rb +34 -33
  257. data/lib/rouge/lexers/smarty.rb +20 -19
  258. data/lib/rouge/lexers/sml.rb +68 -67
  259. data/lib/rouge/lexers/solidity.rb +185 -0
  260. data/lib/rouge/lexers/sparql.rb +129 -0
  261. data/lib/rouge/lexers/sqf.rb +109 -0
  262. data/lib/rouge/lexers/sqf/commands.rb +15 -0
  263. data/lib/rouge/lexers/sql.rb +47 -26
  264. data/lib/rouge/lexers/supercollider.rb +116 -0
  265. data/lib/rouge/lexers/swift.rb +50 -45
  266. data/lib/rouge/lexers/tap.rb +22 -20
  267. data/lib/rouge/lexers/tcl.rb +28 -27
  268. data/lib/rouge/lexers/terraform.rb +128 -0
  269. data/lib/rouge/lexers/tex.rb +20 -19
  270. data/lib/rouge/lexers/toml.rb +59 -20
  271. data/lib/rouge/lexers/tsx.rb +1 -0
  272. data/lib/rouge/lexers/ttcn3.rb +119 -0
  273. data/lib/rouge/lexers/tulip.rb +38 -36
  274. data/lib/rouge/lexers/turtle.rb +36 -38
  275. data/lib/rouge/lexers/twig.rb +1 -0
  276. data/lib/rouge/lexers/typescript.rb +12 -0
  277. data/lib/rouge/lexers/typescript/common.rb +1 -0
  278. data/lib/rouge/lexers/vala.rb +19 -18
  279. data/lib/rouge/lexers/varnish.rb +168 -0
  280. data/lib/rouge/lexers/vb.rb +28 -27
  281. data/lib/rouge/lexers/verilog.rb +27 -28
  282. data/lib/rouge/lexers/vhdl.rb +13 -12
  283. data/lib/rouge/lexers/viml.rb +15 -14
  284. data/lib/rouge/lexers/viml/keywords.rb +2 -0
  285. data/lib/rouge/lexers/vue.rb +19 -12
  286. data/lib/rouge/lexers/wollok.rb +27 -26
  287. data/lib/rouge/lexers/xml.rb +18 -21
  288. data/lib/rouge/lexers/xojo.rb +61 -0
  289. data/lib/rouge/lexers/xpath.rb +332 -0
  290. data/lib/rouge/lexers/xquery.rb +145 -0
  291. data/lib/rouge/lexers/yaml.rb +64 -61
  292. data/lib/rouge/lexers/yang.rb +147 -0
  293. data/lib/rouge/plugins/redcarpet.rb +9 -2
  294. data/lib/rouge/regex_lexer.rb +27 -25
  295. data/lib/rouge/template_lexer.rb +1 -0
  296. data/lib/rouge/tex_theme_renderer.rb +132 -0
  297. data/lib/rouge/text_analyzer.rb +1 -0
  298. data/lib/rouge/theme.rb +5 -0
  299. data/lib/rouge/themes/base16.rb +1 -0
  300. data/lib/rouge/themes/bw.rb +41 -0
  301. data/lib/rouge/themes/colorful.rb +1 -0
  302. data/lib/rouge/themes/github.rb +1 -0
  303. data/lib/rouge/themes/gruvbox.rb +1 -0
  304. data/lib/rouge/themes/igor_pro.rb +1 -0
  305. data/lib/rouge/themes/magritte.rb +78 -0
  306. data/lib/rouge/themes/molokai.rb +1 -0
  307. data/lib/rouge/themes/monokai.rb +1 -0
  308. data/lib/rouge/themes/monokai_sublime.rb +4 -1
  309. data/lib/rouge/themes/pastie.rb +2 -1
  310. data/lib/rouge/themes/thankful_eyes.rb +2 -1
  311. data/lib/rouge/themes/tulip.rb +2 -1
  312. data/lib/rouge/token.rb +31 -22
  313. data/lib/rouge/util.rb +3 -2
  314. data/lib/rouge/version.rb +2 -1
  315. data/rouge.gemspec +6 -3
  316. metadata +136 -8
  317. data/lib/rouge/lexers/apache/keywords.yml +0 -764
  318. data/lib/rouge/lexers/lasso/keywords.yml +0 -446
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
2
3
 
3
4
  module Rouge
4
5
  module Lexers
@@ -9,7 +10,8 @@ module Rouge
9
10
  aliases 'rb'
10
11
  filenames '*.rb', '*.ruby', '*.rbw', '*.rake', '*.gemspec', '*.podspec',
11
12
  'Rakefile', 'Guardfile', 'Gemfile', 'Capfile', 'Podfile',
12
- 'Vagrantfile', '*.ru', '*.prawn', 'Berksfile', '*.arb'
13
+ 'Vagrantfile', '*.ru', '*.prawn', 'Berksfile', '*.arb',
14
+ 'Dangerfile', 'Fastfile', 'Deliverfile', 'Appfile'
13
15
 
14
16
  mimetypes 'text/x-ruby', 'application/x-ruby'
15
17
 
@@ -29,15 +31,15 @@ module Rouge
29
31
  rule %r(:(?:\*\*|[-+]@|[/\%&\|^`~]|\[\]=?|<<|>>|<=?>|<=?|===?)),
30
32
  Str::Symbol
31
33
 
32
- rule /:'(\\\\|\\'|[^'])*'/, Str::Symbol
33
- rule /:"/, Str::Symbol, :simple_sym
34
+ rule %r/:'(\\\\|\\'|[^'])*'/, Str::Symbol
35
+ rule %r/:"/, Str::Symbol, :simple_sym
34
36
  end
35
37
 
36
38
  state :sigil_strings do
37
39
  # %-sigiled strings
38
40
  # %(abc), %[abc], %<abc>, %.abc., %r.abc., etc
39
41
  delimiter_map = { '{' => '}', '[' => ']', '(' => ')', '<' => '>' }
40
- rule /%([rqswQWxiI])?([^\w\s])/ do |m|
42
+ rule %r/%([rqswQWxiI])?([^\w\s])/ do |m|
41
43
  open = Regexp.escape(m[2])
42
44
  close = Regexp.escape(delimiter_map[m[2]] || m[2])
43
45
  interp = /[rQWxI]/ === m[1]
@@ -55,38 +57,40 @@ module Rouge
55
57
  token toktype
56
58
 
57
59
  push do
58
- rule /\\[##{open}#{close}\\]/, Str::Escape
60
+ uniq_chars = "#{open}#{close}".squeeze
61
+ uniq_chars = '' if open == close && open == "\\#"
62
+ rule %r/\\[##{uniq_chars}\\]/, Str::Escape
59
63
  # nesting rules only with asymmetric delimiters
60
64
  if open != close
61
- rule /#{open}/ do
65
+ rule %r/#{open}/ do
62
66
  token toktype
63
67
  push
64
68
  end
65
69
  end
66
- rule /#{close}/, toktype, :pop!
70
+ rule %r/#{close}/, toktype, :pop!
67
71
 
68
72
  if interp
69
73
  mixin :string_intp_escaped
70
- rule /#/, toktype
74
+ rule %r/#/, toktype
71
75
  else
72
- rule /[\\#]/, toktype
76
+ rule %r/[\\#]/, toktype
73
77
  end
74
78
 
75
- rule /[^##{open}#{close}\\]+/m, toktype
79
+ rule %r/[^##{uniq_chars}\\]+/m, toktype
76
80
  end
77
81
  end
78
82
  end
79
83
 
80
84
  state :strings do
81
85
  mixin :symbols
82
- rule /\b[a-z_]\w*?[?!]?:\s+/, Str::Symbol, :expr_start
83
- rule /'(\\\\|\\'|[^'])*'/, Str::Single
84
- rule /"/, Str::Double, :simple_string
85
- rule /(?<!\.)`/, Str::Backtick, :simple_backtick
86
+ rule %r/\b[a-z_]\w*?[?!]?:\s+/, Str::Symbol, :expr_start
87
+ rule %r/'(\\\\|\\'|[^'])*'/, Str::Single
88
+ rule %r/"/, Str::Double, :simple_string
89
+ rule %r/(?<!\.)`/, Str::Backtick, :simple_backtick
86
90
  end
87
91
 
88
92
  state :regex_flags do
89
- rule /[mixounse]*/, Str::Regex, :pop!
93
+ rule %r/[mixounse]*/, Str::Regex, :pop!
90
94
  end
91
95
 
92
96
  # double-quoted string and symbol
@@ -95,9 +99,9 @@ module Rouge
95
99
  [:backtick, Str::Backtick, '`']].each do |name, tok, fin|
96
100
  state :"simple_#{name}" do
97
101
  mixin :string_intp_escaped
98
- rule /[^\\#{fin}#]+/m, tok
99
- rule /[\\#]/, tok
100
- rule /#{fin}/, tok, :pop!
102
+ rule %r/[^\\#{fin}#]+/m, tok
103
+ rule %r/[\\#]/, tok
104
+ rule %r/#{fin}/, tok, :pop!
101
105
  end
102
106
  end
103
107
 
@@ -149,38 +153,41 @@ module Rouge
149
153
 
150
154
  state :whitespace do
151
155
  mixin :inline_whitespace
152
- rule /\n\s*/m, Text, :expr_start
153
- rule /#.*$/, Comment::Single
156
+ rule %r/\n\s*/m, Text, :expr_start
157
+ rule %r/#.*$/, Comment::Single
154
158
 
155
159
  rule %r(=begin\b.*?\n=end\b)m, Comment::Multiline
156
160
  end
157
161
 
158
162
  state :inline_whitespace do
159
- rule /[ \t\r]+/, Text
163
+ rule %r/[ \t\r]+/, Text
160
164
  end
161
165
 
162
166
  state :root do
163
167
  mixin :whitespace
164
- rule /__END__/, Comment::Preproc, :end_part
168
+ rule %r/__END__/, Comment::Preproc, :end_part
165
169
 
166
- rule /0_?[0-7]+(?:_[0-7]+)*/, Num::Oct
167
- rule /0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*/, Num::Hex
168
- rule /0b[01]+(?:_[01]+)*/, Num::Bin
169
- rule /\d+\.\d+(e[\+\-]?\d+)?/, Num::Float
170
- rule /[\d]+(?:_\d+)*/, Num::Integer
170
+ rule %r/0_?[0-7]+(?:_[0-7]+)*/, Num::Oct
171
+ rule %r/0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*/, Num::Hex
172
+ rule %r/0b[01]+(?:_[01]+)*/, Num::Bin
173
+
174
+ decimal = %r/[\d]+(?:_\d+)*/
175
+ exp = %r/e[+-]?\d+/i
176
+ rule %r/#{decimal}(?:\.#{decimal}#{exp}?|#{exp})/, Num::Float
177
+ rule decimal, Num::Integer
171
178
 
172
179
  # names
173
- rule /@@[a-z_]\w*/i, Name::Variable::Class
174
- rule /@[a-z_]\w*/i, Name::Variable::Instance
175
- rule /\$\w+/, Name::Variable::Global
180
+ rule %r/@@[a-z_]\w*/i, Name::Variable::Class
181
+ rule %r/@[a-z_]\w*/i, Name::Variable::Instance
182
+ rule %r/\$\w+/, Name::Variable::Global
176
183
  rule %r(\$[!@&`'+~=/\\,;.<>_*\$?:"]), Name::Variable::Global
177
- rule /\$-[0adFiIlpvw]/, Name::Variable::Global
178
- rule /::/, Operator
184
+ rule %r/\$-[0adFiIlpvw]/, Name::Variable::Global
185
+ rule %r/::/, Operator
179
186
 
180
187
  mixin :strings
181
188
 
182
- rule /(?:#{keywords.join('|')})\b/, Keyword, :expr_start
183
- rule /(?:#{keywords_pseudo.join('|')})\b/, Keyword::Pseudo, :expr_start
189
+ rule %r/(?:#{keywords.join('|')})(?=\W|$)/, Keyword, :expr_start
190
+ rule %r/(?:#{keywords_pseudo.join('|')})\b/, Keyword::Pseudo, :expr_start
184
191
 
185
192
  rule %r(
186
193
  (module)
@@ -190,52 +197,52 @@ module Rouge
190
197
  groups Keyword, Text, Name::Namespace
191
198
  end
192
199
 
193
- rule /(def\b)(\s*)/ do
200
+ rule %r/(def\b)(\s*)/ do
194
201
  groups Keyword, Text
195
202
  push :funcname
196
203
  end
197
204
 
198
- rule /(class\b)(\s*)/ do
205
+ rule %r/(class\b)(\s*)/ do
199
206
  groups Keyword, Text
200
207
  push :classname
201
208
  end
202
209
 
203
- rule /(?:#{builtins_q.join('|')})[?]/, Name::Builtin, :expr_start
204
- rule /(?:#{builtins_b.join('|')})!/, Name::Builtin, :expr_start
205
- rule /(?<!\.)(?:#{builtins_g.join('|')})\b/,
210
+ rule %r/(?:#{builtins_q.join('|')})[?]/, Name::Builtin, :expr_start
211
+ rule %r/(?:#{builtins_b.join('|')})!/, Name::Builtin, :expr_start
212
+ rule %r/(?<!\.)(?:#{builtins_g.join('|')})\b/,
206
213
  Name::Builtin, :method_call
207
214
 
208
215
  mixin :has_heredocs
209
216
 
210
217
  # `..` and `...` for ranges must have higher priority than `.`
211
218
  # Otherwise, they will be parsed as :method_call
212
- rule /\.{2,3}/, Operator, :expr_start
219
+ rule %r/\.{2,3}/, Operator, :expr_start
213
220
 
214
- rule /[A-Z][a-zA-Z0-9_]*/, Name::Constant, :method_call
215
- rule /(\.|::)(\s*)([a-z_]\w*[!?]?|[*%&^`~+-\/\[<>=])/ do
221
+ rule %r/[A-Z][a-zA-Z0-9_]*/, Name::Constant, :method_call
222
+ rule %r/(\.|::)(\s*)([a-z_]\w*[!?]?|[*%&^`~+-\/\[<>=])/ do
216
223
  groups Punctuation, Text, Name::Function
217
224
  push :method_call
218
225
  end
219
226
 
220
- rule /[a-zA-Z_]\w*[?!]/, Name, :expr_start
221
- rule /[a-zA-Z_]\w*/, Name, :method_call
222
- rule /\*\*|<<?|>>?|>=|<=|<=>|=~|={3}|!~|&&?|\|\||\./,
227
+ rule %r/[a-zA-Z_]\w*[?!]/, Name, :expr_start
228
+ rule %r/[a-zA-Z_]\w*/, Name, :method_call
229
+ rule %r/\*\*|<<?|>>?|>=|<=|<=>|=~|={3}|!~|&&?|\|\||\./,
223
230
  Operator, :expr_start
224
- rule /[-+\/*%=<>&!^|~]=?/, Operator, :expr_start
231
+ rule %r/[-+\/*%=<>&!^|~]=?/, Operator, :expr_start
225
232
  rule(/[?]/) { token Punctuation; push :ternary; push :expr_start }
226
233
  rule %r<[\[({,:\\;/]>, Punctuation, :expr_start
227
234
  rule %r<[\])}]>, Punctuation
228
235
  end
229
236
 
230
237
  state :has_heredocs do
231
- rule /(?<!\w)(<<[-~]?)(["`']?)([a-zA-Z_]\w*)(\2)/ do |m|
238
+ rule %r/(?<!\w)(<<[-~]?)(["`']?)([a-zA-Z_]\w*)(\2)/ do |m|
232
239
  token Operator, m[1]
233
240
  token Name::Constant, "#{m[2]}#{m[3]}#{m[4]}"
234
241
  @heredoc_queue << [['<<-', '<<~'].include?(m[1]), m[3]]
235
242
  push :heredoc_queue unless state? :heredoc_queue
236
243
  end
237
244
 
238
- rule /(<<[-~]?)(["'])(\2)/ do |m|
245
+ rule %r/(<<[-~]?)(["'])(\2)/ do |m|
239
246
  token Operator, m[1]
240
247
  token Name::Constant, "#{m[2]}#{m[3]}#{m[4]}"
241
248
  @heredoc_queue << [['<<-', '<<~'].include?(m[1]), '']
@@ -244,7 +251,7 @@ module Rouge
244
251
  end
245
252
 
246
253
  state :heredoc_queue do
247
- rule /(?=\n)/ do
254
+ rule %r/(?=\n)/ do
248
255
  goto :resolve_heredocs
249
256
  end
250
257
 
@@ -254,13 +261,13 @@ module Rouge
254
261
  state :resolve_heredocs do
255
262
  mixin :string_intp_escaped
256
263
 
257
- rule /\n/, Str::Heredoc, :test_heredoc
258
- rule /[#\\\n]/, Str::Heredoc
259
- rule /[^#\\\n]+/, Str::Heredoc
264
+ rule %r/\n/, Str::Heredoc, :test_heredoc
265
+ rule %r/[#\\\n]/, Str::Heredoc
266
+ rule %r/[^#\\\n]+/, Str::Heredoc
260
267
  end
261
268
 
262
269
  state :test_heredoc do
263
- rule /[^#\\\n]*$/ do |m|
270
+ rule %r/[^#\\\n]*$/ do |m|
264
271
  tolerant, heredoc_name = @heredoc_queue.first
265
272
  check = tolerant ? m[0].strip : m[0].rstrip
266
273
 
@@ -282,12 +289,12 @@ module Rouge
282
289
  end
283
290
 
284
291
  state :funcname do
285
- rule /\s+/, Text
286
- rule /\(/, Punctuation, :defexpr
292
+ rule %r/\s+/, Text
293
+ rule %r/\(/, Punctuation, :defexpr
287
294
  rule %r(
288
- (?:([a-zA-Z_][\w_]*)(\.))?
295
+ (?:([a-zA-Z_]\w*)(\.))?
289
296
  (
290
- [a-zA-Z_][\w_]*[!?]? |
297
+ [a-zA-Z_]\w*[!?]? |
291
298
  \*\*? | [-+]@? | [/%&\|^`~] | \[\]=? |
292
299
  <<? | >>? | <=>? | >= | ===?
293
300
  )
@@ -301,36 +308,46 @@ module Rouge
301
308
  end
302
309
 
303
310
  state :classname do
304
- rule /\s+/, Text
305
- rule /\(/ do
311
+ rule %r/\s+/, Text
312
+ rule %r/\w+(::\w+)+/, Name::Class
313
+
314
+ rule %r/\(/ do
306
315
  token Punctuation
307
316
  push :defexpr
308
317
  push :expr_start
309
318
  end
310
319
 
311
320
  # class << expr
312
- rule /<</ do
321
+ rule %r/<</ do
313
322
  token Operator
314
323
  goto :expr_start
315
324
  end
316
325
 
317
- rule /[A-Z_]\w*/, Name::Class, :pop!
326
+ rule %r/[A-Z_]\w*/, Name::Class, :pop!
318
327
 
319
328
  rule(//) { pop! }
320
329
  end
321
330
 
322
331
  state :ternary do
323
- rule(/:(?!:)/) { token Punctuation; goto :expr_start }
332
+ rule %r/(:)(\s+)/ do
333
+ groups Punctuation, Text
334
+ goto :expr_start
335
+ end
336
+
337
+ rule %r/:(?![^#\n]*?[:\\])/ do
338
+ token Punctuation
339
+ goto :expr_start
340
+ end
324
341
 
325
342
  mixin :root
326
343
  end
327
344
 
328
345
  state :defexpr do
329
- rule /(\))(\.|::)?/ do
346
+ rule %r/(\))(\.|::)?/ do
330
347
  groups Punctuation, Operator
331
348
  pop!
332
349
  end
333
- rule /\(/ do
350
+ rule %r/\(/ do
334
351
  token Punctuation
335
352
  push :defexpr
336
353
  push :expr_start
@@ -340,20 +357,20 @@ module Rouge
340
357
  end
341
358
 
342
359
  state :in_interp do
343
- rule /}/, Str::Interpol, :pop!
360
+ rule %r/}/, Str::Interpol, :pop!
344
361
  mixin :root
345
362
  end
346
363
 
347
364
  state :string_intp do
348
- rule /[#][{]/, Str::Interpol, :in_interp
349
- rule /#(@@?|\$)[a-z_]\w*/i, Str::Interpol
365
+ rule %r/[#][{]/, Str::Interpol, :in_interp
366
+ rule %r/#(@@?|\$)[a-z_]\w*/i, Str::Interpol
350
367
  end
351
368
 
352
369
  state :string_intp_escaped do
353
370
  mixin :string_intp
354
- rule /\\([\\abefnrstv#"']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})/,
371
+ rule %r/\\([\\abefnrstv#"']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})/,
355
372
  Str::Escape
356
- rule /\\./, Str::Escape
373
+ rule %r/\\./, Str::Escape
357
374
  end
358
375
 
359
376
  state :method_call do
@@ -406,7 +423,7 @@ module Rouge
406
423
 
407
424
  # special case for using a single space. Ruby demands that
408
425
  # these be in a single line, otherwise it would make no sense.
409
- rule /(\s*)(%[rqswQWxiI]? \S* )/ do
426
+ rule %r/(\s*)(%[rqswQWxiI]? \S* )/ do
410
427
  groups Text, Str::Other
411
428
  pop!
412
429
  end
@@ -430,7 +447,7 @@ module Rouge
430
447
 
431
448
  state :end_part do
432
449
  # eat up the rest of the stream as Comment::Preproc
433
- rule /.+/m, Comment::Preproc, :pop!
450
+ rule %r/.+/m, Comment::Preproc, :pop!
434
451
  end
435
452
  end
436
453
  end
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
2
3
 
3
4
  module Rouge
4
5
  module Lexers
@@ -6,7 +7,12 @@ module Rouge
6
7
  title "Rust"
7
8
  desc 'The Rust programming language (rust-lang.org)'
8
9
  tag 'rust'
9
- aliases 'rs'
10
+ aliases 'rs',
11
+ # So that directives from https://github.com/budziq/rust-skeptic
12
+ # do not prevent highlighting.
13
+ 'rust,no_run', 'rs,no_run',
14
+ 'rust,ignore', 'rs,ignore',
15
+ 'rust,should_panic', 'rs,should_panic'
10
16
  filenames '*.rs'
11
17
  mimetypes 'text/x-rust'
12
18
 
@@ -16,7 +22,7 @@ module Rouge
16
22
 
17
23
  def self.keywords
18
24
  @keywords ||= %w(
19
- as assert break const copy do drop else enum extern fail false
25
+ as assert async await break const copy do drop else enum extern fail false
20
26
  fn for if impl let log loop match mod move mut priv pub pure
21
27
  ref return self static struct true trait type unsafe use where
22
28
  while box
@@ -43,6 +49,7 @@ module Rouge
43
49
 
44
50
  start {
45
51
  @macro_delims = { ']' => 0, ')' => 0, '}' => 0 }
52
+ push :bol
46
53
  }
47
54
 
48
55
  delim_map = { '[' => ']', '(' => ')', '{' => '}' }
@@ -50,57 +57,59 @@ module Rouge
50
57
  id = /[a-z_]\w*/i
51
58
  hex = /[0-9a-f]/i
52
59
  escapes = %r(
53
- \\ ([nrt'\\] | x#{hex}{2} | u#{hex}{4} | U#{hex}{8})
60
+ \\ ([nrt'"\\0] | x#{hex}{2} | u#{hex}{4} | U#{hex}{8})
54
61
  )x
55
62
  size = /8|16|32|64/
56
63
 
57
- state :start_line do
64
+ # Although not officially part of Rust, the rustdoc tool allows code in
65
+ # comments to begin with `#`. Code like this will be evaluated but not
66
+ # included in the HTML output produced by rustdoc. So that code intended
67
+ # for these comments can be higlighted with Rouge, the Rust lexer needs
68
+ # to check if the beginning of the line begins with a `# `.
69
+ state :bol do
58
70
  mixin :whitespace
59
- rule /\s+/, Text
60
- rule /#\[/ do
61
- token Name::Decorator; push :attribute
62
- end
71
+ rule %r/#\s[^\n]*/, Comment::Special
63
72
  rule(//) { pop! }
64
- rule /#\s[^\n]*/, Comment::Preproc
65
73
  end
66
74
 
67
75
  state :attribute do
68
76
  mixin :whitespace
69
77
  mixin :has_literals
70
- rule /[(,)=]/, Name::Decorator
71
- rule /\]/, Name::Decorator, :pop!
78
+ rule %r/[(,)=:]/, Name::Decorator
79
+ rule %r/\]/, Name::Decorator, :pop!
72
80
  rule id, Name::Decorator
73
81
  end
74
82
 
75
83
  state :whitespace do
76
- rule /\s+/, Text
84
+ rule %r/\s+/, Text
77
85
  rule %r(//[^\n]*), Comment
78
86
  rule %r(/[*].*?[*]/)m, Comment::Multiline
79
87
  end
80
88
 
81
89
  state :root do
82
- rule /\n/, Text, :start_line
90
+ rule %r/\n/, Text, :bol
83
91
  mixin :whitespace
84
- rule /\b(?:#{Rust.keywords.join('|')})\b/, Keyword
92
+ rule %r/#!?\[/, Name::Decorator, :attribute
93
+ rule %r/\b(?:#{Rust.keywords.join('|')})\b/, Keyword
85
94
  mixin :has_literals
86
95
 
87
96
  rule %r([=-]>), Keyword
88
97
  rule %r(<->), Keyword
89
- rule /[()\[\]{}|,:;]/, Punctuation
90
- rule /[*!@~&+%^<>=-\?]|\.{2,3}/, Operator
98
+ rule %r/[()\[\]{}|,:;]/, Punctuation
99
+ rule %r/[*\/!@~&+%^<>=\?-]|\.{2,3}/, Operator
91
100
 
92
- rule /([.]\s*)?#{id}(?=\s*[(])/m, Name::Function
93
- rule /[.]\s*#{id}/, Name::Property
94
- rule /(#{id})(::)/m do
101
+ rule %r/([.]\s*)?#{id}(?=\s*[(])/m, Name::Function
102
+ rule %r/[.]\s*#{id}/, Name::Property
103
+ rule %r/(#{id})(::)/m do
95
104
  groups Name::Namespace, Punctuation
96
105
  end
97
106
 
98
107
  # macros
99
- rule /\bmacro_rules!/, Name::Decorator, :macro_rules
100
- rule /#{id}!/, Name::Decorator, :macro
108
+ rule %r/\bmacro_rules!/, Name::Decorator, :macro_rules
109
+ rule %r/#{id}!/, Name::Decorator, :macro
101
110
 
102
- rule /'#{id}/, Name::Variable
103
- rule /#{id}/ do |m|
111
+ rule %r/'#{id}/, Name::Variable
112
+ rule %r/#{id}/ do |m|
104
113
  name = m[0]
105
114
  if self.class.builtins.include? name
106
115
  token Name::Builtin
@@ -113,13 +122,13 @@ module Rouge
113
122
  state :macro do
114
123
  mixin :has_literals
115
124
 
116
- rule /[\[{(]/ do |m|
125
+ rule %r/[\[{(]/ do |m|
117
126
  @macro_delims[delim_map[m[0]]] += 1
118
127
  puts " macro_delims: #{@macro_delims.inspect}" if @debug
119
128
  token Punctuation
120
129
  end
121
130
 
122
- rule /[\]})]/ do |m|
131
+ rule %r/[\]})]/ do |m|
123
132
  @macro_delims[m[0]] -= 1
124
133
  puts " macro_delims: #{@macro_delims.inspect}" if @debug
125
134
  pop! if macro_closed?
@@ -127,29 +136,30 @@ module Rouge
127
136
  end
128
137
 
129
138
  # same as the rule in root, but don't push another macro state
130
- rule /#{id}!/, Name::Decorator
139
+ rule %r/#{id}!/, Name::Decorator
131
140
  mixin :root
132
141
 
133
142
  # No syntax errors in macros
134
- rule /./, Text
143
+ rule %r/./, Text
135
144
  end
136
145
 
137
146
  state :macro_rules do
138
- rule /[$]#{id}(:#{id})?/, Name::Variable
139
- rule /[$]/, Name::Variable
147
+ rule %r/[$]#{id}(:#{id})?/, Name::Variable
148
+ rule %r/[$]/, Name::Variable
140
149
 
141
150
  mixin :macro
142
151
  end
143
152
 
144
153
  state :has_literals do
145
154
  # constants
146
- rule /\b(?:true|false|nil)\b/, Keyword::Constant
155
+ rule %r/\b(?:true|false|nil)\b/, Keyword::Constant
147
156
  # characters
148
157
  rule %r(
149
158
  ' (?: #{escapes} | [^\\] ) '
150
159
  )x, Str::Char
151
160
 
152
- rule /"/, Str, :string
161
+ rule %r/"/, Str, :string
162
+ rule %r/r(#*)".*?"\1/m, Str
153
163
 
154
164
  # numbers
155
165
  dot = /[.][0-9_]+/
@@ -166,26 +176,17 @@ module Rouge
166
176
 
167
177
  rule %r(
168
178
  ( 0b[10_]+
169
- | 0x[0-9a-fA-F-]+
170
- | [0-9]+
179
+ | 0x[0-9a-fA-F_]+
180
+ | [0-9_]+
171
181
  ) (u#{size}?|i#{size})?
172
182
  )x, Num::Integer
173
183
 
174
184
  end
175
185
 
176
186
  state :string do
177
- rule /"/, Str, :pop!
187
+ rule %r/"/, Str, :pop!
178
188
  rule escapes, Str::Escape
179
- rule /%%/, Str::Interpol
180
- rule %r(
181
- %
182
- ( [0-9]+ [$] )? # Parameter
183
- [0#+-]* # Flag
184
- ( [0-9]+ [$]? )? # Width
185
- ( [.] [0-9]+ )? # Precision
186
- [bcdfiostuxX?] # Type
187
- )x, Str::Interpol
188
- rule /[^%"\\]+/m, Str
189
+ rule %r/[^"\\]+/m, Str
189
190
  end
190
191
  end
191
192
  end