rouge 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/bin/rougify +1 -1
- data/lib/rouge/demos/{text → plaintext} +0 -0
- data/lib/rouge/formatters/html.rb +13 -8
- data/lib/rouge/formatters/terminal256.rb +15 -11
- data/lib/rouge/lexer.rb +3 -1
- data/lib/rouge/lexers/c.rb +65 -55
- data/lib/rouge/lexers/clojure.rb +19 -19
- data/lib/rouge/lexers/coffeescript.rb +42 -42
- data/lib/rouge/lexers/common_lisp.rb +49 -48
- data/lib/rouge/lexers/conf.rb +6 -6
- data/lib/rouge/lexers/cpp.rb +48 -48
- data/lib/rouge/lexers/csharp.rb +25 -25
- data/lib/rouge/lexers/css.rb +32 -33
- data/lib/rouge/lexers/diff.rb +8 -8
- data/lib/rouge/lexers/elixir.rb +30 -30
- data/lib/rouge/lexers/erb.rb +5 -5
- data/lib/rouge/lexers/erlang.rb +38 -38
- data/lib/rouge/lexers/factor.rb +56 -56
- data/lib/rouge/lexers/gherkin.rb +27 -27
- data/lib/rouge/lexers/go.rb +21 -21
- data/lib/rouge/lexers/groovy.rb +32 -32
- data/lib/rouge/lexers/haml.rb +35 -35
- data/lib/rouge/lexers/handlebars.rb +27 -27
- data/lib/rouge/lexers/haskell.rb +78 -79
- data/lib/rouge/lexers/html.rb +28 -28
- data/lib/rouge/lexers/http.rb +13 -13
- data/lib/rouge/lexers/ini.rb +13 -13
- data/lib/rouge/lexers/io.rb +19 -19
- data/lib/rouge/lexers/java.rb +29 -29
- data/lib/rouge/lexers/javascript.rb +49 -52
- data/lib/rouge/lexers/literate_haskell.rb +5 -5
- data/lib/rouge/lexers/llvm.rb +14 -14
- data/lib/rouge/lexers/lua.rb +33 -33
- data/lib/rouge/lexers/make.rb +26 -26
- data/lib/rouge/lexers/markdown.rb +49 -49
- data/lib/rouge/lexers/nginx.rb +19 -19
- data/lib/rouge/lexers/perl.rb +53 -54
- data/lib/rouge/lexers/php.rb +42 -43
- data/lib/rouge/lexers/{text.rb → plain_text.rb} +3 -2
- data/lib/rouge/lexers/prolog.rb +19 -19
- data/lib/rouge/lexers/puppet.rb +40 -40
- data/lib/rouge/lexers/python.rb +63 -63
- data/lib/rouge/lexers/r.rb +15 -15
- data/lib/rouge/lexers/racket.rb +29 -29
- data/lib/rouge/lexers/ruby.rb +94 -97
- data/lib/rouge/lexers/rust.rb +37 -37
- data/lib/rouge/lexers/sass.rb +15 -15
- data/lib/rouge/lexers/sass/common.rb +144 -136
- data/lib/rouge/lexers/scheme.rb +25 -25
- data/lib/rouge/lexers/scss.rb +7 -7
- data/lib/rouge/lexers/sed.rb +39 -39
- data/lib/rouge/lexers/shell.rb +45 -45
- data/lib/rouge/lexers/smalltalk.rb +36 -36
- data/lib/rouge/lexers/sql.rb +27 -27
- data/lib/rouge/lexers/tcl.rb +34 -34
- data/lib/rouge/lexers/tex.rb +24 -24
- data/lib/rouge/lexers/toml.rb +18 -18
- data/lib/rouge/lexers/viml.rb +19 -19
- data/lib/rouge/lexers/xml.rb +16 -16
- data/lib/rouge/lexers/yaml.rb +78 -81
- data/lib/rouge/plugins/redcarpet.rb +1 -1
- data/lib/rouge/regex_lexer.rb +31 -14
- data/lib/rouge/template_lexer.rb +1 -1
- data/lib/rouge/theme.rb +12 -10
- data/lib/rouge/themes/thankful_eyes.rb +43 -43
- data/lib/rouge/token.rb +145 -148
- data/lib/rouge/version.rb +1 -1
- metadata +4 -4
data/lib/rouge/lexers/php.rb
CHANGED
@@ -58,103 +58,102 @@ module Rouge
|
|
58
58
|
end
|
59
59
|
|
60
60
|
state :root do
|
61
|
-
rule /<\?(php|=)?/,
|
61
|
+
rule /<\?(php|=)?/, Comment::Preproc, :php
|
62
62
|
rule(/.*?(?=<\?)|.*/m) { delegate parent }
|
63
63
|
end
|
64
64
|
|
65
65
|
state :php do
|
66
|
-
rule /\?>/,
|
66
|
+
rule /\?>/, Comment::Preproc, :pop!
|
67
67
|
# heredocs
|
68
|
-
rule /<<<('?)([a-z_]\w*)\1\n.*?\n\2;?\n/im,
|
69
|
-
rule /\s+/,
|
70
|
-
rule /#.*?\n/,
|
71
|
-
rule %r(//.*?\n),
|
68
|
+
rule /<<<('?)([a-z_]\w*)\1\n.*?\n\2;?\n/im, Str::Heredoc
|
69
|
+
rule /\s+/, Text
|
70
|
+
rule /#.*?\n/, Comment::Single
|
71
|
+
rule %r(//.*?\n), Comment::Single
|
72
72
|
# empty comment, otherwise seen as the start of a docstring
|
73
73
|
rule %r(/\*\*/)
|
74
|
-
rule %r(/\*\*.*?\*/)m,
|
75
|
-
rule %r(/\*.*?\*/)m,
|
74
|
+
rule %r(/\*\*.*?\*/)m, Str::Doc
|
75
|
+
rule %r(/\*.*?\*/)m, Comment::Multiline
|
76
76
|
rule /(->|::)(\s*)([a-zA-Z_][a-zA-Z0-9_]*)/ do
|
77
|
-
group
|
77
|
+
group Operator; group Text; group Name::Attribute
|
78
78
|
end
|
79
79
|
|
80
|
-
rule /[~!%^&*+=\|:.<>\/?@-]+/,
|
81
|
-
rule /[\[\]{}();,]+/,
|
82
|
-
rule /class\b/,
|
80
|
+
rule /[~!%^&*+=\|:.<>\/?@-]+/, Operator
|
81
|
+
rule /[\[\]{}();,]+/, Punctuation
|
82
|
+
rule /class\b/, Keyword, :classname
|
83
83
|
# anonymous functions
|
84
84
|
rule /(function)(\s*)(?=\()/ do
|
85
|
-
group
|
85
|
+
group Keyword; group Text
|
86
86
|
end
|
87
87
|
|
88
88
|
# named functions
|
89
89
|
rule /(function)(\s+)(&?)(\s*)/ do
|
90
|
-
group
|
90
|
+
group Keyword; group Text; group Operator; group Text
|
91
91
|
push :funcname
|
92
92
|
end
|
93
93
|
|
94
94
|
rule /(const)(\s+)([a-zA-Z_]\w*)/i do
|
95
|
-
group
|
95
|
+
group Keyword; group Text; group Name::Constant
|
96
96
|
end
|
97
97
|
|
98
|
-
rule /(true|false|null)\b/,
|
99
|
-
rule /\$\{\$+[a-z_]\w*\}/i,
|
100
|
-
rule /\$+[a-z_]\w*/i,
|
98
|
+
rule /(true|false|null)\b/, Keyword::Constant
|
99
|
+
rule /\$\{\$+[a-z_]\w*\}/i, Name::Variable
|
100
|
+
rule /\$+[a-z_]\w*/i, Name::Variable
|
101
101
|
|
102
102
|
# may be intercepted for builtin highlighting
|
103
103
|
rule /[\\a-z_][\\\w]*/i do |m|
|
104
104
|
name = m[0]
|
105
105
|
|
106
106
|
if self.class.keywords.include? name
|
107
|
-
token
|
107
|
+
token Keyword
|
108
108
|
elsif self.builtins.include? name
|
109
|
-
token
|
109
|
+
token Name::Builtin
|
110
110
|
else
|
111
|
-
token
|
111
|
+
token Name::Other
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
rule /(\d+\.\d*|\d*\.\d+)(e[+-]?\d+)?/i,
|
116
|
-
rule /\d+e[+-]?\d+/i,
|
117
|
-
rule /0[0-7]+/,
|
118
|
-
rule /0x[a-f0-9]+/i,
|
119
|
-
rule /\d+/,
|
120
|
-
rule /'([^'\\]*(?:\\.[^'\\]*)*)'/,
|
121
|
-
rule /`([^`\\]*(?:\\.[^`\\]*)*)`/,
|
122
|
-
rule /"/,
|
115
|
+
rule /(\d+\.\d*|\d*\.\d+)(e[+-]?\d+)?/i, Num::Float
|
116
|
+
rule /\d+e[+-]?\d+/i, Num::Float
|
117
|
+
rule /0[0-7]+/, Num::Oct
|
118
|
+
rule /0x[a-f0-9]+/i, Num::Hex
|
119
|
+
rule /\d+/, Num::Integer
|
120
|
+
rule /'([^'\\]*(?:\\.[^'\\]*)*)'/, Str::Single
|
121
|
+
rule /`([^`\\]*(?:\\.[^`\\]*)*)`/, Str::Backtick
|
122
|
+
rule /"/, Str::Double, :string
|
123
123
|
end
|
124
124
|
|
125
125
|
state :classname do
|
126
|
-
rule /\s+/,
|
127
|
-
rule /[a-z_][\\\w]*/i,
|
126
|
+
rule /\s+/, Text
|
127
|
+
rule /[a-z_][\\\w]*/i, Name::Class, :pop!
|
128
128
|
end
|
129
129
|
|
130
130
|
state :funcname do
|
131
|
-
rule /[a-z_]\w*/i,
|
131
|
+
rule /[a-z_]\w*/i, Name::Function, :pop!
|
132
132
|
end
|
133
133
|
|
134
134
|
state :string do
|
135
|
-
rule /"/,
|
136
|
-
rule /[^\\{$"]+/,
|
135
|
+
rule /"/, Str::Double, :pop!
|
136
|
+
rule /[^\\{$"]+/, Str::Double
|
137
137
|
rule /\\([nrt\"$\\]|[0-7]{1,3}|x[0-9A-Fa-f]{1,2})/,
|
138
|
-
|
139
|
-
rule /\$[a-zA-Z_][a-zA-Z0-9_]*(\[\S+\]|->[a-zA-Z_][a-zA-Z0-9_]*)?/,
|
138
|
+
Str::Escape
|
139
|
+
rule /\$[a-zA-Z_][a-zA-Z0-9_]*(\[\S+\]|->[a-zA-Z_][a-zA-Z0-9_]*)?/, Name::Variable
|
140
140
|
|
141
|
-
|
142
|
-
rule /\{
|
143
|
-
rule /\{(?=\$)/, lsi, :interp_single
|
141
|
+
rule /\{\$\{/, Str::Interpol, :interp_double
|
142
|
+
rule /\{(?=\$)/, Str::Interpol, :interp_single
|
144
143
|
rule /(\{)(\S+)(\})/ do
|
145
|
-
group
|
144
|
+
group Str::Interpol; group Name::Variable; group Str::Interpol
|
146
145
|
end
|
147
146
|
|
148
|
-
rule /[${\\]+/,
|
147
|
+
rule /[${\\]+/, Str::Double
|
149
148
|
end
|
150
149
|
|
151
150
|
state :interp_double do
|
152
|
-
rule /\}\}/,
|
151
|
+
rule /\}\}/, Str::Interpol, :pop!
|
153
152
|
mixin :php
|
154
153
|
end
|
155
154
|
|
156
155
|
state :interp_single do
|
157
|
-
rule /\}/,
|
156
|
+
rule /\}/, Str::Interpol, :pop!
|
158
157
|
mixin :php
|
159
158
|
end
|
160
159
|
end
|
data/lib/rouge/lexers/prolog.rb
CHANGED
@@ -13,35 +13,35 @@ module Rouge
|
|
13
13
|
end
|
14
14
|
|
15
15
|
state :basic do
|
16
|
-
rule /\s+/,
|
17
|
-
rule /^#.*/,
|
18
|
-
rule /\/\*/,
|
16
|
+
rule /\s+/, Text
|
17
|
+
rule /^#.*/, Comment::Single
|
18
|
+
rule /\/\*/, Comment::Multiline, :nested_comment
|
19
19
|
|
20
|
-
rule /[\[\](){}|.,;!]/,
|
21
|
-
rule /:-|-->/,
|
20
|
+
rule /[\[\](){}|.,;!]/, Punctuation
|
21
|
+
rule /:-|-->/, Punctuation
|
22
22
|
|
23
|
-
rule /"[^"]*"/,
|
23
|
+
rule /"[^"]*"/, Str::Double
|
24
24
|
|
25
|
-
rule /\d+\.\d+/,
|
26
|
-
rule /\d+/,
|
25
|
+
rule /\d+\.\d+/, Num::Float
|
26
|
+
rule /\d+/, Num
|
27
27
|
end
|
28
28
|
|
29
29
|
state :atoms do
|
30
|
-
rule /[[:lower:]]([_[:lower:][:digit:]])*/,
|
31
|
-
rule /'[^']*'/,
|
30
|
+
rule /[[:lower:]]([_[:lower:][:digit:]])*/, Str::Symbol
|
31
|
+
rule /'[^']*'/, Str::Symbol
|
32
32
|
end
|
33
33
|
|
34
34
|
state :operators do
|
35
35
|
rule /(<|>|=<|>=|==|=:=|=|\/|\/\/|\*|\+|-)(?=\s|[a-zA-Z0-9\[])/,
|
36
|
-
|
37
|
-
rule /is/,
|
38
|
-
rule /(mod|div|not)/,
|
39
|
-
rule /[#&*+-.\/:<=>?@^~]+/,
|
36
|
+
Operator
|
37
|
+
rule /is/, Operator
|
38
|
+
rule /(mod|div|not)/, Operator
|
39
|
+
rule /[#&*+-.\/:<=>?@^~]+/, Operator
|
40
40
|
end
|
41
41
|
|
42
42
|
state :variables do
|
43
|
-
rule /[A-Z]+\w*/,
|
44
|
-
rule /_[[:word:]]*/,
|
43
|
+
rule /[A-Z]+\w*/, Name::Variable
|
44
|
+
rule /_[[:word:]]*/, Name::Variable
|
45
45
|
end
|
46
46
|
|
47
47
|
state :root do
|
@@ -52,9 +52,9 @@ module Rouge
|
|
52
52
|
end
|
53
53
|
|
54
54
|
state :nested_comment do
|
55
|
-
rule /\/\*/,
|
56
|
-
rule /\s*\*[^*\/]+/,
|
57
|
-
rule /\*\//,
|
55
|
+
rule /\/\*/, Comment::Multiline, :push
|
56
|
+
rule /\s*\*[^*\/]+/, Comment::Multiline
|
57
|
+
rule /\*\//, Comment::Multiline, :pop!
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
data/lib/rouge/lexers/puppet.rb
CHANGED
@@ -35,91 +35,91 @@ module Rouge
|
|
35
35
|
qualname = /(::)?(#{id}::)*\w+/
|
36
36
|
|
37
37
|
state :whitespace do
|
38
|
-
rule /\s+/m,
|
39
|
-
rule /#.*?\n/,
|
38
|
+
rule /\s+/m, Text
|
39
|
+
rule /#.*?\n/, Comment
|
40
40
|
end
|
41
41
|
|
42
42
|
state :root do
|
43
43
|
mixin :whitespace
|
44
44
|
|
45
|
-
rule /[$]#{qualname}/,
|
45
|
+
rule /[$]#{qualname}/, Name::Variable
|
46
46
|
rule /(#{id})(?=\s*[=+]>)/m do |m|
|
47
47
|
if self.class.metaparameters.include? m[0]
|
48
|
-
token
|
48
|
+
token Keyword::Pseudo
|
49
49
|
else
|
50
|
-
token
|
50
|
+
token Name::Property
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
rule /(#{qualname})(?=\s*[(])/m,
|
55
|
-
rule cap_id,
|
54
|
+
rule /(#{qualname})(?=\s*[(])/m, Name::Function
|
55
|
+
rule cap_id, Name::Class
|
56
56
|
|
57
|
-
rule /[+=|~-]>|<[|~-]/,
|
58
|
-
rule /[:}();\[\]]/,
|
57
|
+
rule /[+=|~-]>|<[|~-]/, Punctuation
|
58
|
+
rule /[:}();\[\]]/, Punctuation
|
59
59
|
|
60
60
|
# HACK for case statements and selectors
|
61
|
-
rule /{/,
|
62
|
-
rule /,/,
|
61
|
+
rule /{/, Punctuation, :regex_allowed
|
62
|
+
rule /,/, Punctuation, :regex_allowed
|
63
63
|
|
64
|
-
rule /(in|and|or)\b/,
|
65
|
-
rule /[=!<>]=/,
|
66
|
-
rule /[=!]~/,
|
67
|
-
rule %r([<>!+*/-]),
|
64
|
+
rule /(in|and|or)\b/, Operator::Word
|
65
|
+
rule /[=!<>]=/, Operator
|
66
|
+
rule /[=!]~/, Operator, :regex_allowed
|
67
|
+
rule %r([<>!+*/-]), Operator
|
68
68
|
|
69
69
|
rule /(class|include)(\s*)(#{qualname})/ do
|
70
|
-
group
|
71
|
-
group
|
70
|
+
group Keyword; group Text
|
71
|
+
group Name::Class
|
72
72
|
end
|
73
73
|
|
74
|
-
rule /node\b/,
|
74
|
+
rule /node\b/, Keyword, :regex_allowed
|
75
75
|
|
76
|
-
rule /'(\\[\\']|[^'])*'/m,
|
77
|
-
rule /"/,
|
76
|
+
rule /'(\\[\\']|[^'])*'/m, Str::Single
|
77
|
+
rule /"/, Str::Double, :dquotes
|
78
78
|
|
79
|
-
rule /\d+([.]\d+)?(e[+-]\d+)?/,
|
79
|
+
rule /\d+([.]\d+)?(e[+-]\d+)?/, Num
|
80
80
|
|
81
81
|
# a valid regex. TODO: regexes are only allowed
|
82
82
|
# in certain places in puppet.
|
83
83
|
rule qualname do |m|
|
84
84
|
if self.class.keywords.include? m[0]
|
85
|
-
token
|
85
|
+
token Keyword
|
86
86
|
elsif self.class.constants.include? m[0]
|
87
|
-
token
|
87
|
+
token Keyword::Constant
|
88
88
|
else
|
89
|
-
token
|
89
|
+
token Name
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
94
|
state :regex_allowed do
|
95
95
|
mixin :whitespace
|
96
|
-
rule %r(/),
|
96
|
+
rule %r(/), Str::Regex, :regex
|
97
97
|
|
98
98
|
rule(//) { pop! }
|
99
99
|
end
|
100
100
|
|
101
101
|
state :regex do
|
102
|
-
rule %r(/),
|
103
|
-
rule /\\./,
|
104
|
-
rule /[(){}]/,
|
105
|
-
rule /\[/,
|
106
|
-
rule /./,
|
102
|
+
rule %r(/), Str::Regex, :pop!
|
103
|
+
rule /\\./, Str::Escape
|
104
|
+
rule /[(){}]/, Str::Interpol
|
105
|
+
rule /\[/, Str::Interpol, :regex_class
|
106
|
+
rule /./, Str::Regex
|
107
107
|
end
|
108
108
|
|
109
109
|
state :regex_class do
|
110
|
-
rule /\]/,
|
111
|
-
rule /(?<!\[)-(?=\])/,
|
112
|
-
rule /-/,
|
113
|
-
rule /\\./,
|
114
|
-
rule /[^\\\]-]+/,
|
110
|
+
rule /\]/, Str::Interpol, :pop!
|
111
|
+
rule /(?<!\[)-(?=\])/, Str::Regex
|
112
|
+
rule /-/, Str::Interpol
|
113
|
+
rule /\\./, Str::Escape
|
114
|
+
rule /[^\\\]-]+/, Str::Regex
|
115
115
|
end
|
116
116
|
|
117
117
|
state :dquotes do
|
118
|
-
rule /"/,
|
119
|
-
rule /[^$\\"]+/m,
|
120
|
-
rule /\\./m,
|
121
|
-
rule /[$]#{qualname}/,
|
122
|
-
rule /[$][{]#{qualname}[}]/,
|
118
|
+
rule /"/, Str::Double, :pop!
|
119
|
+
rule /[^$\\"]+/m, Str::Double
|
120
|
+
rule /\\./m, Str::Escape
|
121
|
+
rule /[$]#{qualname}/, Name::Variable
|
122
|
+
rule /[$][{]#{qualname}[}]/, Name::Variable
|
123
123
|
end
|
124
124
|
end
|
125
125
|
end
|
data/lib/rouge/lexers/python.rb
CHANGED
@@ -50,116 +50,116 @@ module Rouge
|
|
50
50
|
identifier = /[a-z_][a-z0-9_]*/i
|
51
51
|
dotted_identifier = /[a-z_.][a-z0-9_.]*/i
|
52
52
|
state :root do
|
53
|
-
rule /\n+/m,
|
53
|
+
rule /\n+/m, Text
|
54
54
|
rule /^(:)(\s*)([ru]{,2}""".*?""")/mi do
|
55
|
-
group
|
56
|
-
group
|
57
|
-
group
|
55
|
+
group Punctuation
|
56
|
+
group Text
|
57
|
+
group Str::Doc
|
58
58
|
end
|
59
59
|
|
60
|
-
rule /[^\S\n]+/,
|
61
|
-
rule /#.*$/,
|
62
|
-
rule /[\[\]{}:(),;]/,
|
63
|
-
rule /\\\n/,
|
64
|
-
rule /\\/,
|
60
|
+
rule /[^\S\n]+/, Text
|
61
|
+
rule /#.*$/, Comment
|
62
|
+
rule /[\[\]{}:(),;]/, Punctuation
|
63
|
+
rule /\\\n/, Text
|
64
|
+
rule /\\/, Text
|
65
65
|
|
66
|
-
rule /(in|is|and|or|not)\b/,
|
67
|
-
rule /!=|==|<<|>>|[-~+\/*%=<>&^|.]/,
|
66
|
+
rule /(in|is|and|or|not)\b/, Operator::Word
|
67
|
+
rule /!=|==|<<|>>|[-~+\/*%=<>&^|.]/, Operator
|
68
68
|
|
69
|
-
rule /(?:#{keywords.join('|')})\b/,
|
69
|
+
rule /(?:#{keywords.join('|')})\b/, Keyword
|
70
70
|
|
71
71
|
rule /(def)((?:\s|\\\s)+)/ do
|
72
|
-
group
|
73
|
-
group
|
72
|
+
group Keyword # def
|
73
|
+
group Text # whitespae
|
74
74
|
push :funcname
|
75
75
|
end
|
76
76
|
|
77
77
|
rule /(class)((?:\s|\\\s)+)/ do
|
78
|
-
group
|
79
|
-
group
|
78
|
+
group Keyword
|
79
|
+
group Text
|
80
80
|
push :classname
|
81
81
|
end
|
82
82
|
|
83
83
|
rule /(from)((?:\s|\\\s)+)/ do
|
84
|
-
group
|
85
|
-
group
|
84
|
+
group Keyword::Namespace
|
85
|
+
group Text
|
86
86
|
push :fromimport
|
87
87
|
end
|
88
88
|
|
89
89
|
rule /(import)((?:\s|\\\s)+)/ do
|
90
|
-
group
|
91
|
-
group
|
90
|
+
group Keyword::Namespace
|
91
|
+
group Text
|
92
92
|
push :import
|
93
93
|
end
|
94
94
|
|
95
95
|
# using negative lookbehind so we don't match property names
|
96
|
-
rule /(?<!\.)(?:#{builtins.join('|')})/,
|
97
|
-
rule /(?<!\.)(?:#{builtins_pseudo.join('|')})/,
|
96
|
+
rule /(?<!\.)(?:#{builtins.join('|')})/, Name::Builtin
|
97
|
+
rule /(?<!\.)(?:#{builtins_pseudo.join('|')})/, Name::Builtin::Pseudo
|
98
98
|
|
99
99
|
# TODO: not in python 3
|
100
|
-
rule /`.*?`/,
|
101
|
-
rule /(?:r|ur|ru)"""/i,
|
102
|
-
rule /(?:r|ur|ru)'''/i,
|
103
|
-
rule /(?:r|ur|ru)"/i,
|
104
|
-
rule /(?:r|ur|ru)'/i,
|
105
|
-
rule /u?"""/i,
|
106
|
-
rule /u?'''/i,
|
107
|
-
rule /u?"/i,
|
108
|
-
rule /u?'/i,
|
109
|
-
|
110
|
-
rule /@#{dotted_identifier}/i,
|
111
|
-
rule identifier,
|
112
|
-
|
113
|
-
rule /(\d+\.\d*|\d*\.\d+)(e[+-]?[0-9]+)?/i,
|
114
|
-
rule /\d+e[+-]?[0-9]+/i,
|
115
|
-
rule /0[0-7]+/,
|
116
|
-
rule /0x[a-f0-9]+/i,
|
117
|
-
rule /\d+L/,
|
118
|
-
rule /\d+/,
|
100
|
+
rule /`.*?`/, Str::Backtick
|
101
|
+
rule /(?:r|ur|ru)"""/i, Str, :tdqs
|
102
|
+
rule /(?:r|ur|ru)'''/i, Str, :tsqs
|
103
|
+
rule /(?:r|ur|ru)"/i, Str, :dqs
|
104
|
+
rule /(?:r|ur|ru)'/i, Str, :sqs
|
105
|
+
rule /u?"""/i, Str, :escape_tdqs
|
106
|
+
rule /u?'''/i, Str, :escape_tsqs
|
107
|
+
rule /u?"/i, Str, :escape_dqs
|
108
|
+
rule /u?'/i, Str, :escape_sqs
|
109
|
+
|
110
|
+
rule /@#{dotted_identifier}/i, Name::Decorator
|
111
|
+
rule identifier, Name
|
112
|
+
|
113
|
+
rule /(\d+\.\d*|\d*\.\d+)(e[+-]?[0-9]+)?/i, Num::Float
|
114
|
+
rule /\d+e[+-]?[0-9]+/i, Num::Float
|
115
|
+
rule /0[0-7]+/, Num::Oct
|
116
|
+
rule /0x[a-f0-9]+/i, Num::Hex
|
117
|
+
rule /\d+L/, Num::Integer::Long
|
118
|
+
rule /\d+/, Num::Integer
|
119
119
|
end
|
120
120
|
|
121
121
|
state :funcname do
|
122
|
-
rule identifier,
|
122
|
+
rule identifier, Name::Function, :pop!
|
123
123
|
end
|
124
124
|
|
125
125
|
state :classname do
|
126
|
-
rule identifier,
|
126
|
+
rule identifier, Name::Class, :pop!
|
127
127
|
end
|
128
128
|
|
129
129
|
state :import do
|
130
130
|
# non-line-terminating whitespace
|
131
|
-
rule /(?:[ \t]|\\\n)+/,
|
131
|
+
rule /(?:[ \t]|\\\n)+/, Text
|
132
132
|
|
133
|
-
rule /as\b/,
|
134
|
-
rule /,/,
|
135
|
-
rule dotted_identifier,
|
133
|
+
rule /as\b/, Keyword::Namespace
|
134
|
+
rule /,/, Operator
|
135
|
+
rule dotted_identifier, Name::Namespace
|
136
136
|
rule(//) { pop! } # anything else -> go back
|
137
137
|
end
|
138
138
|
|
139
139
|
state :fromimport do
|
140
140
|
# non-line-terminating whitespace
|
141
|
-
rule /(?:[ \t]|\\\n)+/,
|
141
|
+
rule /(?:[ \t]|\\\n)+/, Text
|
142
142
|
|
143
|
-
rule /import\b/,
|
144
|
-
rule dotted_identifier,
|
143
|
+
rule /import\b/, Keyword::Namespace, :pop!
|
144
|
+
rule dotted_identifier, Name::Namespace
|
145
145
|
end
|
146
146
|
|
147
147
|
state :strings do
|
148
|
-
rule /%(\([a-z0-9_]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?/i,
|
148
|
+
rule /%(\([a-z0-9_]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?/i, Str::Interpol
|
149
149
|
end
|
150
150
|
|
151
151
|
state :strings_double do
|
152
|
-
rule /[^\\"%\n]+/,
|
152
|
+
rule /[^\\"%\n]+/, Str
|
153
153
|
mixin :strings
|
154
154
|
end
|
155
155
|
|
156
156
|
state :strings_single do
|
157
|
-
rule /[^\\'%\n]+/,
|
157
|
+
rule /[^\\'%\n]+/, Str
|
158
158
|
mixin :strings
|
159
159
|
end
|
160
160
|
|
161
161
|
state :nl do
|
162
|
-
rule /\n/,
|
162
|
+
rule /\n/, Str
|
163
163
|
end
|
164
164
|
|
165
165
|
state :escape do
|
@@ -172,31 +172,31 @@ module Rouge
|
|
172
172
|
| x[a-fA-F0-9]{2}
|
173
173
|
| [0-7]{1,3}
|
174
174
|
)
|
175
|
-
)x,
|
175
|
+
)x, Str::Escape
|
176
176
|
end
|
177
177
|
|
178
178
|
state :dqs do
|
179
|
-
rule /"/,
|
180
|
-
rule /\\\\|\\"|\\\n/,
|
179
|
+
rule /"/, Str, :pop!
|
180
|
+
rule /\\\\|\\"|\\\n/, Str::Escape
|
181
181
|
mixin :strings_double
|
182
182
|
end
|
183
183
|
|
184
184
|
state :sqs do
|
185
|
-
rule /'/,
|
186
|
-
rule /\\\\|\\'|\\\n/,
|
185
|
+
rule /'/, Str, :pop!
|
186
|
+
rule /\\\\|\\'|\\\n/, Str::Escape
|
187
187
|
mixin :strings_single
|
188
188
|
end
|
189
189
|
|
190
190
|
state :tdqs do
|
191
|
-
rule /"""/,
|
192
|
-
rule /"/,
|
191
|
+
rule /"""/, Str, :pop!
|
192
|
+
rule /"/, Str
|
193
193
|
mixin :strings_double
|
194
194
|
mixin :nl
|
195
195
|
end
|
196
196
|
|
197
197
|
state :tsqs do
|
198
|
-
rule /'''/,
|
199
|
-
rule /'/,
|
198
|
+
rule /'''/, Str, :pop!
|
199
|
+
rule /'/, Str
|
200
200
|
mixin :strings_single
|
201
201
|
mixin :nl
|
202
202
|
end
|