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/ini.rb
CHANGED
@@ -15,39 +15,39 @@ module Rouge
|
|
15
15
|
identifier = /[\w\-.]+/
|
16
16
|
|
17
17
|
state :basic do
|
18
|
-
rule /[;#].*?\n/, Comment
|
19
|
-
rule /\s+/, Text
|
20
|
-
rule /\\\n/, Str::Escape
|
18
|
+
rule %r/[;#].*?\n/, Comment
|
19
|
+
rule %r/\s+/, Text
|
20
|
+
rule %r/\\\n/, Str::Escape
|
21
21
|
end
|
22
22
|
|
23
23
|
state :root do
|
24
24
|
mixin :basic
|
25
25
|
|
26
|
-
rule /(#{identifier})(\s*)(=)/ do
|
26
|
+
rule %r/(#{identifier})(\s*)(=)/ do
|
27
27
|
groups Name::Property, Text, Punctuation
|
28
28
|
push :value
|
29
29
|
end
|
30
30
|
|
31
|
-
rule /\[.*?\]/, Name::Namespace
|
31
|
+
rule %r/\[.*?\]/, Name::Namespace
|
32
32
|
end
|
33
33
|
|
34
34
|
state :value do
|
35
|
-
rule /\n/, Text, :pop!
|
35
|
+
rule %r/\n/, Text, :pop!
|
36
36
|
mixin :basic
|
37
|
-
rule /"/, Str, :dq
|
38
|
-
rule /'.*?'/, Str
|
37
|
+
rule %r/"/, Str, :dq
|
38
|
+
rule %r/'.*?'/, Str
|
39
39
|
mixin :esc_str
|
40
|
-
rule /[^\\\n]+/, Str
|
40
|
+
rule %r/[^\\\n]+/, Str
|
41
41
|
end
|
42
42
|
|
43
43
|
state :dq do
|
44
|
-
rule /"/, Str, :pop!
|
44
|
+
rule %r/"/, Str, :pop!
|
45
45
|
mixin :esc_str
|
46
|
-
rule /[^\\"]+/m, Str
|
46
|
+
rule %r/[^\\"]+/m, Str
|
47
47
|
end
|
48
48
|
|
49
49
|
state :esc_str do
|
50
|
-
rule /\\./m, Str::Escape
|
50
|
+
rule %r/\\./m, Str::Escape
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
data/lib/rouge/lexers/io.rb
CHANGED
@@ -26,22 +26,22 @@ module Rouge
|
|
26
26
|
end
|
27
27
|
|
28
28
|
state :root do
|
29
|
-
rule /\s+/m, Text
|
29
|
+
rule %r/\s+/m, Text
|
30
30
|
rule %r(//.*?\n), Comment::Single
|
31
31
|
rule %r(#.*?\n), Comment::Single
|
32
32
|
rule %r(/(\\\n)?[*].*?[*](\\\n)?/)m, Comment::Multiline
|
33
33
|
rule %r(/[+]), Comment::Multiline, :nested_comment
|
34
34
|
|
35
|
-
rule /"(\\\\|\\"|[^"])*"/, Str
|
35
|
+
rule %r/"(\\\\|\\"|[^"])*"/, Str
|
36
36
|
|
37
37
|
rule %r(:?:=), Keyword
|
38
|
-
rule /[()]/, Punctuation
|
38
|
+
rule %r/[()]/, Punctuation
|
39
39
|
|
40
40
|
rule %r([-=;,*+><!/|^.%&\[\]{}]), Operator
|
41
41
|
|
42
|
-
rule /[A-Z]\w*/, Name::Class
|
42
|
+
rule %r/[A-Z]\w*/, Name::Class
|
43
43
|
|
44
|
-
rule /[a-z_]\w*/ do |m|
|
44
|
+
rule %r/[a-z_]\w*/ do |m|
|
45
45
|
name = m[0]
|
46
46
|
|
47
47
|
if self.class.constants.include? name
|
@@ -54,9 +54,9 @@ module Rouge
|
|
54
54
|
end
|
55
55
|
|
56
56
|
rule %r((\d+[.]?\d*|\d*[.]\d+)(e[+-]?[0-9]+)?)i, Num::Float
|
57
|
-
rule /\d+/, Num::Integer
|
57
|
+
rule %r/\d+/, Num::Integer
|
58
58
|
|
59
|
-
rule /@@?/, Keyword
|
59
|
+
rule %r/@@?/, Keyword
|
60
60
|
end
|
61
61
|
|
62
62
|
state :nested_comment do
|
data/lib/rouge/lexers/irb.rb
CHANGED
@@ -41,25 +41,25 @@ module Rouge
|
|
41
41
|
|
42
42
|
state :has_irb_output do
|
43
43
|
rule %r(=>), Punctuation, :pop!
|
44
|
-
rule /.+?(\n|$)/, Generic::Output
|
44
|
+
rule %r/.+?(\n|$)/, Generic::Output
|
45
45
|
end
|
46
46
|
|
47
47
|
state :irb_error do
|
48
|
-
rule /.+?(\n|$)/, Generic::Error
|
48
|
+
rule %r/.+?(\n|$)/, Generic::Error
|
49
49
|
mixin :has_irb_output
|
50
50
|
end
|
51
51
|
|
52
52
|
state :stdout do
|
53
|
-
rule /\w+?(Error|Exception):.+?(\n|$)/, Generic::Error, :irb_error
|
53
|
+
rule %r/\w+?(Error|Exception):.+?(\n|$)/, Generic::Error, :irb_error
|
54
54
|
mixin :has_irb_output
|
55
55
|
end
|
56
56
|
|
57
57
|
prepend :root do
|
58
|
-
rule /#</, Keyword::Type, :irb_object
|
58
|
+
rule %r/#</, Keyword::Type, :irb_object
|
59
59
|
end
|
60
60
|
|
61
61
|
state :irb_object do
|
62
|
-
rule />/, Keyword::Type, :pop!
|
62
|
+
rule %r/>/, Keyword::Type, :pop!
|
63
63
|
mixin :root
|
64
64
|
end
|
65
65
|
end
|
data/lib/rouge/lexers/java.rb
CHANGED
@@ -28,12 +28,12 @@ module Rouge
|
|
28
28
|
class_name = /[A-Z][a-zA-Z0-9]*\b/
|
29
29
|
|
30
30
|
state :root do
|
31
|
-
rule /[^\S\n]+/, Text
|
31
|
+
rule %r/[^\S\n]+/, Text
|
32
32
|
rule %r(//.*?$), Comment::Single
|
33
33
|
rule %r(/\*.*?\*/)m, Comment::Multiline
|
34
34
|
# keywords: go before method names to avoid lexing "throw new XYZ"
|
35
35
|
# as a method signature
|
36
|
-
rule /(?:#{keywords.join('|')})\b/, Keyword
|
36
|
+
rule %r/(?:#{keywords.join('|')})\b/, Keyword
|
37
37
|
|
38
38
|
rule %r(
|
39
39
|
(\s*(?:[a-zA-Z_][a-zA-Z0-9_.\[\]<>]*\s+)+?) # return arguments
|
@@ -47,45 +47,45 @@ module Rouge
|
|
47
47
|
token Operator, m[4]
|
48
48
|
end
|
49
49
|
|
50
|
-
rule /@#{id}/, Name::Decorator
|
51
|
-
rule /(?:#{declarations.join('|')})\b/, Keyword::Declaration
|
52
|
-
rule /(?:#{types.join('|')})\b/, Keyword::Type
|
53
|
-
rule /package\b/, Keyword::Namespace
|
54
|
-
rule /(?:true|false|null)\b/, Keyword::Constant
|
55
|
-
rule /(?:class|interface)\b/, Keyword::Declaration, :class
|
56
|
-
rule /import\b/, Keyword::Namespace, :import
|
57
|
-
rule /"(\\\\|\\"|[^"])*"/, Str
|
58
|
-
rule /'(?:\\.|[^\\]|\\u[0-9a-f]{4})'/, Str::Char
|
59
|
-
rule /(\.)(#{id})/ do
|
50
|
+
rule %r/@#{id}/, Name::Decorator
|
51
|
+
rule %r/(?:#{declarations.join('|')})\b/, Keyword::Declaration
|
52
|
+
rule %r/(?:#{types.join('|')})\b/, Keyword::Type
|
53
|
+
rule %r/package\b/, Keyword::Namespace
|
54
|
+
rule %r/(?:true|false|null)\b/, Keyword::Constant
|
55
|
+
rule %r/(?:class|interface)\b/, Keyword::Declaration, :class
|
56
|
+
rule %r/import\b/, Keyword::Namespace, :import
|
57
|
+
rule %r/"(\\\\|\\"|[^"])*"/, Str
|
58
|
+
rule %r/'(?:\\.|[^\\]|\\u[0-9a-f]{4})'/, Str::Char
|
59
|
+
rule %r/(\.)(#{id})/ do
|
60
60
|
groups Operator, Name::Attribute
|
61
61
|
end
|
62
62
|
|
63
|
-
rule /#{id}:/, Name::Label
|
63
|
+
rule %r/#{id}:/, Name::Label
|
64
64
|
rule const_name, Name::Constant
|
65
65
|
rule class_name, Name::Class
|
66
|
-
rule /\$?#{id}/, Name
|
67
|
-
rule /[~^*!%&\[\](){}<>\|+=:;,.\/?-]/, Operator
|
66
|
+
rule %r/\$?#{id}/, Name
|
67
|
+
rule %r/[~^*!%&\[\](){}<>\|+=:;,.\/?-]/, Operator
|
68
68
|
|
69
69
|
digit = /[0-9]_+[0-9]|[0-9]/
|
70
70
|
bin_digit = /[01]_+[01]|[01]/
|
71
71
|
oct_digit = /[0-7]_+[0-7]|[0-7]/
|
72
72
|
hex_digit = /[0-9a-f]_+[0-9a-f]|[0-9a-f]/i
|
73
|
-
rule /#{digit}+\.#{digit}+([eE]#{digit}+)?[fd]?/, Num::Float
|
74
|
-
rule /0b#{bin_digit}+/i, Num::Bin
|
75
|
-
rule /0x#{hex_digit}+/i, Num::Hex
|
76
|
-
rule /0#{oct_digit}+/, Num::Oct
|
77
|
-
rule /#{digit}+L?/, Num::Integer
|
78
|
-
rule /\n/, Text
|
73
|
+
rule %r/#{digit}+\.#{digit}+([eE]#{digit}+)?[fd]?/, Num::Float
|
74
|
+
rule %r/0b#{bin_digit}+/i, Num::Bin
|
75
|
+
rule %r/0x#{hex_digit}+/i, Num::Hex
|
76
|
+
rule %r/0#{oct_digit}+/, Num::Oct
|
77
|
+
rule %r/#{digit}+L?/, Num::Integer
|
78
|
+
rule %r/\n/, Text
|
79
79
|
end
|
80
80
|
|
81
81
|
state :class do
|
82
|
-
rule /\s+/m, Text
|
82
|
+
rule %r/\s+/m, Text
|
83
83
|
rule id, Name::Class, :pop!
|
84
84
|
end
|
85
85
|
|
86
86
|
state :import do
|
87
|
-
rule /\s+/m, Text
|
88
|
-
rule /[a-z0-9_.]+\*?/i, Name::Namespace, :pop!
|
87
|
+
rule %r/\s+/m, Text
|
88
|
+
rule %r/[a-z0-9_.]+\*?/i, Name::Namespace, :pop!
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
@@ -32,8 +32,8 @@ module Rouge
|
|
32
32
|
end
|
33
33
|
|
34
34
|
state :comments_and_whitespace do
|
35
|
-
rule /\s+/, Text
|
36
|
-
rule /<!--/, Comment # really...?
|
35
|
+
rule %r/\s+/, Text
|
36
|
+
rule %r/<!--/, Comment # really...?
|
37
37
|
rule %r(//.*?$), Comment::Single
|
38
38
|
rule %r(/[*]), Comment::Multiline, :multiline_comment
|
39
39
|
end
|
@@ -46,12 +46,12 @@ module Rouge
|
|
46
46
|
goto :regex
|
47
47
|
end
|
48
48
|
|
49
|
-
rule /[{]/ do
|
49
|
+
rule %r/[{]/ do
|
50
50
|
token Punctuation
|
51
51
|
goto :object
|
52
52
|
end
|
53
53
|
|
54
|
-
rule //, Text, :pop!
|
54
|
+
rule %r//, Text, :pop!
|
55
55
|
end
|
56
56
|
|
57
57
|
state :regex do
|
@@ -62,38 +62,38 @@ module Rouge
|
|
62
62
|
|
63
63
|
rule %r([^/]\n), Error, :pop!
|
64
64
|
|
65
|
-
rule /\n/, Error, :pop!
|
66
|
-
rule /\[\^/, Str::Escape, :regex_group
|
67
|
-
rule /\[/, Str::Escape, :regex_group
|
68
|
-
rule /\\./, Str::Escape
|
65
|
+
rule %r/\n/, Error, :pop!
|
66
|
+
rule %r/\[\^/, Str::Escape, :regex_group
|
67
|
+
rule %r/\[/, Str::Escape, :regex_group
|
68
|
+
rule %r/\\./, Str::Escape
|
69
69
|
rule %r{[(][?][:=<!]}, Str::Escape
|
70
|
-
rule /[{][\d,]+[}]/, Str::Escape
|
71
|
-
rule /[()?]/, Str::Escape
|
72
|
-
rule /./, Str::Regex
|
70
|
+
rule %r/[{][\d,]+[}]/, Str::Escape
|
71
|
+
rule %r/[()?]/, Str::Escape
|
72
|
+
rule %r/./, Str::Regex
|
73
73
|
end
|
74
74
|
|
75
75
|
state :regex_end do
|
76
|
-
rule /[gim]+/, Str::Regex, :pop!
|
76
|
+
rule %r/[gim]+/, Str::Regex, :pop!
|
77
77
|
rule(//) { pop! }
|
78
78
|
end
|
79
79
|
|
80
80
|
state :regex_group do
|
81
81
|
# specially highlight / in a group to indicate that it doesn't
|
82
82
|
# close the regex
|
83
|
-
rule
|
83
|
+
rule %r(/), Str::Escape
|
84
84
|
|
85
85
|
rule %r([^/]\n) do
|
86
86
|
token Error
|
87
87
|
pop! 2
|
88
88
|
end
|
89
89
|
|
90
|
-
rule /\]/, Str::Escape, :pop!
|
91
|
-
rule /\\./, Str::Escape
|
92
|
-
rule /./, Str::Regex
|
90
|
+
rule %r/\]/, Str::Escape, :pop!
|
91
|
+
rule %r/\\./, Str::Escape
|
92
|
+
rule %r/./, Str::Regex
|
93
93
|
end
|
94
94
|
|
95
95
|
state :bad_regex do
|
96
|
-
rule /[^\n]+/, Error, :pop!
|
96
|
+
rule %r/[^\n]+/, Error, :pop!
|
97
97
|
end
|
98
98
|
|
99
99
|
def self.keywords
|
@@ -144,34 +144,34 @@ module Rouge
|
|
144
144
|
id = self.id_regex
|
145
145
|
|
146
146
|
state :root do
|
147
|
-
rule /\A\s*#!.*?\n/m, Comment::Preproc, :statement
|
147
|
+
rule %r/\A\s*#!.*?\n/m, Comment::Preproc, :statement
|
148
148
|
rule %r((?<=\n)(?=\s|/|<!--)), Text, :expr_start
|
149
149
|
mixin :comments_and_whitespace
|
150
150
|
rule %r(\+\+ | -- | ~ | && | \|\| | \\(?=\n) | << | >>>? | ===
|
151
151
|
| !== )x,
|
152
152
|
Operator, :expr_start
|
153
153
|
rule %r([-<>+*%&|\^/!=]=?), Operator, :expr_start
|
154
|
-
rule /[(\[,]/, Punctuation, :expr_start
|
155
|
-
rule /;/, Punctuation, :statement
|
156
|
-
rule /[)\].]/, Punctuation
|
154
|
+
rule %r/[(\[,]/, Punctuation, :expr_start
|
155
|
+
rule %r/;/, Punctuation, :statement
|
156
|
+
rule %r/[)\].]/, Punctuation
|
157
157
|
|
158
|
-
rule /`/ do
|
158
|
+
rule %r/`/ do
|
159
159
|
token Str::Double
|
160
160
|
push :template_string
|
161
161
|
end
|
162
162
|
|
163
|
-
rule /[?]/ do
|
163
|
+
rule %r/[?]/ do
|
164
164
|
token Punctuation
|
165
165
|
push :ternary
|
166
166
|
push :expr_start
|
167
167
|
end
|
168
168
|
|
169
|
-
rule /(\@)(\w+)?/ do
|
169
|
+
rule %r/(\@)(\w+)?/ do
|
170
170
|
groups Punctuation, Name::Decorator
|
171
171
|
push :expr_start
|
172
172
|
end
|
173
173
|
|
174
|
-
rule /[{}]/, Punctuation, :statement
|
174
|
+
rule %r/[{}]/, Punctuation, :statement
|
175
175
|
|
176
176
|
rule id do |m|
|
177
177
|
if self.class.keywords.include? m[0]
|
@@ -191,41 +191,41 @@ module Rouge
|
|
191
191
|
end
|
192
192
|
end
|
193
193
|
|
194
|
-
rule /[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?/, Num::Float
|
195
|
-
rule /0x[0-9a-fA-F]+/i, Num::Hex
|
196
|
-
rule /0o[0-7][0-7_]*/i, Num::Oct
|
197
|
-
rule /0b[01][01_]*/i, Num::Bin
|
198
|
-
rule /[0-9]+/, Num::Integer
|
194
|
+
rule %r/[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?/, Num::Float
|
195
|
+
rule %r/0x[0-9a-fA-F]+/i, Num::Hex
|
196
|
+
rule %r/0o[0-7][0-7_]*/i, Num::Oct
|
197
|
+
rule %r/0b[01][01_]*/i, Num::Bin
|
198
|
+
rule %r/[0-9]+/, Num::Integer
|
199
199
|
|
200
|
-
rule /"/, Str::Delimiter, :dq
|
201
|
-
rule /'/, Str::Delimiter, :sq
|
202
|
-
rule /:/, Punctuation
|
200
|
+
rule %r/"/, Str::Delimiter, :dq
|
201
|
+
rule %r/'/, Str::Delimiter, :sq
|
202
|
+
rule %r/:/, Punctuation
|
203
203
|
end
|
204
204
|
|
205
205
|
state :dq do
|
206
|
-
rule /\\[\\nrt"]?/, Str::Escape
|
207
|
-
rule /[^\\"]+/, Str::Double
|
208
|
-
rule /"/, Str::Delimiter, :pop!
|
206
|
+
rule %r/\\[\\nrt"]?/, Str::Escape
|
207
|
+
rule %r/[^\\"]+/, Str::Double
|
208
|
+
rule %r/"/, Str::Delimiter, :pop!
|
209
209
|
end
|
210
210
|
|
211
211
|
state :sq do
|
212
|
-
rule /\\[\\nrt']?/, Str::Escape
|
213
|
-
rule /[^\\']+/, Str::Single
|
214
|
-
rule /'/, Str::Delimiter, :pop!
|
212
|
+
rule %r/\\[\\nrt']?/, Str::Escape
|
213
|
+
rule %r/[^\\']+/, Str::Single
|
214
|
+
rule %r/'/, Str::Delimiter, :pop!
|
215
215
|
end
|
216
216
|
|
217
217
|
# braced parts that aren't object literals
|
218
218
|
state :statement do
|
219
|
-
rule /case\b/ do
|
219
|
+
rule %r/case\b/ do
|
220
220
|
token Keyword
|
221
221
|
goto :expr_start
|
222
222
|
end
|
223
223
|
|
224
|
-
rule /(#{id})(\s*)(:)/ do
|
224
|
+
rule %r/(#{id})(\s*)(:)/ do
|
225
225
|
groups Name::Label, Text, Punctuation
|
226
226
|
end
|
227
227
|
|
228
|
-
rule /[{}]/, Punctuation
|
228
|
+
rule %r/[{}]/, Punctuation
|
229
229
|
|
230
230
|
mixin :expr_start
|
231
231
|
end
|
@@ -234,28 +234,28 @@ module Rouge
|
|
234
234
|
state :object do
|
235
235
|
mixin :comments_and_whitespace
|
236
236
|
|
237
|
-
rule /[{]/ do
|
237
|
+
rule %r/[{]/ do
|
238
238
|
token Punctuation
|
239
239
|
push
|
240
240
|
end
|
241
241
|
|
242
|
-
rule /[}]/ do
|
242
|
+
rule %r/[}]/ do
|
243
243
|
token Punctuation
|
244
244
|
goto :statement
|
245
245
|
end
|
246
246
|
|
247
|
-
rule /(#{id})(\s*)(:)/ do
|
247
|
+
rule %r/(#{id})(\s*)(:)/ do
|
248
248
|
groups Name::Attribute, Text, Punctuation
|
249
249
|
push :expr_start
|
250
250
|
end
|
251
251
|
|
252
|
-
rule /:/, Punctuation
|
252
|
+
rule %r/:/, Punctuation
|
253
253
|
mixin :root
|
254
254
|
end
|
255
255
|
|
256
256
|
# ternary expressions, where <id>: is not a label!
|
257
257
|
state :ternary do
|
258
|
-
rule /:/ do
|
258
|
+
rule %r/:/ do
|
259
259
|
token Punctuation
|
260
260
|
goto :expr_start
|
261
261
|
end
|
@@ -265,13 +265,13 @@ module Rouge
|
|
265
265
|
|
266
266
|
# template strings
|
267
267
|
state :template_string do
|
268
|
-
rule /\${/, Punctuation, :template_string_expr
|
269
|
-
rule /`/, Str::Double, :pop!
|
270
|
-
rule /(\\\\|\\[\$`]|[^\$`]|\$(?!{))*/, Str::Double
|
268
|
+
rule %r/\${/, Punctuation, :template_string_expr
|
269
|
+
rule %r/`/, Str::Double, :pop!
|
270
|
+
rule %r/(\\\\|\\[\$`]|[^\$`]|\$(?!{))*/, Str::Double
|
271
271
|
end
|
272
272
|
|
273
273
|
state :template_string_expr do
|
274
|
-
rule /}/, Punctuation, :pop!
|
274
|
+
rule %r/}/, Punctuation, :pop!
|
275
275
|
mixin :root
|
276
276
|
end
|
277
277
|
end
|
data/lib/rouge/lexers/jinja.rb
CHANGED
@@ -37,16 +37,16 @@ module Rouge
|
|
37
37
|
|
38
38
|
state :root do
|
39
39
|
# Comments
|
40
|
-
rule /{#/, Comment, :comment
|
40
|
+
rule %r/{#/, Comment, :comment
|
41
41
|
|
42
42
|
# Statements
|
43
|
-
rule /\{\%/ do
|
43
|
+
rule %r/\{\%/ do
|
44
44
|
token Comment::Preproc
|
45
45
|
push :statement
|
46
46
|
end
|
47
47
|
|
48
48
|
# Expressions
|
49
|
-
rule /\{\{/ do
|
49
|
+
rule %r/\{\{/ do
|
50
50
|
token Comment::Preproc
|
51
51
|
push :expression
|
52
52
|
end
|
@@ -57,42 +57,42 @@ module Rouge
|
|
57
57
|
|
58
58
|
state :filter do
|
59
59
|
# Filters are called like variable|foo(arg1, ...)
|
60
|
-
rule /(\|)(\w+)/ do
|
60
|
+
rule %r/(\|)(\w+)/ do
|
61
61
|
groups Operator, Name::Function
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
state :function do
|
66
|
-
rule /(\w+)(\()/ do
|
66
|
+
rule %r/(\w+)(\()/ do
|
67
67
|
groups Name::Function, Punctuation
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
71
|
state :text do
|
72
|
-
rule /\s+/m, Text
|
72
|
+
rule %r/\s+/m, Text
|
73
73
|
end
|
74
74
|
|
75
75
|
state :literal do
|
76
76
|
# Strings
|
77
|
-
rule /"(\\.|.)*?"/, Str::Double
|
78
|
-
rule /'(\\.|.)*?'/, Str::Single
|
77
|
+
rule %r/"(\\.|.)*?"/, Str::Double
|
78
|
+
rule %r/'(\\.|.)*?'/, Str::Single
|
79
79
|
|
80
80
|
# Numbers
|
81
|
-
rule /\d+(?=}\s)/, Num
|
81
|
+
rule %r/\d+(?=}\s)/, Num
|
82
82
|
|
83
83
|
# Arithmetic operators (+, -, *, **, //, /)
|
84
84
|
# TODO : implement modulo (%)
|
85
|
-
rule /(\+|\-|\*|\/\/?|\*\*?|=)/, Operator
|
85
|
+
rule %r/(\+|\-|\*|\/\/?|\*\*?|=)/, Operator
|
86
86
|
|
87
87
|
# Comparisons operators (<=, <, >=, >, ==, ===, !=)
|
88
|
-
rule /(<=?|>=?|===?|!=)/, Operator
|
88
|
+
rule %r/(<=?|>=?|===?|!=)/, Operator
|
89
89
|
|
90
90
|
# Punctuation (the comma, [], ())
|
91
|
-
rule /,/, Punctuation
|
92
|
-
rule /\[/, Punctuation
|
93
|
-
rule /\]/, Punctuation
|
94
|
-
rule /\(/, Punctuation
|
95
|
-
rule /\)/, Punctuation
|
91
|
+
rule %r/,/, Punctuation
|
92
|
+
rule %r/\[/, Punctuation
|
93
|
+
rule %r/\]/, Punctuation
|
94
|
+
rule %r/\(/, Punctuation
|
95
|
+
rule %r/\)/, Punctuation
|
96
96
|
end
|
97
97
|
|
98
98
|
state :comment do
|
@@ -101,23 +101,23 @@ module Rouge
|
|
101
101
|
end
|
102
102
|
|
103
103
|
state :expression do
|
104
|
-
rule /\w+\.?/m, Name::Variable
|
104
|
+
rule %r/\w+\.?/m, Name::Variable
|
105
105
|
|
106
106
|
mixin :filter
|
107
107
|
mixin :function
|
108
108
|
mixin :literal
|
109
109
|
mixin :text
|
110
110
|
|
111
|
-
rule /%}|}}/, Comment::Preproc, :pop!
|
111
|
+
rule %r/%}|}}/, Comment::Preproc, :pop!
|
112
112
|
end
|
113
113
|
|
114
114
|
state :statement do
|
115
|
-
rule /(raw|verbatim)(\s+)(\%\})/ do
|
115
|
+
rule %r/(raw|verbatim)(\s+)(\%\})/ do
|
116
116
|
groups Keyword, Text, Comment::Preproc
|
117
117
|
goto :raw
|
118
118
|
end
|
119
119
|
|
120
|
-
rule /(\w+\.?)/ do |m|
|
120
|
+
rule %r/(\w+\.?)/ do |m|
|
121
121
|
if self.class.keywords.include?(m[0])
|
122
122
|
groups Keyword
|
123
123
|
elsif self.class.pseudo_keywords.include?(m[0])
|
@@ -136,7 +136,7 @@ module Rouge
|
|
136
136
|
mixin :literal
|
137
137
|
mixin :text
|
138
138
|
|
139
|
-
rule /\%\}/, Comment::Preproc, :pop!
|
139
|
+
rule %r/\%\}/, Comment::Preproc, :pop!
|
140
140
|
end
|
141
141
|
|
142
142
|
state :raw do
|
@@ -145,7 +145,7 @@ module Rouge
|
|
145
145
|
pop!
|
146
146
|
end
|
147
147
|
|
148
|
-
rule /(.+?)/m, Text
|
148
|
+
rule %r/(.+?)/m, Text
|
149
149
|
end
|
150
150
|
end
|
151
151
|
end
|