rouge 3.4.1 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rouge.rb +3 -0
- data/lib/rouge/cli.rb +19 -2
- data/lib/rouge/demos/bpf +7 -0
- data/lib/rouge/demos/brainfuck +5 -0
- data/lib/rouge/demos/magik +6 -0
- data/lib/rouge/formatter.rb +2 -2
- data/lib/rouge/formatters/tex.rb +90 -0
- data/lib/rouge/guessers/glob_mapping.rb +1 -1
- data/lib/rouge/lexer.rb +22 -10
- data/lib/rouge/lexers/abap.rb +11 -11
- data/lib/rouge/lexers/actionscript.rb +34 -34
- data/lib/rouge/lexers/apache.rb +8 -8
- data/lib/rouge/lexers/apple_script.rb +15 -14
- data/lib/rouge/lexers/awk.rb +25 -25
- data/lib/rouge/lexers/biml.rb +4 -4
- data/lib/rouge/lexers/bpf.rb +104 -0
- data/lib/rouge/lexers/brainfuck.rb +53 -0
- data/lib/rouge/lexers/bsl.rb +12 -12
- data/lib/rouge/lexers/c.rb +30 -30
- data/lib/rouge/lexers/ceylon.rb +1 -29
- data/lib/rouge/lexers/cfscript.rb +26 -26
- data/lib/rouge/lexers/clojure.rb +14 -14
- data/lib/rouge/lexers/cmake.rb +14 -14
- data/lib/rouge/lexers/coffeescript.rb +30 -30
- data/lib/rouge/lexers/common_lisp.rb +36 -36
- data/lib/rouge/lexers/conf.rb +6 -6
- data/lib/rouge/lexers/coq.rb +18 -18
- data/lib/rouge/lexers/cpp.rb +8 -8
- data/lib/rouge/lexers/crystal.rb +70 -70
- data/lib/rouge/lexers/csharp.rb +28 -28
- data/lib/rouge/lexers/css.rb +23 -23
- data/lib/rouge/lexers/d.rb +59 -59
- data/lib/rouge/lexers/dart.rb +33 -33
- data/lib/rouge/lexers/digdag.rb +1 -1
- data/lib/rouge/lexers/docker.rb +10 -10
- data/lib/rouge/lexers/dot.rb +16 -16
- data/lib/rouge/lexers/eiffel.rb +20 -20
- data/lib/rouge/lexers/elixir.rb +29 -28
- data/lib/rouge/lexers/elm.rb +29 -29
- data/lib/rouge/lexers/erb.rb +4 -4
- data/lib/rouge/lexers/factor.rb +40 -40
- data/lib/rouge/lexers/fortran.rb +32 -32
- data/lib/rouge/lexers/fsharp.rb +26 -26
- data/lib/rouge/lexers/gherkin.rb +13 -13
- data/lib/rouge/lexers/glsl.rb +0 -4
- data/lib/rouge/lexers/go.rb +1 -1
- data/lib/rouge/lexers/graphql.rb +62 -62
- data/lib/rouge/lexers/groovy.rb +23 -25
- data/lib/rouge/lexers/hack.rb +1 -1
- data/lib/rouge/lexers/haml.rb +25 -29
- data/lib/rouge/lexers/handlebars.rb +18 -18
- data/lib/rouge/lexers/haskell.rb +66 -65
- data/lib/rouge/lexers/hcl.rb +25 -25
- data/lib/rouge/lexers/html.rb +31 -31
- data/lib/rouge/lexers/http.rb +4 -4
- data/lib/rouge/lexers/hylang.rb +14 -14
- data/lib/rouge/lexers/idlang.rb +32 -32
- data/lib/rouge/lexers/igorpro.rb +30 -30
- data/lib/rouge/lexers/ini.rb +12 -12
- data/lib/rouge/lexers/io.rb +7 -7
- data/lib/rouge/lexers/irb.rb +5 -5
- data/lib/rouge/lexers/java.rb +24 -24
- data/lib/rouge/lexers/javascript.rb +51 -51
- data/lib/rouge/lexers/jinja.rb +22 -22
- data/lib/rouge/lexers/json.rb +11 -10
- data/lib/rouge/lexers/json_doc.rb +2 -2
- data/lib/rouge/lexers/jsonnet.rb +18 -18
- data/lib/rouge/lexers/jsp.rb +28 -28
- data/lib/rouge/lexers/jsx.rb +16 -16
- data/lib/rouge/lexers/julia.rb +44 -44
- data/lib/rouge/lexers/kotlin.rb +3 -3
- data/lib/rouge/lexers/lasso.rb +50 -50
- data/lib/rouge/lexers/liquid.rb +53 -53
- data/lib/rouge/lexers/literate_coffeescript.rb +2 -2
- data/lib/rouge/lexers/literate_haskell.rb +5 -5
- data/lib/rouge/lexers/llvm.rb +23 -16
- data/lib/rouge/lexers/lua.rb +3 -3
- data/lib/rouge/lexers/m68k.rb +18 -19
- data/lib/rouge/lexers/magik.rb +126 -0
- data/lib/rouge/lexers/make.rb +22 -28
- data/lib/rouge/lexers/markdown.rb +37 -37
- data/lib/rouge/lexers/mathematica.rb +11 -11
- data/lib/rouge/lexers/matlab.rb +20 -20
- data/lib/rouge/lexers/moonscript.rb +3 -3
- data/lib/rouge/lexers/mosel.rb +17 -17
- data/lib/rouge/lexers/mxml.rb +18 -18
- data/lib/rouge/lexers/nasm.rb +24 -25
- data/lib/rouge/lexers/nginx.rb +14 -14
- data/lib/rouge/lexers/nim.rb +1 -1
- data/lib/rouge/lexers/nix.rb +42 -42
- data/lib/rouge/lexers/objective_c.rb +38 -38
- data/lib/rouge/lexers/ocaml.rb +29 -29
- data/lib/rouge/lexers/pascal.rb +4 -4
- data/lib/rouge/lexers/perl.rb +68 -68
- data/lib/rouge/lexers/php.rb +38 -38
- data/lib/rouge/lexers/plist.rb +14 -14
- data/lib/rouge/lexers/pony.rb +19 -19
- data/lib/rouge/lexers/powershell.rb +25 -25
- data/lib/rouge/lexers/praat.rb +75 -75
- data/lib/rouge/lexers/prolog.rb +26 -20
- data/lib/rouge/lexers/prometheus.rb +30 -30
- data/lib/rouge/lexers/properties.rb +12 -12
- data/lib/rouge/lexers/protobuf.rb +22 -22
- data/lib/rouge/lexers/puppet.rb +31 -31
- data/lib/rouge/lexers/python.rb +52 -52
- data/lib/rouge/lexers/q.rb +12 -12
- data/lib/rouge/lexers/qml.rb +12 -12
- data/lib/rouge/lexers/r.rb +12 -12
- data/lib/rouge/lexers/racket.rb +22 -22
- data/lib/rouge/lexers/ruby.rb +71 -69
- data/lib/rouge/lexers/rust.rb +30 -30
- data/lib/rouge/lexers/sass.rb +8 -8
- data/lib/rouge/lexers/sass/common.rb +40 -40
- data/lib/rouge/lexers/scala.rb +43 -43
- data/lib/rouge/lexers/scheme.rb +18 -18
- data/lib/rouge/lexers/scss.rb +3 -3
- data/lib/rouge/lexers/sed.rb +29 -29
- data/lib/rouge/lexers/shell.rb +61 -52
- data/lib/rouge/lexers/sieve.rb +8 -8
- data/lib/rouge/lexers/slim.rb +24 -24
- data/lib/rouge/lexers/smalltalk.rb +33 -33
- data/lib/rouge/lexers/smarty.rb +12 -12
- data/lib/rouge/lexers/sml.rb +67 -67
- data/lib/rouge/lexers/sqf.rb +1 -1
- data/lib/rouge/lexers/sql.rb +21 -21
- data/lib/rouge/lexers/supercollider.rb +19 -19
- data/lib/rouge/lexers/swift.rb +42 -39
- data/lib/rouge/lexers/tap.rb +20 -20
- data/lib/rouge/lexers/tcl.rb +27 -27
- data/lib/rouge/lexers/terraform.rb +13 -13
- data/lib/rouge/lexers/tex.rb +19 -19
- data/lib/rouge/lexers/toml.rb +18 -18
- data/lib/rouge/lexers/tulip.rb +36 -36
- data/lib/rouge/lexers/turtle.rb +35 -38
- data/lib/rouge/lexers/vala.rb +17 -17
- data/lib/rouge/lexers/vb.rb +27 -27
- data/lib/rouge/lexers/verilog.rb +25 -27
- data/lib/rouge/lexers/vhdl.rb +10 -10
- data/lib/rouge/lexers/viml.rb +14 -14
- data/lib/rouge/lexers/vue.rb +9 -9
- data/lib/rouge/lexers/wollok.rb +25 -25
- data/lib/rouge/lexers/xml.rb +17 -21
- data/lib/rouge/lexers/xojo.rb +15 -15
- data/lib/rouge/lexers/yaml.rb +61 -61
- data/lib/rouge/plugins/redcarpet.rb +1 -1
- data/lib/rouge/tex_theme_renderer.rb +128 -0
- data/lib/rouge/theme.rb +4 -0
- data/lib/rouge/themes/magritte.rb +78 -0
- data/lib/rouge/version.rb +1 -1
- metadata +11 -2
data/lib/rouge/lexers/q.rb
CHANGED
@@ -36,23 +36,23 @@ module Rouge
|
|
36
36
|
|
37
37
|
state :root do
|
38
38
|
# q allows a file to start with a shebang
|
39
|
-
rule /#!(.*?)$/, Comment::Preproc, :top
|
40
|
-
rule //, Text, :top
|
39
|
+
rule %r/#!(.*?)$/, Comment::Preproc, :top
|
40
|
+
rule %r//, Text, :top
|
41
41
|
end
|
42
42
|
|
43
43
|
state :top do
|
44
44
|
# indented lines at the top of the file are ignored by q
|
45
|
-
rule /^[ \t\r]+.*$/, Comment::Special
|
46
|
-
rule /\n+/, Text
|
47
|
-
rule //, Text, :base
|
45
|
+
rule %r/^[ \t\r]+.*$/, Comment::Special
|
46
|
+
rule %r/\n+/, Text
|
47
|
+
rule %r//, Text, :base
|
48
48
|
end
|
49
49
|
|
50
50
|
state :base do
|
51
|
-
rule /\n+/m, Text
|
51
|
+
rule %r/\n+/m, Text
|
52
52
|
rule(/^.\)/, Keyword::Declaration)
|
53
53
|
|
54
54
|
# Identifiers, word operators, etc.
|
55
|
-
rule /#{identifier}/ do |m|
|
55
|
+
rule %r/#{identifier}/ do |m|
|
56
56
|
if self.class.keywords.include? m[0]
|
57
57
|
token Keyword
|
58
58
|
elsif self.class.word_operators.include? m[0]
|
@@ -102,7 +102,7 @@ module Rouge
|
|
102
102
|
rule(%r{(`:[:a-z0-9._\/]*|`(?:[a-z0-9.][:a-z0-9._]*)?)}i, Str::Symbol)
|
103
103
|
rule(/(?:<=|>=|<>|::)|[?:$%&|@._#*^\-+~,!><=]:?/, Operator)
|
104
104
|
|
105
|
-
rule /[{}\[\]();]/, Punctuation
|
105
|
+
rule %r/[{}\[\]();]/, Punctuation
|
106
106
|
|
107
107
|
# commands
|
108
108
|
rule(/\\.*\n/, Text)
|
@@ -111,13 +111,13 @@ module Rouge
|
|
111
111
|
|
112
112
|
state :string do
|
113
113
|
rule(/"/, Str, :pop!)
|
114
|
-
rule /\\([\\nr]|[01][0-7]{2})/, Str::Escape
|
115
|
-
rule /[^\\"\n]+/, Str
|
116
|
-
rule /\\/, Str # stray backslash
|
114
|
+
rule %r/\\([\\nr]|[01][0-7]{2})/, Str::Escape
|
115
|
+
rule %r/[^\\"\n]+/, Str
|
116
|
+
rule %r/\\/, Str # stray backslash
|
117
117
|
end
|
118
118
|
|
119
119
|
state :bottom do
|
120
|
-
rule /.*\z/m, Comment::Multiline
|
120
|
+
rule %r/.*\z/m, Comment::Multiline
|
121
121
|
end
|
122
122
|
end
|
123
123
|
end
|
data/lib/rouge/lexers/qml.rb
CHANGED
@@ -17,57 +17,57 @@ module Rouge
|
|
17
17
|
id_with_dots = /[$a-zA-Z_][a-zA-Z0-9_.]*/
|
18
18
|
|
19
19
|
prepend :root do
|
20
|
-
rule /(#{id_with_dots})(\s*)({)/ do
|
20
|
+
rule %r/(#{id_with_dots})(\s*)({)/ do
|
21
21
|
groups Keyword::Type, Text, Punctuation
|
22
22
|
push :type_block
|
23
23
|
end
|
24
|
-
rule /(#{id_with_dots})(\s+)(on)(\s+)(#{id_with_dots})(\s*)({)/ do
|
24
|
+
rule %r/(#{id_with_dots})(\s+)(on)(\s+)(#{id_with_dots})(\s*)({)/ do
|
25
25
|
groups Keyword::Type, Text, Keyword, Text, Name::Label, Text, Punctuation
|
26
26
|
push :type_block
|
27
27
|
end
|
28
28
|
|
29
|
-
rule /[{]/, Punctuation, :push
|
29
|
+
rule %r/[{]/, Punctuation, :push
|
30
30
|
end
|
31
31
|
|
32
32
|
state :type_block do
|
33
|
-
rule /(id)(\s*)(:)(\s*)(#{id_with_dots})/ do
|
33
|
+
rule %r/(id)(\s*)(:)(\s*)(#{id_with_dots})/ do
|
34
34
|
groups Name::Label, Text, Punctuation, Text, Keyword::Declaration
|
35
35
|
end
|
36
36
|
|
37
|
-
rule /(#{id_with_dots})(\s*)(:)/ do
|
37
|
+
rule %r/(#{id_with_dots})(\s*)(:)/ do
|
38
38
|
groups Name::Label, Text, Punctuation
|
39
39
|
push :expr_start
|
40
40
|
end
|
41
41
|
|
42
|
-
rule /(signal)(\s+)(#{id_with_dots})/ do
|
42
|
+
rule %r/(signal)(\s+)(#{id_with_dots})/ do
|
43
43
|
groups Keyword::Declaration, Text, Name::Label
|
44
44
|
push :signal
|
45
45
|
end
|
46
46
|
|
47
|
-
rule /(property)(\s+)(#{id_with_dots})(\s+)(#{id_with_dots})(\s*)(:?)/ do
|
47
|
+
rule %r/(property)(\s+)(#{id_with_dots})(\s+)(#{id_with_dots})(\s*)(:?)/ do
|
48
48
|
groups Keyword::Declaration, Text, Keyword::Type, Text, Name::Label, Text, Punctuation
|
49
49
|
push :expr_start
|
50
50
|
end
|
51
51
|
|
52
|
-
rule /[}]/, Punctuation, :pop!
|
52
|
+
rule %r/[}]/, Punctuation, :pop!
|
53
53
|
mixin :root
|
54
54
|
end
|
55
55
|
|
56
56
|
state :signal do
|
57
57
|
mixin :comments_and_whitespace
|
58
|
-
rule /\(/ do
|
58
|
+
rule %r/\(/ do
|
59
59
|
token Punctuation
|
60
60
|
goto :signal_args
|
61
61
|
end
|
62
|
-
rule //, Text, :pop!
|
62
|
+
rule %r//, Text, :pop!
|
63
63
|
end
|
64
64
|
|
65
65
|
state :signal_args do
|
66
66
|
mixin :comments_and_whitespace
|
67
|
-
rule /(#{id_with_dots})(\s+)(#{id_with_dots})(\s*)(,?)/ do
|
67
|
+
rule %r/(#{id_with_dots})(\s+)(#{id_with_dots})(\s*)(,?)/ do
|
68
68
|
groups Keyword::Type, Text, Name, Text, Punctuation
|
69
69
|
end
|
70
|
-
rule /\)/ , Punctuation, :pop!
|
70
|
+
rule %r/\)/ , Punctuation, :pop!
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
data/lib/rouge/lexers/r.rb
CHANGED
@@ -49,27 +49,27 @@ module Rouge
|
|
49
49
|
end
|
50
50
|
|
51
51
|
state :root do
|
52
|
-
rule /#'.*?$/, Comment::Doc
|
53
|
-
rule /#.*?$/, Comment::Single
|
54
|
-
rule /\s+/m, Text::Whitespace
|
52
|
+
rule %r/#'.*?$/, Comment::Doc
|
53
|
+
rule %r/#.*?$/, Comment::Single
|
54
|
+
rule %r/\s+/m, Text::Whitespace
|
55
55
|
|
56
|
-
rule /`[^`]+?`/, Name
|
57
|
-
rule /'(\\.|.)*?'/m, Str::Single
|
58
|
-
rule /"(\\.|.)*?"/m, Str::Double
|
56
|
+
rule %r/`[^`]+?`/, Name
|
57
|
+
rule %r/'(\\.|.)*?'/m, Str::Single
|
58
|
+
rule %r/"(\\.|.)*?"/m, Str::Double
|
59
59
|
|
60
|
-
rule /%[^%]*?%/, Operator
|
60
|
+
rule %r/%[^%]*?%/, Operator
|
61
61
|
|
62
|
-
rule /0[xX][a-fA-F0-9]+([pP][0-9]+)?[Li]?/, Num::Hex
|
63
|
-
rule /[+-]?(\d+([.]\d+)?|[.]\d+)([eE][+-]?\d+)?[Li]?/,
|
62
|
+
rule %r/0[xX][a-fA-F0-9]+([pP][0-9]+)?[Li]?/, Num::Hex
|
63
|
+
rule %r/[+-]?(\d+([.]\d+)?|[.]\d+)([eE][+-]?\d+)?[Li]?/,
|
64
64
|
Num
|
65
65
|
|
66
66
|
# Only recognize built-in functions when they are actually used as a
|
67
67
|
# function call, i.e. followed by an opening parenthesis.
|
68
68
|
# `Name::Builtin` would be more logical, but is usually not
|
69
69
|
# highlighted specifically; thus use `Name::Function`.
|
70
|
-
rule /\b(?<!.)(#{PRIMITIVE_FUNCTIONS.join('|')})(?=\()/, Name::Function
|
70
|
+
rule %r/\b(?<!.)(#{PRIMITIVE_FUNCTIONS.join('|')})(?=\()/, Name::Function
|
71
71
|
|
72
|
-
rule /[a-zA-Z.]([a-zA-Z_][\w.]*)?/ do |m|
|
72
|
+
rule %r/[a-zA-Z.]([a-zA-Z_][\w.]*)?/ do |m|
|
73
73
|
if KEYWORDS.include? m[0]
|
74
74
|
token Keyword
|
75
75
|
elsif KEYWORD_CONSTANTS.include? m[0]
|
@@ -81,7 +81,7 @@ module Rouge
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
rule /[\[\]{}();,]/, Punctuation
|
84
|
+
rule %r/[\[\]{}();,]/, Punctuation
|
85
85
|
|
86
86
|
rule %r([-<>?*+^/!=~$@:%&|]), Operator
|
87
87
|
end
|
data/lib/rouge/lexers/racket.rb
CHANGED
@@ -487,39 +487,39 @@ module Rouge
|
|
487
487
|
|
488
488
|
state :root do
|
489
489
|
# comments
|
490
|
-
rule /;.*$/, Comment::Single
|
491
|
-
rule /\s+/m, Text
|
490
|
+
rule %r/;.*$/, Comment::Single
|
491
|
+
rule %r/\s+/m, Text
|
492
492
|
|
493
|
-
rule /[+-]inf[.][f0]/, Num::Float
|
494
|
-
rule /[+-]nan[.]0/, Num::Float
|
495
|
-
rule /[-]min[.]0/, Num::Float
|
496
|
-
rule /[+]max[.]0/, Num::Float
|
493
|
+
rule %r/[+-]inf[.][f0]/, Num::Float
|
494
|
+
rule %r/[+-]nan[.]0/, Num::Float
|
495
|
+
rule %r/[-]min[.]0/, Num::Float
|
496
|
+
rule %r/[+]max[.]0/, Num::Float
|
497
497
|
|
498
|
-
rule /-?\d+\.\d+/, Num::Float
|
499
|
-
rule /-?\d+/, Num::Integer
|
498
|
+
rule %r/-?\d+\.\d+/, Num::Float
|
499
|
+
rule %r/-?\d+/, Num::Integer
|
500
500
|
|
501
|
-
rule /#:#{id}+/, Name::Tag # keyword
|
501
|
+
rule %r/#:#{id}+/, Name::Tag # keyword
|
502
502
|
|
503
|
-
rule /#b[01]+/, Num::Bin
|
504
|
-
rule /#o[0-7]+/, Num::Oct
|
505
|
-
rule /#d[0-9]+/, Num::Integer
|
506
|
-
rule /#x[0-9a-f]+/i, Num::Hex
|
507
|
-
rule /#[ei][\d.]+/, Num::Other
|
503
|
+
rule %r/#b[01]+/, Num::Bin
|
504
|
+
rule %r/#o[0-7]+/, Num::Oct
|
505
|
+
rule %r/#d[0-9]+/, Num::Integer
|
506
|
+
rule %r/#x[0-9a-f]+/i, Num::Hex
|
507
|
+
rule %r/#[ei][\d.]+/, Num::Other
|
508
508
|
|
509
|
-
rule /"(\\\\|\\"|[^"])*"/, Str
|
510
|
-
rule /['`]#{id}/i, Str::Symbol
|
511
|
-
rule /#\\([()\/'"._!\$%& ?=+-]{1}|[a-z0-9]+)/i,
|
509
|
+
rule %r/"(\\\\|\\"|[^"])*"/, Str
|
510
|
+
rule %r/['`]#{id}/i, Str::Symbol
|
511
|
+
rule %r/#\\([()\/'"._!\$%& ?=+-]{1}|[a-z0-9]+)/i,
|
512
512
|
Str::Char
|
513
|
-
rule /#t|#f/, Name::Constant
|
514
|
-
rule /(?:'|#|`|,@|,|\.)/, Operator
|
513
|
+
rule %r/#t|#f/, Name::Constant
|
514
|
+
rule %r/(?:'|#|`|,@|,|\.)/, Operator
|
515
515
|
|
516
|
-
rule /(['#])(\s*)(\()/m do
|
516
|
+
rule %r/(['#])(\s*)(\()/m do
|
517
517
|
groups Str::Symbol, Text, Punctuation
|
518
518
|
end
|
519
519
|
|
520
520
|
# () [] {} are all permitted as like pairs
|
521
|
-
rule /\(|\[|\{/, Punctuation, :command
|
522
|
-
rule /\)|\]|\}/, Punctuation
|
521
|
+
rule %r/\(|\[|\{/, Punctuation, :command
|
522
|
+
rule %r/\)|\]|\}/, Punctuation
|
523
523
|
|
524
524
|
rule id, Name::Variable
|
525
525
|
end
|
data/lib/rouge/lexers/ruby.rb
CHANGED
@@ -31,15 +31,15 @@ module Rouge
|
|
31
31
|
rule %r(:(?:\*\*|[-+]@|[/\%&\|^`~]|\[\]=?|<<|>>|<=?>|<=?|===?)),
|
32
32
|
Str::Symbol
|
33
33
|
|
34
|
-
rule /:'(\\\\|\\'|[^'])*'/, Str::Symbol
|
35
|
-
rule /:"/, Str::Symbol, :simple_sym
|
34
|
+
rule %r/:'(\\\\|\\'|[^'])*'/, Str::Symbol
|
35
|
+
rule %r/:"/, Str::Symbol, :simple_sym
|
36
36
|
end
|
37
37
|
|
38
38
|
state :sigil_strings do
|
39
39
|
# %-sigiled strings
|
40
40
|
# %(abc), %[abc], %<abc>, %.abc., %r.abc., etc
|
41
41
|
delimiter_map = { '{' => '}', '[' => ']', '(' => ')', '<' => '>' }
|
42
|
-
rule /%([rqswQWxiI])?([^\w\s])/ do |m|
|
42
|
+
rule %r/%([rqswQWxiI])?([^\w\s])/ do |m|
|
43
43
|
open = Regexp.escape(m[2])
|
44
44
|
close = Regexp.escape(delimiter_map[m[2]] || m[2])
|
45
45
|
interp = /[rQWxI]/ === m[1]
|
@@ -57,38 +57,40 @@ module Rouge
|
|
57
57
|
token toktype
|
58
58
|
|
59
59
|
push do
|
60
|
-
|
60
|
+
uniq_chars = "#{open}#{close}".squeeze
|
61
|
+
uniq_chars = '' if open == close && open == "\\#"
|
62
|
+
rule %r/\\[##{uniq_chars}\\]/, Str::Escape
|
61
63
|
# nesting rules only with asymmetric delimiters
|
62
64
|
if open != close
|
63
|
-
rule /#{open}/ do
|
65
|
+
rule %r/#{open}/ do
|
64
66
|
token toktype
|
65
67
|
push
|
66
68
|
end
|
67
69
|
end
|
68
|
-
rule /#{close}/, toktype, :pop!
|
70
|
+
rule %r/#{close}/, toktype, :pop!
|
69
71
|
|
70
72
|
if interp
|
71
73
|
mixin :string_intp_escaped
|
72
|
-
rule /#/, toktype
|
74
|
+
rule %r/#/, toktype
|
73
75
|
else
|
74
|
-
rule /[\\#]/, toktype
|
76
|
+
rule %r/[\\#]/, toktype
|
75
77
|
end
|
76
78
|
|
77
|
-
rule /[^##{
|
79
|
+
rule %r/[^##{uniq_chars}\\]+/m, toktype
|
78
80
|
end
|
79
81
|
end
|
80
82
|
end
|
81
83
|
|
82
84
|
state :strings do
|
83
85
|
mixin :symbols
|
84
|
-
rule /\b[a-z_]\w*?[?!]?:\s+/, Str::Symbol, :expr_start
|
85
|
-
rule /'(\\\\|\\'|[^'])*'/, Str::Single
|
86
|
-
rule /"/, Str::Double, :simple_string
|
87
|
-
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
|
88
90
|
end
|
89
91
|
|
90
92
|
state :regex_flags do
|
91
|
-
rule /[mixounse]*/, Str::Regex, :pop!
|
93
|
+
rule %r/[mixounse]*/, Str::Regex, :pop!
|
92
94
|
end
|
93
95
|
|
94
96
|
# double-quoted string and symbol
|
@@ -97,9 +99,9 @@ module Rouge
|
|
97
99
|
[:backtick, Str::Backtick, '`']].each do |name, tok, fin|
|
98
100
|
state :"simple_#{name}" do
|
99
101
|
mixin :string_intp_escaped
|
100
|
-
rule /[^\\#{fin}#]+/m, tok
|
101
|
-
rule /[\\#]/, tok
|
102
|
-
rule /#{fin}/, tok, :pop!
|
102
|
+
rule %r/[^\\#{fin}#]+/m, tok
|
103
|
+
rule %r/[\\#]/, tok
|
104
|
+
rule %r/#{fin}/, tok, :pop!
|
103
105
|
end
|
104
106
|
end
|
105
107
|
|
@@ -151,38 +153,38 @@ module Rouge
|
|
151
153
|
|
152
154
|
state :whitespace do
|
153
155
|
mixin :inline_whitespace
|
154
|
-
rule /\n\s*/m, Text, :expr_start
|
155
|
-
rule /#.*$/, Comment::Single
|
156
|
+
rule %r/\n\s*/m, Text, :expr_start
|
157
|
+
rule %r/#.*$/, Comment::Single
|
156
158
|
|
157
159
|
rule %r(=begin\b.*?\n=end\b)m, Comment::Multiline
|
158
160
|
end
|
159
161
|
|
160
162
|
state :inline_whitespace do
|
161
|
-
rule /[ \t\r]+/, Text
|
163
|
+
rule %r/[ \t\r]+/, Text
|
162
164
|
end
|
163
165
|
|
164
166
|
state :root do
|
165
167
|
mixin :whitespace
|
166
|
-
rule /__END__/, Comment::Preproc, :end_part
|
168
|
+
rule %r/__END__/, Comment::Preproc, :end_part
|
167
169
|
|
168
|
-
rule /0_?[0-7]+(?:_[0-7]+)*/, Num::Oct
|
169
|
-
rule /0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*/, Num::Hex
|
170
|
-
rule /0b[01]+(?:_[01]+)*/, Num::Bin
|
171
|
-
rule /\d+\.\d+(e[\+\-]?\d+)?/, Num::Float
|
172
|
-
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
|
+
rule %r/\d+\.\d+(e[\+\-]?\d+)?/, Num::Float
|
174
|
+
rule %r/[\d]+(?:_\d+)*/, Num::Integer
|
173
175
|
|
174
176
|
# names
|
175
|
-
rule /@@[a-z_]\w*/i, Name::Variable::Class
|
176
|
-
rule /@[a-z_]\w*/i, Name::Variable::Instance
|
177
|
-
rule /\$\w+/, Name::Variable::Global
|
177
|
+
rule %r/@@[a-z_]\w*/i, Name::Variable::Class
|
178
|
+
rule %r/@[a-z_]\w*/i, Name::Variable::Instance
|
179
|
+
rule %r/\$\w+/, Name::Variable::Global
|
178
180
|
rule %r(\$[!@&`'+~=/\\,;.<>_*\$?:"]), Name::Variable::Global
|
179
|
-
rule /\$-[0adFiIlpvw]/, Name::Variable::Global
|
180
|
-
rule /::/, Operator
|
181
|
+
rule %r/\$-[0adFiIlpvw]/, Name::Variable::Global
|
182
|
+
rule %r/::/, Operator
|
181
183
|
|
182
184
|
mixin :strings
|
183
185
|
|
184
|
-
rule /(?:#{keywords.join('|')})\b/, Keyword, :expr_start
|
185
|
-
rule /(?:#{keywords_pseudo.join('|')})\b/, Keyword::Pseudo, :expr_start
|
186
|
+
rule %r/(?:#{keywords.join('|')})\b/, Keyword, :expr_start
|
187
|
+
rule %r/(?:#{keywords_pseudo.join('|')})\b/, Keyword::Pseudo, :expr_start
|
186
188
|
|
187
189
|
rule %r(
|
188
190
|
(module)
|
@@ -192,52 +194,52 @@ module Rouge
|
|
192
194
|
groups Keyword, Text, Name::Namespace
|
193
195
|
end
|
194
196
|
|
195
|
-
rule /(def\b)(\s*)/ do
|
197
|
+
rule %r/(def\b)(\s*)/ do
|
196
198
|
groups Keyword, Text
|
197
199
|
push :funcname
|
198
200
|
end
|
199
201
|
|
200
|
-
rule /(class\b)(\s*)/ do
|
202
|
+
rule %r/(class\b)(\s*)/ do
|
201
203
|
groups Keyword, Text
|
202
204
|
push :classname
|
203
205
|
end
|
204
206
|
|
205
|
-
rule /(?:#{builtins_q.join('|')})[?]/, Name::Builtin, :expr_start
|
206
|
-
rule /(?:#{builtins_b.join('|')})!/, Name::Builtin, :expr_start
|
207
|
-
rule /(?<!\.)(?:#{builtins_g.join('|')})\b/,
|
207
|
+
rule %r/(?:#{builtins_q.join('|')})[?]/, Name::Builtin, :expr_start
|
208
|
+
rule %r/(?:#{builtins_b.join('|')})!/, Name::Builtin, :expr_start
|
209
|
+
rule %r/(?<!\.)(?:#{builtins_g.join('|')})\b/,
|
208
210
|
Name::Builtin, :method_call
|
209
211
|
|
210
212
|
mixin :has_heredocs
|
211
213
|
|
212
214
|
# `..` and `...` for ranges must have higher priority than `.`
|
213
215
|
# Otherwise, they will be parsed as :method_call
|
214
|
-
rule /\.{2,3}/, Operator, :expr_start
|
216
|
+
rule %r/\.{2,3}/, Operator, :expr_start
|
215
217
|
|
216
|
-
rule /[A-Z][a-zA-Z0-9_]*/, Name::Constant, :method_call
|
217
|
-
rule /(\.|::)(\s*)([a-z_]\w*[!?]?|[*%&^`~+-\/\[<>=])/ do
|
218
|
+
rule %r/[A-Z][a-zA-Z0-9_]*/, Name::Constant, :method_call
|
219
|
+
rule %r/(\.|::)(\s*)([a-z_]\w*[!?]?|[*%&^`~+-\/\[<>=])/ do
|
218
220
|
groups Punctuation, Text, Name::Function
|
219
221
|
push :method_call
|
220
222
|
end
|
221
223
|
|
222
|
-
rule /[a-zA-Z_]\w*[?!]/, Name, :expr_start
|
223
|
-
rule /[a-zA-Z_]\w*/, Name, :method_call
|
224
|
-
rule /\*\*|<<?|>>?|>=|<=|<=>|=~|={3}|!~|&&?|\|\||\./,
|
224
|
+
rule %r/[a-zA-Z_]\w*[?!]/, Name, :expr_start
|
225
|
+
rule %r/[a-zA-Z_]\w*/, Name, :method_call
|
226
|
+
rule %r/\*\*|<<?|>>?|>=|<=|<=>|=~|={3}|!~|&&?|\|\||\./,
|
225
227
|
Operator, :expr_start
|
226
|
-
rule /[-+\/*%=<>&!^|~]=?/, Operator, :expr_start
|
228
|
+
rule %r/[-+\/*%=<>&!^|~]=?/, Operator, :expr_start
|
227
229
|
rule(/[?]/) { token Punctuation; push :ternary; push :expr_start }
|
228
230
|
rule %r<[\[({,:\\;/]>, Punctuation, :expr_start
|
229
231
|
rule %r<[\])}]>, Punctuation
|
230
232
|
end
|
231
233
|
|
232
234
|
state :has_heredocs do
|
233
|
-
rule /(?<!\w)(<<[-~]?)(["`']?)([a-zA-Z_]\w*)(\2)/ do |m|
|
235
|
+
rule %r/(?<!\w)(<<[-~]?)(["`']?)([a-zA-Z_]\w*)(\2)/ do |m|
|
234
236
|
token Operator, m[1]
|
235
237
|
token Name::Constant, "#{m[2]}#{m[3]}#{m[4]}"
|
236
238
|
@heredoc_queue << [['<<-', '<<~'].include?(m[1]), m[3]]
|
237
239
|
push :heredoc_queue unless state? :heredoc_queue
|
238
240
|
end
|
239
241
|
|
240
|
-
rule /(<<[-~]?)(["'])(\2)/ do |m|
|
242
|
+
rule %r/(<<[-~]?)(["'])(\2)/ do |m|
|
241
243
|
token Operator, m[1]
|
242
244
|
token Name::Constant, "#{m[2]}#{m[3]}#{m[4]}"
|
243
245
|
@heredoc_queue << [['<<-', '<<~'].include?(m[1]), '']
|
@@ -246,7 +248,7 @@ module Rouge
|
|
246
248
|
end
|
247
249
|
|
248
250
|
state :heredoc_queue do
|
249
|
-
rule /(?=\n)/ do
|
251
|
+
rule %r/(?=\n)/ do
|
250
252
|
goto :resolve_heredocs
|
251
253
|
end
|
252
254
|
|
@@ -256,13 +258,13 @@ module Rouge
|
|
256
258
|
state :resolve_heredocs do
|
257
259
|
mixin :string_intp_escaped
|
258
260
|
|
259
|
-
rule /\n/, Str::Heredoc, :test_heredoc
|
260
|
-
rule /[#\\\n]/, Str::Heredoc
|
261
|
-
rule /[^#\\\n]+/, Str::Heredoc
|
261
|
+
rule %r/\n/, Str::Heredoc, :test_heredoc
|
262
|
+
rule %r/[#\\\n]/, Str::Heredoc
|
263
|
+
rule %r/[^#\\\n]+/, Str::Heredoc
|
262
264
|
end
|
263
265
|
|
264
266
|
state :test_heredoc do
|
265
|
-
rule /[^#\\\n]*$/ do |m|
|
267
|
+
rule %r/[^#\\\n]*$/ do |m|
|
266
268
|
tolerant, heredoc_name = @heredoc_queue.first
|
267
269
|
check = tolerant ? m[0].strip : m[0].rstrip
|
268
270
|
|
@@ -284,12 +286,12 @@ module Rouge
|
|
284
286
|
end
|
285
287
|
|
286
288
|
state :funcname do
|
287
|
-
rule /\s+/, Text
|
288
|
-
rule /\(/, Punctuation, :defexpr
|
289
|
+
rule %r/\s+/, Text
|
290
|
+
rule %r/\(/, Punctuation, :defexpr
|
289
291
|
rule %r(
|
290
|
-
(?:([a-zA-Z_]
|
292
|
+
(?:([a-zA-Z_]\w*)(\.))?
|
291
293
|
(
|
292
|
-
[a-zA-Z_]
|
294
|
+
[a-zA-Z_]\w*[!?]? |
|
293
295
|
\*\*? | [-+]@? | [/%&\|^`~] | \[\]=? |
|
294
296
|
<<? | >>? | <=>? | >= | ===?
|
295
297
|
)
|
@@ -303,20 +305,20 @@ module Rouge
|
|
303
305
|
end
|
304
306
|
|
305
307
|
state :classname do
|
306
|
-
rule /\s+/, Text
|
307
|
-
rule /\(/ do
|
308
|
+
rule %r/\s+/, Text
|
309
|
+
rule %r/\(/ do
|
308
310
|
token Punctuation
|
309
311
|
push :defexpr
|
310
312
|
push :expr_start
|
311
313
|
end
|
312
314
|
|
313
315
|
# class << expr
|
314
|
-
rule /<</ do
|
316
|
+
rule %r/<</ do
|
315
317
|
token Operator
|
316
318
|
goto :expr_start
|
317
319
|
end
|
318
320
|
|
319
|
-
rule /[A-Z_]\w*/, Name::Class, :pop!
|
321
|
+
rule %r/[A-Z_]\w*/, Name::Class, :pop!
|
320
322
|
|
321
323
|
rule(//) { pop! }
|
322
324
|
end
|
@@ -328,11 +330,11 @@ module Rouge
|
|
328
330
|
end
|
329
331
|
|
330
332
|
state :defexpr do
|
331
|
-
rule /(\))(\.|::)?/ do
|
333
|
+
rule %r/(\))(\.|::)?/ do
|
332
334
|
groups Punctuation, Operator
|
333
335
|
pop!
|
334
336
|
end
|
335
|
-
rule /\(/ do
|
337
|
+
rule %r/\(/ do
|
336
338
|
token Punctuation
|
337
339
|
push :defexpr
|
338
340
|
push :expr_start
|
@@ -342,20 +344,20 @@ module Rouge
|
|
342
344
|
end
|
343
345
|
|
344
346
|
state :in_interp do
|
345
|
-
rule /}/, Str::Interpol, :pop!
|
347
|
+
rule %r/}/, Str::Interpol, :pop!
|
346
348
|
mixin :root
|
347
349
|
end
|
348
350
|
|
349
351
|
state :string_intp do
|
350
|
-
rule /[#][{]/, Str::Interpol, :in_interp
|
351
|
-
rule /#(@@?|\$)[a-z_]\w*/i, Str::Interpol
|
352
|
+
rule %r/[#][{]/, Str::Interpol, :in_interp
|
353
|
+
rule %r/#(@@?|\$)[a-z_]\w*/i, Str::Interpol
|
352
354
|
end
|
353
355
|
|
354
356
|
state :string_intp_escaped do
|
355
357
|
mixin :string_intp
|
356
|
-
rule /\\([\\abefnrstv#"']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})/,
|
358
|
+
rule %r/\\([\\abefnrstv#"']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})/,
|
357
359
|
Str::Escape
|
358
|
-
rule /\\./, Str::Escape
|
360
|
+
rule %r/\\./, Str::Escape
|
359
361
|
end
|
360
362
|
|
361
363
|
state :method_call do
|
@@ -408,7 +410,7 @@ module Rouge
|
|
408
410
|
|
409
411
|
# special case for using a single space. Ruby demands that
|
410
412
|
# these be in a single line, otherwise it would make no sense.
|
411
|
-
rule /(\s*)(%[rqswQWxiI]? \S* )/ do
|
413
|
+
rule %r/(\s*)(%[rqswQWxiI]? \S* )/ do
|
412
414
|
groups Text, Str::Other
|
413
415
|
pop!
|
414
416
|
end
|
@@ -432,7 +434,7 @@ module Rouge
|
|
432
434
|
|
433
435
|
state :end_part do
|
434
436
|
# eat up the rest of the stream as Comment::Preproc
|
435
|
-
rule /.+/m, Comment::Preproc, :pop!
|
437
|
+
rule %r/.+/m, Comment::Preproc, :pop!
|
436
438
|
end
|
437
439
|
end
|
438
440
|
end
|