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/diff.rb
CHANGED
@@ -16,17 +16,17 @@ module Rouge
|
|
16
16
|
end
|
17
17
|
|
18
18
|
state :header do
|
19
|
-
rule /^diff .*?\n(?=---|\+\+\+)/m,
|
20
|
-
rule /^--- .*?\n/,
|
21
|
-
rule /^\+\+\+ .*?\n/,
|
19
|
+
rule /^diff .*?\n(?=---|\+\+\+)/m, Generic::Heading
|
20
|
+
rule /^--- .*?\n/, Generic::Deleted
|
21
|
+
rule /^\+\+\+ .*?\n/, Generic::Inserted
|
22
22
|
end
|
23
23
|
|
24
24
|
state :diff do
|
25
|
-
rule /@@ -\d+,\d+ \+\d+,\d+ @@.*?\n/,
|
26
|
-
rule /^\+.*?\n/,
|
27
|
-
rule /^-.*?\n/,
|
28
|
-
rule /^ .*?\n/,
|
29
|
-
rule /^.*?\n/,
|
25
|
+
rule /@@ -\d+,\d+ \+\d+,\d+ @@.*?\n/, Generic::Heading
|
26
|
+
rule /^\+.*?\n/, Generic::Inserted
|
27
|
+
rule /^-.*?\n/, Generic::Deleted
|
28
|
+
rule /^ .*?\n/, Text
|
29
|
+
rule /^.*?\n/, Error
|
30
30
|
end
|
31
31
|
|
32
32
|
state :root do
|
data/lib/rouge/lexers/elixir.rb
CHANGED
@@ -19,40 +19,40 @@ module Rouge
|
|
19
19
|
]
|
20
20
|
|
21
21
|
state :root do
|
22
|
-
rule /\s+/m,
|
23
|
-
rule /#.*$/,
|
22
|
+
rule /\s+/m, Text
|
23
|
+
rule /#.*$/, Comment::Single
|
24
24
|
rule %r{\b(case|cond|end|bc|lc|if|unless|try|loop|receive|fn|defmodule|
|
25
25
|
defp?|defprotocol|defimpl|defrecord|defmacrop?|defdelegate|
|
26
26
|
defexception|exit|raise|throw|unless|after|rescue|catch|else)\b(?![?!])|
|
27
|
-
(?<!\.)\b(do|\-\>)\b}x,
|
28
|
-
rule /\b(import|require|use|recur|quote|unquote|super|refer)\b(?![?!])/,
|
29
|
-
rule /(?<!\.)\b(and|not|or|when|xor|in)\b/,
|
27
|
+
(?<!\.)\b(do|\-\>)\b}x, Keyword
|
28
|
+
rule /\b(import|require|use|recur|quote|unquote|super|refer)\b(?![?!])/, Keyword::Namespace
|
29
|
+
rule /(?<!\.)\b(and|not|or|when|xor|in)\b/, Operator::Word
|
30
30
|
rule %r{%=|\*=|\*\*=|\+=|\-=|\^=|\|\|=|
|
31
31
|
<=>|<(?!<|=)|>(?!<|=|>)|<=|>=|===|==|=~|!=|!~|(?=[\s\t])\?|
|
32
32
|
(?<=[\s\t])!+|&&|\|\||\^|\*|\+|\-|/|
|
33
|
-
\||\+\+|\-\-|\*\*|\/\/|\<\-|\<\>|<<|>>|=|\.}x,
|
33
|
+
\||\+\+|\-\-|\*\*|\/\/|\<\-|\<\>|<<|>>|=|\.}x, Operator
|
34
34
|
rule %r{(?<!:)(:)([a-zA-Z_]\w*([?!]|=(?![>=]))?|\<\>|===?|>=?|<=?|
|
35
35
|
<=>|&&?|%\(\)|%\[\]|%\{\}|\+\+?|\-\-?|\|\|?|\!|//|[%&`/\|]|
|
36
|
-
\*\*?|=?~|<\-)|([a-zA-Z_]\w*([?!])?)(:)(?!:)},
|
37
|
-
rule /:"/,
|
38
|
-
rule /\b(nil|true|false)\b(?![?!])|\b[A-Z]\w*\b/,
|
39
|
-
rule /\b(__(FILE|LINE|MODULE|MAIN|FUNCTION)__)\b(?![?!])/,
|
40
|
-
rule /[a-zA-Z_!][\w_]*[!\?]?/,
|
41
|
-
rule %r{::|[(){};,/\|:\\\[\]]},
|
42
|
-
rule /@[a-zA-Z_]\w*|&\d/,
|
36
|
+
\*\*?|=?~|<\-)|([a-zA-Z_]\w*([?!])?)(:)(?!:)}, Str::Symbol
|
37
|
+
rule /:"/, Str::Symbol, :interpoling_symbol
|
38
|
+
rule /\b(nil|true|false)\b(?![?!])|\b[A-Z]\w*\b/, Name::Constant
|
39
|
+
rule /\b(__(FILE|LINE|MODULE|MAIN|FUNCTION)__)\b(?![?!])/, Name::Builtin::Pseudo
|
40
|
+
rule /[a-zA-Z_!][\w_]*[!\?]?/, Name
|
41
|
+
rule %r{::|[(){};,/\|:\\\[\]]}, Punctuation
|
42
|
+
rule /@[a-zA-Z_]\w*|&\d/, Name::Variable
|
43
43
|
rule %r{\b(0[xX][0-9A-Fa-f]+|\d(_?\d)*(\.(?![^\d\s])
|
44
|
-
(_?\d)*)?([eE][-+]?\d(_?\d)*)?|0[bB][01]+)\b}x,
|
45
|
-
rule %r{%r\/.*\/},
|
44
|
+
(_?\d)*)?([eE][-+]?\d(_?\d)*)?|0[bB][01]+)\b}x, Num
|
45
|
+
rule %r{%r\/.*\/}, Str::Regex
|
46
46
|
|
47
47
|
mixin :strings
|
48
48
|
end
|
49
49
|
|
50
50
|
state :strings do
|
51
|
-
rule /(%[A-Ba-z])?"""(?:.|\n)*?"""/,
|
52
|
-
rule /'''(?:.|\n)*?'''/,
|
53
|
-
rule /"/,
|
54
|
-
rule /'.*?'/,
|
55
|
-
rule %r{(?<!\w)\?(\\(x\d{1,2}|\h{1,2}(?!\h)\b|0[0-7]{0,2}(?![0-7])\b[^x0MC])|(\\[MC]-)+\w|[^\s\\])},
|
51
|
+
rule /(%[A-Ba-z])?"""(?:.|\n)*?"""/, Str::Doc
|
52
|
+
rule /'''(?:.|\n)*?'''/, Str::Doc
|
53
|
+
rule /"/, Str::Doc, :dqs
|
54
|
+
rule /'.*?'/, Str::Single
|
55
|
+
rule %r{(?<!\w)\?(\\(x\d{1,2}|\h{1,2}(?!\h)\b|0[0-7]{0,2}(?![0-7])\b[^x0MC])|(\\[MC]-)+\w|[^\s\\])}, Str::Other
|
56
56
|
|
57
57
|
BRACES.each do |_, _, name|
|
58
58
|
mixin :"braces_#{name}"
|
@@ -61,43 +61,43 @@ module Rouge
|
|
61
61
|
|
62
62
|
BRACES.each do |lbrace, rbrace, name|
|
63
63
|
state :"braces_#{name}" do
|
64
|
-
rule /%[a-z]#{lbrace}/,
|
65
|
-
rule /%[A-Z]#{lbrace}/,
|
64
|
+
rule /%[a-z]#{lbrace}/, Str::Double, :"braces_#{name}_intp"
|
65
|
+
rule /%[A-Z]#{lbrace}/, Str::Double, :"braces_#{name}_no_intp"
|
66
66
|
end
|
67
67
|
|
68
68
|
state :"braces_#{name}_intp" do
|
69
|
-
rule /#{rbrace}[a-z]*/,
|
69
|
+
rule /#{rbrace}[a-z]*/, Str::Double, :pop!
|
70
70
|
mixin :enddoublestr
|
71
71
|
end
|
72
72
|
|
73
73
|
state :"braces_#{name}_no_intp" do
|
74
|
-
rule /.*#{rbrace}[a-z]*/,
|
74
|
+
rule /.*#{rbrace}[a-z]*/, Str::Double, :pop!
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
78
|
state :dqs do
|
79
|
-
rule /"/,
|
79
|
+
rule /"/, Str::Double, :pop!
|
80
80
|
mixin :enddoublestr
|
81
81
|
end
|
82
82
|
|
83
83
|
state :interpoling do
|
84
|
-
rule /#\{/,
|
84
|
+
rule /#\{/, Str::Interpol, :interpoling_string
|
85
85
|
end
|
86
86
|
|
87
87
|
state :interpoling_string do
|
88
|
-
rule /\}/,
|
88
|
+
rule /\}/, Str::Interpol, :pop!
|
89
89
|
mixin :root
|
90
90
|
end
|
91
91
|
|
92
92
|
state :interpoling_symbol do
|
93
|
-
rule /"/,
|
93
|
+
rule /"/, Str::Symbol, :pop!
|
94
94
|
mixin :interpoling
|
95
|
-
rule /[^#"]+/,
|
95
|
+
rule /[^#"]+/, Str::Symbol
|
96
96
|
end
|
97
97
|
|
98
98
|
state :enddoublestr do
|
99
99
|
mixin :interpoling
|
100
|
-
rule /[^#"]+/,
|
100
|
+
rule /[^#"]+/, Str::Double
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
data/lib/rouge/lexers/erb.rb
CHANGED
@@ -27,9 +27,9 @@ module Rouge
|
|
27
27
|
close = /%%>|-%>|%>/
|
28
28
|
|
29
29
|
state :root do
|
30
|
-
rule /<%#/,
|
30
|
+
rule /<%#/, Comment, :comment
|
31
31
|
|
32
|
-
rule open,
|
32
|
+
rule open, Comment::Preproc, :ruby
|
33
33
|
|
34
34
|
rule /.+?(?=#{open})|.+/m do
|
35
35
|
delegate parent
|
@@ -37,12 +37,12 @@ module Rouge
|
|
37
37
|
end
|
38
38
|
|
39
39
|
state :comment do
|
40
|
-
rule close,
|
41
|
-
rule /.+(?=#{close})|.+/m,
|
40
|
+
rule close, Comment, :pop!
|
41
|
+
rule /.+(?=#{close})|.+/m, Comment
|
42
42
|
end
|
43
43
|
|
44
44
|
state :ruby do
|
45
|
-
rule close,
|
45
|
+
rule close, Comment::Preproc, :pop!
|
46
46
|
|
47
47
|
rule /.+?(?=#{close})|.+/m do
|
48
48
|
delegate @ruby_lexer
|
data/lib/rouge/lexers/erlang.rb
CHANGED
@@ -64,60 +64,60 @@ module Rouge
|
|
64
64
|
base_re = %r{(?:[2-9]|[12][0-9]|3[0-6])}
|
65
65
|
|
66
66
|
state :root do
|
67
|
-
rule(/\s+/,
|
68
|
-
rule(/%.*\n/,
|
69
|
-
rule(%r{(#{keywords.join('|')})\b},
|
70
|
-
rule(%r{(#{builtins.join('|')})\b},
|
71
|
-
rule(%r{(#{word_operators.join('|')})\b},
|
72
|
-
rule(/^-/,
|
73
|
-
rule(operators,
|
74
|
-
rule(/"/,
|
75
|
-
rule(/<</,
|
76
|
-
rule(/>>/,
|
67
|
+
rule(/\s+/, Text)
|
68
|
+
rule(/%.*\n/, Comment)
|
69
|
+
rule(%r{(#{keywords.join('|')})\b}, Keyword)
|
70
|
+
rule(%r{(#{builtins.join('|')})\b}, Name::Builtin)
|
71
|
+
rule(%r{(#{word_operators.join('|')})\b}, Operator::Word)
|
72
|
+
rule(/^-/, Punctuation, :directive)
|
73
|
+
rule(operators, Operator)
|
74
|
+
rule(/"/, Str, :string)
|
75
|
+
rule(/<</, Name::Label)
|
76
|
+
rule(/>>/, Name::Label)
|
77
77
|
rule %r{(#{atom_re})(:)} do
|
78
|
-
group
|
79
|
-
group
|
78
|
+
group Name::Namespace
|
79
|
+
group Punctuation
|
80
80
|
end
|
81
81
|
rule %r{(?:^|(?<=:))(#{atom_re})(\s*)(\()} do
|
82
|
-
group
|
83
|
-
group
|
84
|
-
group
|
82
|
+
group Name::Function
|
83
|
+
group Text
|
84
|
+
group Punctuation
|
85
85
|
end
|
86
|
-
rule(%r{[+-]?#{base_re}#[0-9a-zA-Z]+},
|
87
|
-
rule(/[+-]?\d+/,
|
88
|
-
rule(/[+-]?\d+.\d+/,
|
89
|
-
rule(%r{[\]\[:_@\".{}()|;,]},
|
90
|
-
rule(variable_re,
|
91
|
-
rule(atom_re,
|
92
|
-
rule(%r{\?#{macro_re}},
|
93
|
-
rule(%r{\$(?:#{escape_re}|\\[ %]|[^\\])},
|
94
|
-
rule(%r{##{atom_re}(:?\.#{atom_re})?},
|
86
|
+
rule(%r{[+-]?#{base_re}#[0-9a-zA-Z]+}, Num::Integer)
|
87
|
+
rule(/[+-]?\d+/, Num::Integer)
|
88
|
+
rule(/[+-]?\d+.\d+/, Num::Float)
|
89
|
+
rule(%r{[\]\[:_@\".{}()|;,]}, Punctuation)
|
90
|
+
rule(variable_re, Name::Variable)
|
91
|
+
rule(atom_re, Name)
|
92
|
+
rule(%r{\?#{macro_re}}, Name::Constant)
|
93
|
+
rule(%r{\$(?:#{escape_re}|\\[ %]|[^\\])}, Str::Char)
|
94
|
+
rule(%r{##{atom_re}(:?\.#{atom_re})?}, Name::Label)
|
95
95
|
end
|
96
96
|
|
97
97
|
state :string do
|
98
|
-
rule(escape_re,
|
99
|
-
rule(/"/,
|
100
|
-
rule(%r{~[0-9.*]*[~#+bBcdefginpPswWxX]},
|
101
|
-
rule(%r{[^"\\~]+},
|
102
|
-
rule(/~/,
|
98
|
+
rule(escape_re, Str::Escape)
|
99
|
+
rule(/"/, Str, :pop!)
|
100
|
+
rule(%r{~[0-9.*]*[~#+bBcdefginpPswWxX]}, Str::Interpol)
|
101
|
+
rule(%r{[^"\\~]+}, Str)
|
102
|
+
rule(/~/, Str)
|
103
103
|
end
|
104
104
|
|
105
105
|
state :directive do
|
106
106
|
rule %r{(define)(\s*)(\()(#{macro_re})} do
|
107
|
-
group
|
108
|
-
group
|
109
|
-
group
|
110
|
-
group
|
107
|
+
group Name::Entity
|
108
|
+
group Text
|
109
|
+
group Punctuation
|
110
|
+
group Name::Constant
|
111
111
|
pop!
|
112
112
|
end
|
113
113
|
rule %r{(record)(\s*)(\()(#{macro_re})} do
|
114
|
-
group
|
115
|
-
group
|
116
|
-
group
|
117
|
-
group
|
114
|
+
group Name::Entity
|
115
|
+
group Text
|
116
|
+
group Punctuation
|
117
|
+
group Name::Label
|
118
118
|
pop!
|
119
119
|
end
|
120
|
-
rule(atom_re,
|
120
|
+
rule(atom_re, Name::Entity, :pop!)
|
121
121
|
end
|
122
122
|
end
|
123
123
|
end
|
data/lib/rouge/lexers/factor.rb
CHANGED
@@ -163,135 +163,135 @@ module Rouge
|
|
163
163
|
end
|
164
164
|
|
165
165
|
state :root do
|
166
|
-
rule /\s+/m,
|
166
|
+
rule /\s+/m, Text
|
167
167
|
|
168
168
|
rule /(:|::|MACRO:|MEMO:|GENERIC:|HELP:)(\s+)(\S+)/m do
|
169
|
-
group
|
170
|
-
group
|
169
|
+
group Keyword; group Text
|
170
|
+
group Name::Function
|
171
171
|
end
|
172
172
|
|
173
173
|
rule /(M:|HOOK:|GENERIC#)(\s+)(\S+)(\s+)(\S+)/m do
|
174
|
-
group
|
175
|
-
group
|
176
|
-
group
|
174
|
+
group Keyword; group Text
|
175
|
+
group Name::Class; group Text
|
176
|
+
group Name::Function
|
177
177
|
end
|
178
178
|
|
179
|
-
rule /\((?=\s)/,
|
180
|
-
rule /;(?=\s)/,
|
179
|
+
rule /\((?=\s)/, Name::Function, :stack_effect
|
180
|
+
rule /;(?=\s)/, Keyword
|
181
181
|
|
182
182
|
rule /(USING:)((?:\s|\\\s)+)/m do
|
183
|
-
group
|
183
|
+
group Keyword::Namespace; group Text
|
184
184
|
push :import
|
185
185
|
end
|
186
186
|
|
187
187
|
rule /(IN:|USE:|UNUSE:|QUALIFIED:|QUALIFIED-WITH:)(\s+)(\S+)/m do
|
188
|
-
group
|
188
|
+
group Keyword::Namespace; group Text; group Name::Namespace
|
189
189
|
end
|
190
190
|
|
191
191
|
rule /(FROM:|EXCLUDE:)(\s+)(\S+)(\s+)(=>)/m do
|
192
|
-
group
|
193
|
-
group
|
194
|
-
group
|
192
|
+
group Keyword::Namespace; group Text
|
193
|
+
group Name::Namespace; group Text
|
194
|
+
group Punctuation
|
195
195
|
end
|
196
196
|
|
197
|
-
rule /(?:ALIAS|DEFER|FORGET|POSTPONE):/,
|
197
|
+
rule /(?:ALIAS|DEFER|FORGET|POSTPONE):/, Keyword::Namespace
|
198
198
|
|
199
199
|
rule /(TUPLE:)(\s+)(\S+)(\s+)(<)(\s+)(\S+)/m do
|
200
|
-
group
|
201
|
-
group
|
202
|
-
group
|
203
|
-
group
|
200
|
+
group Keyword; group Text
|
201
|
+
group Name::Class; group Text
|
202
|
+
group Punctuation; group Text
|
203
|
+
group Name::Class
|
204
204
|
push :slots
|
205
205
|
end
|
206
206
|
|
207
207
|
rule /(TUPLE:)(\s+)(\S+)/m do
|
208
|
-
group
|
208
|
+
group Keyword; group Text; group Name::Class
|
209
209
|
push :slots
|
210
210
|
end
|
211
211
|
|
212
212
|
rule /(UNION:|INTERSECTION:)(\s+)(\S+)/m do
|
213
|
-
group
|
213
|
+
group Keyword; group Text; group Name::Class
|
214
214
|
end
|
215
215
|
|
216
216
|
rule /(PREDICATE:)(\s+)(\S+)(\s+)(<)(\s+)(\S+)/m do
|
217
|
-
group
|
218
|
-
group
|
219
|
-
group
|
220
|
-
group
|
217
|
+
group Keyword; group Text
|
218
|
+
group Name::Class; group Text
|
219
|
+
group Punctuation; group Text
|
220
|
+
group Name::Class
|
221
221
|
end
|
222
222
|
|
223
223
|
rule /(C:)(\s+)(\S+)(\s+)(\S+)/m do
|
224
|
-
group
|
225
|
-
group
|
226
|
-
group
|
224
|
+
group Keyword; group Text
|
225
|
+
group Name::Function; group Text
|
226
|
+
group Name::Class
|
227
227
|
end
|
228
228
|
|
229
229
|
rule %r(
|
230
230
|
(INSTANCE|SLOT|MIXIN|SINGLETONS?|CONSTANT|SYMBOLS?|ERROR|SYNTAX
|
231
231
|
|ALIEN|TYPEDEF|FUNCTION|STRUCT):
|
232
|
-
)x,
|
232
|
+
)x, Keyword
|
233
233
|
|
234
|
-
rule /(?:<PRIVATE|PRIVATE>)/,
|
234
|
+
rule /(?:<PRIVATE|PRIVATE>)/, Keyword::Namespace
|
235
235
|
|
236
236
|
rule /(MAIN:)(\s+)(\S+)/ do
|
237
|
-
group
|
237
|
+
group Keyword::Namespace; group Text; group Name::Function
|
238
238
|
end
|
239
239
|
|
240
240
|
# strings
|
241
|
-
rule /"""\s+.*?\s+"""/,
|
242
|
-
rule /"(\\.|[^\\])*?"/,
|
243
|
-
rule /(CHAR:)(\s+)(\\[\\abfnrstv]*|\S)(?=\s)/,
|
241
|
+
rule /"""\s+.*?\s+"""/, Str
|
242
|
+
rule /"(\\.|[^\\])*?"/, Str
|
243
|
+
rule /(CHAR:)(\s+)(\\[\\abfnrstv]*|\S)(?=\s)/, Str::Char
|
244
244
|
|
245
245
|
# comments
|
246
|
-
rule /!\s+.*$/,
|
247
|
-
rule /#!\s+.*$/,
|
246
|
+
rule /!\s+.*$/, Comment
|
247
|
+
rule /#!\s+.*$/, Comment
|
248
248
|
|
249
249
|
# booleans
|
250
|
-
rule /[tf](?=\s)/,
|
250
|
+
rule /[tf](?=\s)/, Name::Constant
|
251
251
|
|
252
252
|
# numbers
|
253
|
-
rule /-?\d+\.\d+(?=\s)/,
|
254
|
-
rule /-?\d+(?=\s)/,
|
253
|
+
rule /-?\d+\.\d+(?=\s)/, Num::Float
|
254
|
+
rule /-?\d+(?=\s)/, Num::Integer
|
255
255
|
|
256
|
-
rule /HEX:\s+[a-fA-F\d]+(?=\s)/m,
|
257
|
-
rule /BIN:\s+[01]+(?=\s)/,
|
258
|
-
rule /OCT:\s+[0-7]+(?=\s)/,
|
256
|
+
rule /HEX:\s+[a-fA-F\d]+(?=\s)/m, Num::Hex
|
257
|
+
rule /BIN:\s+[01]+(?=\s)/, Num::Bin
|
258
|
+
rule /OCT:\s+[0-7]+(?=\s)/, Num::Oct
|
259
259
|
|
260
|
-
rule %r([-+/*=<>^](?=\s)),
|
260
|
+
rule %r([-+/*=<>^](?=\s)), Operator
|
261
261
|
|
262
262
|
rule /(?:deprecated|final|foldable|flushable|inline|recursive)(?=\s)/,
|
263
|
-
|
263
|
+
Keyword
|
264
264
|
|
265
265
|
rule /\S+/ do |m|
|
266
266
|
name = m[0]
|
267
267
|
|
268
268
|
if self.class.builtins.values.any? { |b| b.include? name }
|
269
|
-
token
|
269
|
+
token Name::Builtin
|
270
270
|
else
|
271
|
-
token
|
271
|
+
token Name
|
272
272
|
end
|
273
273
|
end
|
274
274
|
end
|
275
275
|
|
276
276
|
state :stack_effect do
|
277
|
-
rule /\s+/,
|
278
|
-
rule /\(/,
|
279
|
-
rule /\)/,
|
277
|
+
rule /\s+/, Text
|
278
|
+
rule /\(/, Name::Function, :stack_effect
|
279
|
+
rule /\)/, Name::Function, :pop!
|
280
280
|
|
281
|
-
rule /--/,
|
282
|
-
rule /\S+/,
|
281
|
+
rule /--/, Name::Function
|
282
|
+
rule /\S+/, Name::Variable
|
283
283
|
end
|
284
284
|
|
285
285
|
state :slots do
|
286
|
-
rule /\s+/,
|
287
|
-
rule /;(?=\s)/,
|
288
|
-
rule /\S+/,
|
286
|
+
rule /\s+/, Text
|
287
|
+
rule /;(?=\s)/, Keyword, :pop!
|
288
|
+
rule /\S+/, Name::Variable
|
289
289
|
end
|
290
290
|
|
291
291
|
state :import do
|
292
|
-
rule /;(?=\s)/,
|
293
|
-
rule /\s+/,
|
294
|
-
rule /\S+/,
|
292
|
+
rule /;(?=\s)/, Keyword, :pop!
|
293
|
+
rule /\s+/, Text
|
294
|
+
rule /\S+/, Name::Namespace
|
295
295
|
end
|
296
296
|
end
|
297
297
|
end
|