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
@@ -26,21 +26,21 @@ module Rouge
26
26
  mixin :strings
27
27
  mixin :whitespace
28
28
 
29
- rule /-?\d+\.\d+/, Num::Float
30
- rule /-?\d+[smhdwy]?/, Num::Integer
29
+ rule %r/-?\d+\.\d+/, Num::Float
30
+ rule %r/-?\d+[smhdwy]?/, Num::Integer
31
31
 
32
32
  mixin :operators
33
33
 
34
- rule /(ignoring|on)(\()/ do
34
+ rule %r/(ignoring|on)(\()/ do
35
35
  groups Keyword::Pseudo, Punctuation
36
36
  push :label_list
37
37
  end
38
- rule /(group_left|group_right)(\()/ do
38
+ rule %r/(group_left|group_right)(\()/ do
39
39
  groups Keyword::Type, Punctuation
40
40
  end
41
- rule /(bool|offset)\b/, Keyword
42
- rule /(without|by)\b/, Keyword, :label_list
43
- rule /[\w:]+/ do |m|
41
+ rule %r/(bool|offset)\b/, Keyword
42
+ rule %r/(without|by)\b/, Keyword, :label_list
43
+ rule %r/[\w:]+/ do |m|
44
44
  if self.class.functions.include?(m[0])
45
45
  token Name::Builtin
46
46
  else
@@ -52,17 +52,17 @@ module Rouge
52
52
  end
53
53
 
54
54
  state :metrics do
55
- rule /[a-zA-Z0-9_-]+/, Name
55
+ rule %r/[a-zA-Z0-9_-]+/, Name
56
56
 
57
- rule /[\(\)\]:.,]/, Punctuation
58
- rule /\{/, Punctuation, :filters
59
- rule /\[/, Punctuation
57
+ rule %r/[\(\)\]:.,]/, Punctuation
58
+ rule %r/\{/, Punctuation, :filters
59
+ rule %r/\[/, Punctuation
60
60
  end
61
61
 
62
62
  state :strings do
63
- rule /"/, Str::Double, :double_string_escaped
64
- rule /'/, Str::Single, :single_string_escaped
65
- rule /`.*`/, Str::Backtick
63
+ rule %r/"/, Str::Double, :double_string_escaped
64
+ rule %r/'/, Str::Single, :single_string_escaped
65
+ rule %r/`.*`/, Str::Backtick
66
66
  end
67
67
 
68
68
  [
@@ -70,52 +70,52 @@ module Rouge
70
70
  [:single, Str::Single, "'"]
71
71
  ].each do |name, tok, fin|
72
72
  state :"#{name}_string_escaped" do
73
- rule /\\[\\abfnrtv#{fin}]/, Str::Escape
74
- rule /[^\\#{fin}]+/m, tok
75
- rule /#{fin}/, tok, :pop!
73
+ rule %r/\\[\\abfnrtv#{fin}]/, Str::Escape
74
+ rule %r/[^\\#{fin}]+/m, tok
75
+ rule %r/#{fin}/, tok, :pop!
76
76
  end
77
77
  end
78
78
 
79
79
  state :filters do
80
80
  mixin :inline_whitespace
81
- rule /,/, Punctuation
81
+ rule %r/,/, Punctuation
82
82
  mixin :labels
83
83
  mixin :filter_matching_operators
84
84
  mixin :strings
85
- rule /}/, Punctuation, :pop!
85
+ rule %r/}/, Punctuation, :pop!
86
86
  end
87
87
 
88
88
  state :label_list do
89
- rule /\(/, Punctuation
90
- rule /[a-zA-Z0-9_:-]+/, Name::Attribute
91
- rule /,/, Punctuation
89
+ rule %r/\(/, Punctuation
90
+ rule %r/[a-zA-Z0-9_:-]+/, Name::Attribute
91
+ rule %r/,/, Punctuation
92
92
  mixin :whitespace
93
- rule /\)/, Punctuation, :pop!
93
+ rule %r/\)/, Punctuation, :pop!
94
94
  end
95
95
 
96
96
  state :labels do
97
- rule /[a-zA-Z0-9_:-]+/, Name::Attribute
97
+ rule %r/[a-zA-Z0-9_:-]+/, Name::Attribute
98
98
  end
99
99
 
100
100
  state :operators do
101
101
  rule %r([+\-\*/%\^]), Operator # Arithmetic
102
102
  rule %r(=|==|!=|<|>|<=|>=), Operator # Comparison
103
- rule /and|or|unless/, Operator # Logical/Set
104
- rule /(sum|min|max|avg|stddev|stdvar|count|count_values|bottomk|topk)\b/, Name::Function
103
+ rule %r/and|or|unless/, Operator # Logical/Set
104
+ rule %r/(sum|min|max|avg|stddev|stdvar|count|count_values|bottomk|topk)\b/, Name::Function
105
105
  end
106
106
 
107
107
  state :filter_matching_operators do
108
- rule /!(=|~)|=~?/, Operator
108
+ rule %r/!(=|~)|=~?/, Operator
109
109
  end
110
110
 
111
111
  state :inline_whitespace do
112
- rule /[ \t\r]+/, Text
112
+ rule %r/[ \t\r]+/, Text
113
113
  end
114
114
 
115
115
  state :whitespace do
116
116
  mixin :inline_whitespace
117
- rule /\n\s*/m, Text
118
- rule /#.*?$/, Comment
117
+ rule %r/\n\s*/m, Text
118
+ rule %r/#.*?$/, Comment
119
119
  end
120
120
  end
121
121
  end
@@ -14,38 +14,38 @@ module Rouge
14
14
  identifier = /[\w.-]+/
15
15
 
16
16
  state :basic do
17
- rule /[!#].*?\n/, Comment
18
- rule /\s+/, Text
19
- rule /\\\n/, Str::Escape
17
+ rule %r/[!#].*?\n/, Comment
18
+ rule %r/\s+/, Text
19
+ rule %r/\\\n/, Str::Escape
20
20
  end
21
21
 
22
22
  state :root do
23
23
  mixin :basic
24
24
 
25
- rule /(#{identifier})(\s*)([=:])/ do
25
+ rule %r/(#{identifier})(\s*)([=:])/ do
26
26
  groups Name::Property, Text, Punctuation
27
27
  push :value
28
28
  end
29
29
  end
30
30
 
31
31
  state :value do
32
- rule /\n/, Text, :pop!
32
+ rule %r/\n/, Text, :pop!
33
33
  mixin :basic
34
- rule /"/, Str, :dq
35
- rule /'.*?'/, Str
34
+ rule %r/"/, Str, :dq
35
+ rule %r/'.*?'/, Str
36
36
  mixin :esc_str
37
- rule /[^\\\n]+/, Str
37
+ rule %r/[^\\\n]+/, Str
38
38
  end
39
39
 
40
40
  state :dq do
41
- rule /"/, Str, :pop!
41
+ rule %r/"/, Str, :pop!
42
42
  mixin :esc_str
43
- rule /[^\\"]+/m, Str
43
+ rule %r/[^\\"]+/m, Str
44
44
  end
45
45
 
46
46
  state :esc_str do
47
- rule /\\u[0-9]{4}/, Str::Escape
48
- rule /\\./m, Str::Escape
47
+ rule %r/\\u[0-9]{4}/, Str::Escape
48
+ rule %r/\\./m, Str::Escape
49
49
  end
50
50
  end
51
51
  end
@@ -15,55 +15,55 @@ module Rouge
15
15
  datatype = /\b(bool|bytes|double|fixed32|fixed64|float|int32|int64|sfixed32|sfixed64|sint32|sint64|string|uint32|uint64)\b/
16
16
 
17
17
  state :root do
18
- rule /[\s]+/, Text
19
- rule /[,;{}\[\]()]/, Punctuation
20
- rule /\/(\\\n)?\/(\n|(.|\n)*?[^\\]\n)/, Comment::Single
21
- rule /\/(\\\n)?\*(.|\n)*?\*(\\\n)?\//, Comment::Multiline
18
+ rule %r/[\s]+/, Text
19
+ rule %r/[,;{}\[\]()]/, Punctuation
20
+ rule %r/\/(\\\n)?\/(\n|(.|\n)*?[^\\]\n)/, Comment::Single
21
+ rule %r/\/(\\\n)?\*(.|\n)*?\*(\\\n)?\//, Comment::Multiline
22
22
  rule kw, Keyword
23
23
  rule datatype, Keyword::Type
24
- rule /true|false/, Keyword::Constant
25
- rule /(package)(\s+)/ do
24
+ rule %r/true|false/, Keyword::Constant
25
+ rule %r/(package)(\s+)/ do
26
26
  groups Keyword::Namespace, Text
27
27
  push :package
28
28
  end
29
29
 
30
- rule /(message|extend)(\s+)/ do
30
+ rule %r/(message|extend)(\s+)/ do
31
31
  groups Keyword::Declaration, Text
32
32
  push :message
33
33
  end
34
34
 
35
- rule /(enum|group|service)(\s+)/ do
35
+ rule %r/(enum|group|service)(\s+)/ do
36
36
  groups Keyword::Declaration, Text
37
37
  push :type
38
38
  end
39
39
 
40
- rule /".*?"/, Str
41
- rule /'.*?'/, Str
42
- rule /(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*/, Num::Float
43
- rule /(\d+\.\d*|\.\d+|\d+[fF])[fF]?/, Num::Float
44
- rule /(\-?(inf|nan))\b/, Num::Float
45
- rule /0x[0-9a-fA-F]+[LlUu]*/, Num::Hex
46
- rule /0[0-7]+[LlUu]*/, Num::Oct
47
- rule /\d+[LlUu]*/, Num::Integer
48
- rule /[+-=]/, Operator
49
- rule /([a-zA-Z_][\w.]*)([ \t]*)(=)/ do
40
+ rule %r/".*?"/, Str
41
+ rule %r/'.*?'/, Str
42
+ rule %r/(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*/, Num::Float
43
+ rule %r/(\d+\.\d*|\.\d+|\d+[fF])[fF]?/, Num::Float
44
+ rule %r/(\-?(inf|nan))\b/, Num::Float
45
+ rule %r/0x[0-9a-fA-F]+[LlUu]*/, Num::Hex
46
+ rule %r/0[0-7]+[LlUu]*/, Num::Oct
47
+ rule %r/\d+[LlUu]*/, Num::Integer
48
+ rule %r/[+-=]/, Operator
49
+ rule %r/([a-zA-Z_][\w.]*)([ \t]*)(=)/ do
50
50
  groups Name::Attribute, Text, Operator
51
51
  end
52
- rule /[a-zA-Z_][\w.]*/, Name
52
+ rule %r/[a-zA-Z_][\w.]*/, Name
53
53
  end
54
54
 
55
55
  state :package do
56
- rule /[a-zA-Z_]\w*/, Name::Namespace, :pop!
56
+ rule %r/[a-zA-Z_]\w*/, Name::Namespace, :pop!
57
57
  rule(//) { pop! }
58
58
  end
59
59
 
60
60
  state :message do
61
- rule /[a-zA-Z_]\w*/, Name::Class, :pop!
61
+ rule %r/[a-zA-Z_]\w*/, Name::Class, :pop!
62
62
  rule(//) { pop! }
63
63
  end
64
64
 
65
65
  state :type do
66
- rule /[a-zA-Z_]\w*/, Name, :pop!
66
+ rule %r/[a-zA-Z_]\w*/, Name, :pop!
67
67
  rule(//) { pop! }
68
68
  end
69
69
  end
@@ -39,15 +39,15 @@ module Rouge
39
39
  qualname = /(::)?(#{id}::)*\w+/
40
40
 
41
41
  state :whitespace do
42
- rule /\s+/m, Text
43
- rule /#.*?\n/, Comment
42
+ rule %r/\s+/m, Text
43
+ rule %r/#.*?\n/, Comment
44
44
  end
45
45
 
46
46
  state :root do
47
47
  mixin :whitespace
48
48
 
49
- rule /[$]#{qualname}/, Name::Variable
50
- rule /(#{id})(?=\s*[=+]>)/m do |m|
49
+ rule %r/[$]#{qualname}/, Name::Variable
50
+ rule %r/(#{id})(?=\s*[=+]>)/m do |m|
51
51
  if self.class.metaparameters.include? m[0]
52
52
  token Keyword::Pseudo
53
53
  else
@@ -55,31 +55,31 @@ module Rouge
55
55
  end
56
56
  end
57
57
 
58
- rule /(#{qualname})(?=\s*[(])/m, Name::Function
58
+ rule %r/(#{qualname})(?=\s*[(])/m, Name::Function
59
59
  rule cap_id, Name::Class
60
60
 
61
- rule /[+=|~-]>|<[|~-]/, Punctuation
62
- rule /[:}();\[\]]/, Punctuation
61
+ rule %r/[+=|~-]>|<[|~-]/, Punctuation
62
+ rule %r/[:}();\[\]]/, Punctuation
63
63
 
64
64
  # HACK for case statements and selectors
65
- rule /{/, Punctuation, :regex_allowed
66
- rule /,/, Punctuation, :regex_allowed
65
+ rule %r/{/, Punctuation, :regex_allowed
66
+ rule %r/,/, Punctuation, :regex_allowed
67
67
 
68
- rule /(in|and|or)\b/, Operator::Word
69
- rule /[=!<>]=/, Operator
70
- rule /[=!]~/, Operator, :regex_allowed
68
+ rule %r/(in|and|or)\b/, Operator::Word
69
+ rule %r/[=!<>]=/, Operator
70
+ rule %r/[=!]~/, Operator, :regex_allowed
71
71
  rule %r([=<>!+*/-]), Operator
72
72
 
73
- rule /(class|include)(\s*)(#{qualname})/ do
73
+ rule %r/(class|include)(\s*)(#{qualname})/ do
74
74
  groups Keyword, Text, Name::Class
75
75
  end
76
76
 
77
- rule /node\b/, Keyword, :regex_allowed
77
+ rule %r/node\b/, Keyword, :regex_allowed
78
78
 
79
- rule /'(\\[\\']|[^'])*'/m, Str::Single
80
- rule /"/, Str::Double, :dquotes
79
+ rule %r/'(\\[\\']|[^'])*'/m, Str::Single
80
+ rule %r/"/, Str::Double, :dquotes
81
81
 
82
- rule /\d+([.]\d+)?(e[+-]\d+)?/, Num
82
+ rule %r/\d+([.]\d+)?(e[+-]\d+)?/, Num
83
83
 
84
84
  # a valid regex. TODO: regexes are only allowed
85
85
  # in certain places in puppet.
@@ -103,26 +103,26 @@ module Rouge
103
103
 
104
104
  state :regex do
105
105
  rule %r(/), Str::Regex, :pop!
106
- rule /\\./, Str::Escape
107
- rule /[(){}]/, Str::Interpol
108
- rule /\[/, Str::Interpol, :regex_class
109
- rule /./, Str::Regex
106
+ rule %r/\\./, Str::Escape
107
+ rule %r/[(){}]/, Str::Interpol
108
+ rule %r/\[/, Str::Interpol, :regex_class
109
+ rule %r/./, Str::Regex
110
110
  end
111
111
 
112
112
  state :regex_class do
113
- rule /\]/, Str::Interpol, :pop!
114
- rule /(?<!\[)-(?=\])/, Str::Regex
115
- rule /-/, Str::Interpol
116
- rule /\\./, Str::Escape
117
- rule /[^\\\]-]+/, Str::Regex
113
+ rule %r/\]/, Str::Interpol, :pop!
114
+ rule %r/(?<!\[)-(?=\])/, Str::Regex
115
+ rule %r/-/, Str::Interpol
116
+ rule %r/\\./, Str::Escape
117
+ rule %r/[^\\\]-]+/, Str::Regex
118
118
  end
119
119
 
120
120
  state :dquotes do
121
- rule /"/, Str::Double, :pop!
122
- rule /[^$\\"]+/m, Str::Double
123
- rule /\\./m, Str::Escape
124
- rule /[$]#{qualname}/, Name::Variable
125
- rule /[$][{]#{qualname}[}]/, Name::Variable
121
+ rule %r/"/, Str::Double, :pop!
122
+ rule %r/[^$\\"]+/m, Str::Double
123
+ rule %r/\\./m, Str::Escape
124
+ rule %r/[$]#{qualname}/, Name::Variable
125
+ rule %r/[$][{]#{qualname}[}]/, Name::Variable
126
126
  end
127
127
  end
128
128
  end
@@ -12,7 +12,7 @@ module Rouge
12
12
  mimetypes 'text/x-python', 'application/x-python'
13
13
 
14
14
  def self.detect?(text)
15
- return true if text.shebang?(/pythonw?(3|2(\.\d)?)?/)
15
+ return true if text.shebang?(/pythonw?(?:[23](?:\.\d+)?)?/)
16
16
  end
17
17
 
18
18
  def self.keywords
@@ -69,23 +69,23 @@ module Rouge
69
69
  identifier = /[a-z_][a-z0-9_]*/i
70
70
  dotted_identifier = /[a-z_.][a-z0-9_.]*/i
71
71
  state :root do
72
- rule /\n+/m, Text
73
- rule /^(:)(\s*)([ru]{,2}""".*?""")/mi do
72
+ rule %r/\n+/m, Text
73
+ rule %r/^(:)(\s*)([ru]{,2}""".*?""")/mi do
74
74
  groups Punctuation, Text, Str::Doc
75
75
  end
76
76
 
77
- rule /[^\S\n]+/, Text
77
+ rule %r/[^\S\n]+/, Text
78
78
  rule %r(#(.*)?\n?), Comment::Single
79
- rule /[\[\]{}:(),;]/, Punctuation
80
- rule /\\\n/, Text
81
- rule /\\/, Text
79
+ rule %r/[\[\]{}:(),;]/, Punctuation
80
+ rule %r/\\\n/, Text
81
+ rule %r/\\/, Text
82
82
 
83
- rule /(in|is|and|or|not)\b/, Operator::Word
84
- rule /(<<|>>|\/\/|\*\*)=?/, Operator
85
- rule /[-~+\/*%=<>&^|@]=?|!=/, Operator
86
- rule /\.(?![0-9])/, Operator # so it doesn't match float literals
83
+ rule %r/(in|is|and|or|not)\b/, Operator::Word
84
+ rule %r/(<<|>>|\/\/|\*\*)=?/, Operator
85
+ rule %r/[-~+\/*%=<>&^|@]=?|!=/, Operator
86
+ rule %r/\.(?![0-9])/, Operator # so it doesn't match float literals
87
87
 
88
- rule /(from)((?:\\\s|\s)+)(#{dotted_identifier})((?:\\\s|\s)+)(import)/ do
88
+ rule %r/(from)((?:\\\s|\s)+)(#{dotted_identifier})((?:\\\s|\s)+)(import)/ do
89
89
  groups Keyword::Namespace,
90
90
  Text,
91
91
  Name::Namespace,
@@ -93,35 +93,35 @@ module Rouge
93
93
  Keyword::Namespace
94
94
  end
95
95
 
96
- rule /(import)(\s+)(#{dotted_identifier})/ do
96
+ rule %r/(import)(\s+)(#{dotted_identifier})/ do
97
97
  groups Keyword::Namespace, Text, Name::Namespace
98
98
  end
99
99
 
100
- rule /(def)((?:\s|\\\s)+)/ do
100
+ rule %r/(def)((?:\s|\\\s)+)/ do
101
101
  groups Keyword, Text
102
102
  push :funcname
103
103
  end
104
104
 
105
- rule /(class)((?:\s|\\\s)+)/ do
105
+ rule %r/(class)((?:\s|\\\s)+)/ do
106
106
  groups Keyword, Text
107
107
  push :classname
108
108
  end
109
109
 
110
110
  # TODO: not in python 3
111
- rule /`.*?`/, Str::Backtick
112
- rule /(?:r|ur|ru)"""/i, Str, :raw_tdqs
113
- rule /(?:r|ur|ru)'''/i, Str, :raw_tsqs
114
- rule /(?:r|ur|ru)"/i, Str, :raw_dqs
115
- rule /(?:r|ur|ru)'/i, Str, :raw_sqs
116
- rule /u?"""/i, Str, :tdqs
117
- rule /u?'''/i, Str, :tsqs
118
- rule /u?"/i, Str, :dqs
119
- rule /u?'/i, Str, :sqs
120
-
121
- rule /@#{dotted_identifier}/i, Name::Decorator
111
+ rule %r/`.*?`/, Str::Backtick
112
+ rule %r/(?:r|ur|ru)"""/i, Str, :raw_tdqs
113
+ rule %r/(?:r|ur|ru)'''/i, Str, :raw_tsqs
114
+ rule %r/(?:r|ur|ru)"/i, Str, :raw_dqs
115
+ rule %r/(?:r|ur|ru)'/i, Str, :raw_sqs
116
+ rule %r/u?"""/i, Str, :tdqs
117
+ rule %r/u?'''/i, Str, :tsqs
118
+ rule %r/u?"/i, Str, :dqs
119
+ rule %r/u?'/i, Str, :sqs
120
+
121
+ rule %r/@#{dotted_identifier}/i, Name::Decorator
122
122
 
123
123
  # using negative lookbehind so we don't match property names
124
- rule /(?<!\.)#{identifier}/ do |m|
124
+ rule %r/(?<!\.)#{identifier}/ do |m|
125
125
  if self.class.keywords.include? m[0]
126
126
  token Keyword
127
127
  elsif self.class.exceptions.include? m[0]
@@ -140,15 +140,15 @@ module Rouge
140
140
  digits = /[0-9](_?[0-9])*/
141
141
  decimal = /((#{digits})?\.#{digits}|#{digits}\.)/
142
142
  exponent = /e[+-]?#{digits}/i
143
- rule /#{decimal}(#{exponent})?j?/i, Num::Float
144
- rule /#{digits}#{exponent}j?/i, Num::Float
145
- rule /#{digits}j/i, Num::Float
143
+ rule %r/#{decimal}(#{exponent})?j?/i, Num::Float
144
+ rule %r/#{digits}#{exponent}j?/i, Num::Float
145
+ rule %r/#{digits}j/i, Num::Float
146
146
 
147
- rule /0b(_?[0-1])+/i, Num::Bin
148
- rule /0o(_?[0-7])+/i, Num::Oct
149
- rule /0x(_?[a-f0-9])+/i, Num::Hex
150
- rule /\d+L/, Num::Integer::Long
151
- rule /([1-9](_?[0-9])*|0(_?0)*)/, Num::Integer
147
+ rule %r/0b(_?[0-1])+/i, Num::Bin
148
+ rule %r/0o(_?[0-7])+/i, Num::Oct
149
+ rule %r/0x(_?[a-f0-9])+/i, Num::Hex
150
+ rule %r/\d+L/, Num::Integer::Long
151
+ rule %r/([1-9](_?[0-9])*|0(_?0)*)/, Num::Integer
152
152
  end
153
153
 
154
154
  state :funcname do
@@ -160,11 +160,11 @@ module Rouge
160
160
  end
161
161
 
162
162
  state :raise do
163
- rule /from\b/, Keyword
164
- rule /raise\b/, Keyword
165
- rule /yield\b/, Keyword
166
- rule /\n/, Text, :pop!
167
- rule /;/, Punctuation, :pop!
163
+ rule %r/from\b/, Keyword
164
+ rule %r/raise\b/, Keyword
165
+ rule %r/yield\b/, Keyword
166
+ rule %r/\n/, Text, :pop!
167
+ rule %r/;/, Punctuation, :pop!
168
168
  mixin :root
169
169
  end
170
170
 
@@ -173,28 +173,28 @@ module Rouge
173
173
  end
174
174
 
175
175
  state :strings do
176
- rule /%(\([a-z0-9_]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?/i, Str::Interpol
176
+ rule %r/%(\([a-z0-9_]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?/i, Str::Interpol
177
177
  end
178
178
 
179
179
  state :strings_double do
180
- rule /[^\\"%\n]+/, Str
180
+ rule %r/[^\\"%\n]+/, Str
181
181
  mixin :strings
182
182
  end
183
183
 
184
184
  state :strings_single do
185
- rule /[^\\'%\n]+/, Str
185
+ rule %r/[^\\'%\n]+/, Str
186
186
  mixin :strings
187
187
  end
188
188
 
189
189
  state :nl do
190
- rule /\n/, Str
190
+ rule %r/\n/, Str
191
191
  end
192
192
 
193
193
  state :escape do
194
194
  rule %r(\\
195
195
  ( [\\abfnrtv"']
196
196
  | \n
197
- | N{[a-zA-z][a-zA-Z ]+[a-zA-Z]}
197
+ | N{[a-zA-Z][a-zA-Z ]+[a-zA-Z]}
198
198
  | u[a-fA-F0-9]{4}
199
199
  | U[a-fA-F0-9]{8}
200
200
  | x[a-fA-F0-9]{2}
@@ -204,32 +204,32 @@ module Rouge
204
204
  end
205
205
 
206
206
  state :raw_escape do
207
- rule /\\./, Str
207
+ rule %r/\\./, Str
208
208
  end
209
209
 
210
210
  state :dqs do
211
- rule /"/, Str, :pop!
211
+ rule %r/"/, Str, :pop!
212
212
  mixin :escape
213
213
  mixin :strings_double
214
214
  end
215
215
 
216
216
  state :sqs do
217
- rule /'/, Str, :pop!
217
+ rule %r/'/, Str, :pop!
218
218
  mixin :escape
219
219
  mixin :strings_single
220
220
  end
221
221
 
222
222
  state :tdqs do
223
- rule /"""/, Str, :pop!
224
- rule /"/, Str
223
+ rule %r/"""/, Str, :pop!
224
+ rule %r/"/, Str
225
225
  mixin :escape
226
226
  mixin :strings_double
227
227
  mixin :nl
228
228
  end
229
229
 
230
230
  state :tsqs do
231
- rule /'''/, Str, :pop!
232
- rule /'/, Str
231
+ rule %r/'''/, Str, :pop!
232
+ rule %r/'/, Str
233
233
  mixin :escape
234
234
  mixin :strings_single
235
235
  mixin :nl