coderay 1.0.0 → 1.0.0.598.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/FOLDERS +49 -0
- data/Rakefile +6 -5
- data/bin/coderay +74 -190
- data/bin/coderay_stylesheet +4 -0
- data/{README_INDEX.rdoc → lib/README} +20 -10
- data/lib/coderay.rb +60 -62
- data/lib/coderay/duo.rb +55 -2
- data/lib/coderay/encoder.rb +39 -52
- data/lib/coderay/encoders/_map.rb +7 -11
- data/lib/coderay/encoders/comment_filter.rb +61 -0
- data/lib/coderay/encoders/count.rb +26 -11
- data/lib/coderay/encoders/debug.rb +60 -11
- data/lib/coderay/encoders/div.rb +8 -9
- data/lib/coderay/encoders/filter.rb +52 -12
- data/lib/coderay/encoders/html.rb +113 -106
- data/lib/coderay/encoders/html/css.rb +7 -2
- data/lib/coderay/encoders/html/numbering.rb +27 -24
- data/lib/coderay/encoders/html/output.rb +58 -15
- data/lib/coderay/encoders/json.rb +44 -37
- data/lib/coderay/encoders/lines_of_code.rb +56 -9
- data/lib/coderay/encoders/null.rb +13 -6
- data/lib/coderay/encoders/page.rb +8 -8
- data/lib/coderay/encoders/span.rb +9 -10
- data/lib/coderay/encoders/statistic.rb +114 -51
- data/lib/coderay/encoders/terminal.rb +10 -7
- data/lib/coderay/encoders/text.rb +36 -17
- data/lib/coderay/encoders/token_kind_filter.rb +58 -1
- data/lib/coderay/encoders/xml.rb +11 -13
- data/lib/coderay/encoders/yaml.rb +14 -16
- data/lib/coderay/for_redcloth.rb +1 -1
- data/lib/coderay/helpers/file_type.rb +240 -125
- data/lib/coderay/helpers/gzip_simple.rb +123 -0
- data/lib/coderay/helpers/plugin.rb +307 -241
- data/lib/coderay/helpers/word_list.rb +126 -65
- data/lib/coderay/scanner.rb +103 -153
- data/lib/coderay/scanners/_map.rb +16 -18
- data/lib/coderay/scanners/c.rb +13 -13
- data/lib/coderay/scanners/cpp.rb +6 -6
- data/lib/coderay/scanners/css.rb +48 -47
- data/lib/coderay/scanners/debug.rb +55 -9
- data/lib/coderay/scanners/delphi.rb +4 -4
- data/lib/coderay/scanners/diff.rb +25 -43
- data/lib/coderay/scanners/groovy.rb +2 -2
- data/lib/coderay/scanners/html.rb +30 -107
- data/lib/coderay/scanners/java.rb +5 -6
- data/lib/coderay/scanners/java/builtin_types.rb +0 -2
- data/lib/coderay/scanners/java_script.rb +6 -6
- data/lib/coderay/scanners/json.rb +6 -7
- data/lib/coderay/scanners/nitro_xhtml.rb +136 -0
- data/lib/coderay/scanners/php.rb +12 -13
- data/lib/coderay/scanners/plaintext.rb +26 -0
- data/lib/coderay/scanners/python.rb +4 -4
- data/lib/coderay/scanners/{erb.rb → rhtml.rb} +11 -19
- data/lib/coderay/scanners/ruby.rb +208 -219
- data/lib/coderay/scanners/ruby/patterns.rb +85 -18
- data/lib/coderay/scanners/scheme.rb +136 -0
- data/lib/coderay/scanners/sql.rb +22 -29
- data/lib/coderay/scanners/yaml.rb +10 -11
- data/lib/coderay/styles/_map.rb +2 -2
- data/lib/coderay/styles/alpha.rb +104 -102
- data/lib/coderay/styles/cycnus.rb +143 -0
- data/lib/coderay/styles/murphy.rb +123 -0
- data/lib/coderay/token_kinds.rb +86 -87
- data/lib/coderay/tokens.rb +169 -26
- data/test/functional/basic.rb +14 -200
- data/test/functional/examples.rb +14 -20
- data/test/functional/for_redcloth.rb +8 -15
- data/test/functional/load_plugin_scanner.rb +11 -0
- data/test/functional/suite.rb +6 -9
- data/test/functional/vhdl.rb +126 -0
- data/test/functional/word_list.rb +79 -0
- metadata +129 -107
- data/lib/coderay/helpers/gzip.rb +0 -41
- data/lib/coderay/scanners/clojure.rb +0 -217
- data/lib/coderay/scanners/haml.rb +0 -168
- data/lib/coderay/scanners/ruby/string_state.rb +0 -71
- data/lib/coderay/scanners/text.rb +0 -26
- data/lib/coderay/tokens_proxy.rb +0 -55
- data/lib/coderay/version.rb +0 -3
@@ -4,7 +4,7 @@ module Scanners
|
|
4
4
|
|
5
5
|
module Ruby::Patterns # :nodoc: all
|
6
6
|
|
7
|
-
|
7
|
+
RESERVED_WORDS = %w[
|
8
8
|
and def end in or unless begin
|
9
9
|
defined? ensure module redo super until
|
10
10
|
BEGIN break do next rescue then
|
@@ -26,8 +26,8 @@ module Scanners
|
|
26
26
|
]
|
27
27
|
|
28
28
|
IDENT_KIND = WordList.new(:ident).
|
29
|
-
add(
|
30
|
-
add(PREDEFINED_CONSTANTS, :
|
29
|
+
add(RESERVED_WORDS, :reserved).
|
30
|
+
add(PREDEFINED_CONSTANTS, :pre_constant)
|
31
31
|
|
32
32
|
KEYWORD_NEW_STATE = WordList.new(:initial).
|
33
33
|
add(%w[ def ], :def_expected).
|
@@ -65,6 +65,7 @@ module Scanners
|
|
65
65
|
QUOTE_TO_TYPE.default = :string
|
66
66
|
|
67
67
|
REGEXP_MODIFIERS = /[mousenix]*/
|
68
|
+
REGEXP_SYMBOLS = /[|?*+(){}\[\].^$]/
|
68
69
|
|
69
70
|
DECIMAL = /\d+(?:_\d+)*/
|
70
71
|
OCTAL = /0_?[0-7]+(?:_[0-7]+)*/
|
@@ -90,7 +91,7 @@ module Scanners
|
|
90
91
|
[abefnrstv]
|
91
92
|
| [0-7]{1,3}
|
92
93
|
| x[0-9A-Fa-f]{1,2}
|
93
|
-
|
|
94
|
+
| .?
|
94
95
|
/mx
|
95
96
|
|
96
97
|
CONTROL_META_ESCAPE = /
|
@@ -156,20 +157,86 @@ module Scanners
|
|
156
157
|
while elsif if not return
|
157
158
|
yield
|
158
159
|
])
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
'
|
164
|
-
'
|
165
|
-
|
166
|
-
|
167
|
-
'
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
160
|
+
|
161
|
+
FANCY_START = / % ( [qQwWxsr] | (?![a-zA-Z0-9]) ) ([^a-zA-Z0-9]) /mx
|
162
|
+
|
163
|
+
FancyStringType = {
|
164
|
+
'q' => [:string, false],
|
165
|
+
'Q' => [:string, true],
|
166
|
+
'r' => [:regexp, true],
|
167
|
+
's' => [:symbol, false],
|
168
|
+
'x' => [:shell, true]
|
169
|
+
}
|
170
|
+
FancyStringType['w'] = FancyStringType['q']
|
171
|
+
FancyStringType['W'] = FancyStringType[''] = FancyStringType['Q']
|
172
|
+
|
173
|
+
class StringState < Struct.new :type, :interpreted, :delim, :heredoc,
|
174
|
+
:opening_paren, :paren_depth, :pattern, :next_state
|
175
|
+
|
176
|
+
CLOSING_PAREN = Hash[ *%w[
|
177
|
+
( )
|
178
|
+
[ ]
|
179
|
+
< >
|
180
|
+
{ }
|
181
|
+
] ]
|
182
|
+
|
183
|
+
CLOSING_PAREN.each { |k,v| k.freeze; v.freeze } # debug, if I try to change it with <<
|
184
|
+
OPENING_PAREN = CLOSING_PAREN.invert
|
185
|
+
|
186
|
+
STRING_PATTERN = Hash.new do |h, k|
|
187
|
+
delim, interpreted = *k
|
188
|
+
delim_pattern = Regexp.escape(delim.dup) # dup: workaround for old Ruby
|
189
|
+
if closing_paren = CLOSING_PAREN[delim]
|
190
|
+
delim_pattern = delim_pattern[0..-1] if defined? JRUBY_VERSION # JRuby fix
|
191
|
+
delim_pattern << Regexp.escape(closing_paren)
|
192
|
+
end
|
193
|
+
delim_pattern << '\\\\' unless delim == '\\'
|
194
|
+
|
195
|
+
special_escapes =
|
196
|
+
case interpreted
|
197
|
+
when :regexp_symbols
|
198
|
+
'| ' + REGEXP_SYMBOLS.source
|
199
|
+
when :words
|
200
|
+
'| \s'
|
201
|
+
end
|
202
|
+
|
203
|
+
h[k] =
|
204
|
+
if interpreted and not delim == '#'
|
205
|
+
/ (?= [#{delim_pattern}] | \# [{$@] #{special_escapes} ) /mx
|
206
|
+
else
|
207
|
+
/ (?= [#{delim_pattern}] #{special_escapes} ) /mx
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
HEREDOC_PATTERN = Hash.new do |h, k|
|
212
|
+
delim, interpreted, indented = *k
|
213
|
+
delim_pattern = Regexp.escape(delim.dup) # dup: workaround for old Ruby
|
214
|
+
delim_pattern = / \n #{ '(?>[\ \t]*)' if indented } #{ Regexp.new delim_pattern } $ /x
|
215
|
+
h[k] =
|
216
|
+
if interpreted
|
217
|
+
/ (?= #{delim_pattern}() | \\ | \# [{$@] ) /mx # $1 set == end of heredoc
|
218
|
+
else
|
219
|
+
/ (?= #{delim_pattern}() | \\ ) /mx
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
def initialize kind, interpreted, delim, heredoc = false
|
224
|
+
if heredoc
|
225
|
+
pattern = HEREDOC_PATTERN[ [delim, interpreted, heredoc == :indented] ]
|
226
|
+
delim = nil
|
227
|
+
else
|
228
|
+
pattern = STRING_PATTERN[ [delim, interpreted] ]
|
229
|
+
if closing_paren = CLOSING_PAREN[delim]
|
230
|
+
opening_paren = delim
|
231
|
+
delim = closing_paren
|
232
|
+
paren_depth = 1
|
233
|
+
end
|
234
|
+
end
|
235
|
+
super kind, interpreted, delim, heredoc, opening_paren, paren_depth, pattern, :initial
|
236
|
+
end
|
237
|
+
end unless defined? StringState
|
238
|
+
|
172
239
|
end
|
173
|
-
|
240
|
+
|
174
241
|
end
|
175
242
|
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
module CodeRay
|
2
|
+
module Scanners
|
3
|
+
|
4
|
+
# Scheme scanner for CodeRay (by closure).
|
5
|
+
#
|
6
|
+
# Thanks to murphy for putting CodeRay into public.
|
7
|
+
class Scheme < Scanner
|
8
|
+
|
9
|
+
# TODO: function defs
|
10
|
+
# TODO: built-in functions
|
11
|
+
|
12
|
+
register_for :scheme
|
13
|
+
file_extension 'scm'
|
14
|
+
|
15
|
+
CORE_FORMS = %w[
|
16
|
+
lambda let let* letrec syntax-case define-syntax let-syntax
|
17
|
+
letrec-syntax begin define quote if or and cond case do delay
|
18
|
+
quasiquote set! cons force call-with-current-continuation call/cc
|
19
|
+
] # :nodoc:
|
20
|
+
|
21
|
+
IDENT_KIND = CaseIgnoringWordList.new(:ident).
|
22
|
+
add(CORE_FORMS, :reserved) # :nodoc:
|
23
|
+
|
24
|
+
#IDENTIFIER_INITIAL = /[a-z!@\$%&\*\/\:<=>\?~_\^]/i
|
25
|
+
#IDENTIFIER_SUBSEQUENT = /#{IDENTIFIER_INITIAL}|\d|\.|\+|-/
|
26
|
+
#IDENTIFIER = /#{IDENTIFIER_INITIAL}#{IDENTIFIER_SUBSEQUENT}*|\+|-|\.{3}/
|
27
|
+
IDENTIFIER = /[a-zA-Z!@$%&*\/:<=>?~_^][\w!@$%&*\/:<=>?~^.+\-]*|[+-]|\.\.\./ # :nodoc:
|
28
|
+
DIGIT = /\d/ # :nodoc:
|
29
|
+
DIGIT10 = /\d/ # :nodoc:
|
30
|
+
DIGIT16 = /[0-9a-f]/i # :nodoc:
|
31
|
+
DIGIT8 = /[0-7]/ # :nodoc:
|
32
|
+
DIGIT2 = /[01]/ # :nodoc:
|
33
|
+
RADIX16 = /\#x/i # :nodoc:
|
34
|
+
RADIX8 = /\#o/i # :nodoc:
|
35
|
+
RADIX2 = /\#b/i # :nodoc:
|
36
|
+
RADIX10 = /\#d/i # :nodoc:
|
37
|
+
EXACTNESS = /#i|#e/i # :nodoc:
|
38
|
+
SIGN = /[\+-]?/ # :nodoc:
|
39
|
+
EXP_MARK = /[esfdl]/i # :nodoc:
|
40
|
+
EXP = /#{EXP_MARK}#{SIGN}#{DIGIT}+/ # :nodoc:
|
41
|
+
SUFFIX = /#{EXP}?/ # :nodoc:
|
42
|
+
PREFIX10 = /#{RADIX10}?#{EXACTNESS}?|#{EXACTNESS}?#{RADIX10}?/ # :nodoc:
|
43
|
+
PREFIX16 = /#{RADIX16}#{EXACTNESS}?|#{EXACTNESS}?#{RADIX16}/ # :nodoc:
|
44
|
+
PREFIX8 = /#{RADIX8}#{EXACTNESS}?|#{EXACTNESS}?#{RADIX8}/ # :nodoc:
|
45
|
+
PREFIX2 = /#{RADIX2}#{EXACTNESS}?|#{EXACTNESS}?#{RADIX2}/ # :nodoc:
|
46
|
+
UINT10 = /#{DIGIT10}+#*/ # :nodoc:
|
47
|
+
UINT16 = /#{DIGIT16}+#*/ # :nodoc:
|
48
|
+
UINT8 = /#{DIGIT8}+#*/ # :nodoc:
|
49
|
+
UINT2 = /#{DIGIT2}+#*/ # :nodoc:
|
50
|
+
DECIMAL = /#{DIGIT10}+#+\.#*#{SUFFIX}|#{DIGIT10}+\.#{DIGIT10}*#*#{SUFFIX}|\.#{DIGIT10}+#*#{SUFFIX}|#{UINT10}#{EXP}/ # :nodoc:
|
51
|
+
UREAL10 = /#{UINT10}\/#{UINT10}|#{DECIMAL}|#{UINT10}/ # :nodoc:
|
52
|
+
UREAL16 = /#{UINT16}\/#{UINT16}|#{UINT16}/ # :nodoc:
|
53
|
+
UREAL8 = /#{UINT8}\/#{UINT8}|#{UINT8}/ # :nodoc:
|
54
|
+
UREAL2 = /#{UINT2}\/#{UINT2}|#{UINT2}/ # :nodoc:
|
55
|
+
REAL10 = /#{SIGN}#{UREAL10}/ # :nodoc:
|
56
|
+
REAL16 = /#{SIGN}#{UREAL16}/ # :nodoc:
|
57
|
+
REAL8 = /#{SIGN}#{UREAL8}/ # :nodoc:
|
58
|
+
REAL2 = /#{SIGN}#{UREAL2}/ # :nodoc:
|
59
|
+
IMAG10 = /i|#{UREAL10}i/ # :nodoc:
|
60
|
+
IMAG16 = /i|#{UREAL16}i/ # :nodoc:
|
61
|
+
IMAG8 = /i|#{UREAL8}i/ # :nodoc:
|
62
|
+
IMAG2 = /i|#{UREAL2}i/ # :nodoc:
|
63
|
+
COMPLEX10 = /#{REAL10}@#{REAL10}|#{REAL10}\+#{IMAG10}|#{REAL10}-#{IMAG10}|\+#{IMAG10}|-#{IMAG10}|#{REAL10}/ # :nodoc:
|
64
|
+
COMPLEX16 = /#{REAL16}@#{REAL16}|#{REAL16}\+#{IMAG16}|#{REAL16}-#{IMAG16}|\+#{IMAG16}|-#{IMAG16}|#{REAL16}/ # :nodoc:
|
65
|
+
COMPLEX8 = /#{REAL8}@#{REAL8}|#{REAL8}\+#{IMAG8}|#{REAL8}-#{IMAG8}|\+#{IMAG8}|-#{IMAG8}|#{REAL8}/ # :nodoc:
|
66
|
+
COMPLEX2 = /#{REAL2}@#{REAL2}|#{REAL2}\+#{IMAG2}|#{REAL2}-#{IMAG2}|\+#{IMAG2}|-#{IMAG2}|#{REAL2}/ # :nodoc:
|
67
|
+
NUM10 = /#{PREFIX10}?#{COMPLEX10}/ # :nodoc:
|
68
|
+
NUM16 = /#{PREFIX16}#{COMPLEX16}/ # :nodoc:
|
69
|
+
NUM8 = /#{PREFIX8}#{COMPLEX8}/ # :nodoc:
|
70
|
+
NUM2 = /#{PREFIX2}#{COMPLEX2}/ # :nodoc:
|
71
|
+
NUM = /#{NUM10}|#{NUM16}|#{NUM8}|#{NUM2}/ # :nodoc:
|
72
|
+
|
73
|
+
protected
|
74
|
+
|
75
|
+
def scan_tokens encoder, options
|
76
|
+
|
77
|
+
state = :initial
|
78
|
+
ident_kind = IDENT_KIND
|
79
|
+
|
80
|
+
until eos?
|
81
|
+
|
82
|
+
case state
|
83
|
+
when :initial
|
84
|
+
if match = scan(/ \s+ | \\\n /x)
|
85
|
+
encoder.text_token match, :space
|
86
|
+
elsif match = scan(/['\(\[\)\]]|#\(/)
|
87
|
+
encoder.text_token match, :operator # FIXME: was :operator_fat
|
88
|
+
elsif match = scan(/;.*/)
|
89
|
+
encoder.text_token match, :comment
|
90
|
+
elsif match = scan(/#\\(?:newline|space|.?)/)
|
91
|
+
encoder.text_token match, :char
|
92
|
+
elsif match = scan(/#[ft]/)
|
93
|
+
encoder.text_token match, :pre_constant
|
94
|
+
elsif match = scan(/#{IDENTIFIER}/o)
|
95
|
+
encoder.text_token match, ident_kind[matched]
|
96
|
+
elsif match = scan(/\./)
|
97
|
+
encoder.text_token match, :operator
|
98
|
+
elsif match = scan(/"/)
|
99
|
+
encoder.begin_group :string
|
100
|
+
encoder.text_token match, :delimiter
|
101
|
+
state = :string
|
102
|
+
elsif match = scan(/#{NUM}/o) and not matched.empty?
|
103
|
+
encoder.text_token match, :integer
|
104
|
+
else
|
105
|
+
encoder.text_token getch, :error
|
106
|
+
end
|
107
|
+
|
108
|
+
when :string
|
109
|
+
if match = scan(/[^"\\]+|\\.?/)
|
110
|
+
encoder.text_token match, :content
|
111
|
+
elsif match = scan(/"/)
|
112
|
+
encoder.text_token match, :delimiter
|
113
|
+
encoder.end_group :string
|
114
|
+
state = :initial
|
115
|
+
else
|
116
|
+
raise_inspect "else case \" reached; %p not handled." % peek(1),
|
117
|
+
encoder, state
|
118
|
+
end
|
119
|
+
|
120
|
+
else
|
121
|
+
raise 'else case reached'
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
if state == :string
|
128
|
+
encoder.end_group state
|
129
|
+
end
|
130
|
+
|
131
|
+
encoder
|
132
|
+
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
data/lib/coderay/scanners/sql.rb
CHANGED
@@ -5,27 +5,26 @@ module CodeRay module Scanners
|
|
5
5
|
|
6
6
|
register_for :sql
|
7
7
|
|
8
|
-
|
9
|
-
all and
|
10
|
-
|
11
|
-
for foreign from
|
12
|
-
like not
|
13
|
-
then to union using values when where
|
8
|
+
RESERVED_WORDS = %w(
|
9
|
+
all and as before begin by case collate
|
10
|
+
constraint create else end engine exists
|
11
|
+
for foreign from group if inner is join key
|
12
|
+
like not on or order outer primary references replace
|
13
|
+
then to trigger union using values when where
|
14
14
|
left right distinct
|
15
15
|
)
|
16
16
|
|
17
17
|
OBJECTS = %w(
|
18
|
-
database databases table tables column columns
|
19
|
-
constraints transaction function procedure row key view trigger
|
18
|
+
database databases table tables column columns index
|
20
19
|
)
|
21
20
|
|
22
21
|
COMMANDS = %w(
|
23
22
|
add alter comment create delete drop grant insert into select update set
|
24
|
-
show
|
23
|
+
show
|
25
24
|
)
|
26
25
|
|
27
26
|
PREDEFINED_TYPES = %w(
|
28
|
-
char varchar
|
27
|
+
char varchar enum binary text tinytext mediumtext
|
29
28
|
longtext blob tinyblob mediumblob longblob timestamp
|
30
29
|
date time datetime year double decimal float int
|
31
30
|
integer tinyint mediumint bigint smallint unsigned bit
|
@@ -34,20 +33,16 @@ module CodeRay module Scanners
|
|
34
33
|
|
35
34
|
PREDEFINED_FUNCTIONS = %w( sum cast substring abs pi count min max avg now )
|
36
35
|
|
37
|
-
DIRECTIVES = %w(
|
38
|
-
auto_increment unique default charset initially deferred
|
39
|
-
deferrable cascade immediate read write asc desc after
|
40
|
-
primary foreign return engine
|
41
|
-
)
|
36
|
+
DIRECTIVES = %w( auto_increment unique default charset )
|
42
37
|
|
43
38
|
PREDEFINED_CONSTANTS = %w( null true false )
|
44
39
|
|
45
|
-
IDENT_KIND =
|
46
|
-
add(
|
40
|
+
IDENT_KIND = CaseIgnoringWordList.new(:ident).
|
41
|
+
add(RESERVED_WORDS, :reserved).
|
47
42
|
add(OBJECTS, :type).
|
48
43
|
add(COMMANDS, :class).
|
49
|
-
add(PREDEFINED_TYPES, :
|
50
|
-
add(PREDEFINED_CONSTANTS, :
|
44
|
+
add(PREDEFINED_TYPES, :pre_type).
|
45
|
+
add(PREDEFINED_CONSTANTS, :pre_constant).
|
51
46
|
add(PREDEFINED_FUNCTIONS, :predefined).
|
52
47
|
add(DIRECTIVES, :directive)
|
53
48
|
|
@@ -61,7 +56,6 @@ module CodeRay module Scanners
|
|
61
56
|
state = :initial
|
62
57
|
string_type = nil
|
63
58
|
string_content = ''
|
64
|
-
name_expected = false
|
65
59
|
|
66
60
|
until eos?
|
67
61
|
|
@@ -70,14 +64,13 @@ module CodeRay module Scanners
|
|
70
64
|
if match = scan(/ \s+ | \\\n /x)
|
71
65
|
encoder.text_token match, :space
|
72
66
|
|
73
|
-
elsif match = scan(
|
67
|
+
elsif match = scan(/^(?:--\s?|#).*/)
|
74
68
|
encoder.text_token match, :comment
|
75
69
|
|
76
70
|
elsif match = scan(%r( /\* (!)? (?: .*? \*/ | .* ) )mx)
|
77
71
|
encoder.text_token match, self[1] ? :directive : :comment
|
78
72
|
|
79
|
-
elsif match = scan(/ [
|
80
|
-
name_expected = true if match == '.' && check(/[A-Za-z_]/)
|
73
|
+
elsif match = scan(/ [-+*\/=<>;,!&^|()\[\]{}~%] | \.(?!\d) /x)
|
81
74
|
encoder.text_token match, :operator
|
82
75
|
|
83
76
|
elsif match = scan(/(#{STRING_PREFIXES})?([`"'])/o)
|
@@ -90,23 +83,23 @@ module CodeRay module Scanners
|
|
90
83
|
encoder.text_token match, :delimiter
|
91
84
|
|
92
85
|
elsif match = scan(/ @? [A-Za-z_][A-Za-z_0-9]* /x)
|
93
|
-
|
94
|
-
|
86
|
+
# FIXME: Don't match keywords after "."
|
87
|
+
encoder.text_token match, match[0] == ?@ ? :variable : IDENT_KIND[match.downcase]
|
95
88
|
|
96
89
|
elsif match = scan(/0[xX][0-9A-Fa-f]+/)
|
97
90
|
encoder.text_token match, :hex
|
98
91
|
|
99
92
|
elsif match = scan(/0[0-7]+(?![89.eEfF])/)
|
100
|
-
encoder.text_token match, :
|
93
|
+
encoder.text_token match, :oct
|
101
94
|
|
102
|
-
elsif match = scan(/
|
95
|
+
elsif match = scan(/(?>\d+)(?![.eEfF])/)
|
103
96
|
encoder.text_token match, :integer
|
104
97
|
|
105
|
-
elsif match = scan(
|
98
|
+
elsif match = scan(/\d[fF]|\d*\.\d+(?:[eE][+-]?\d+)?|\d+[eE][+-]?\d+/)
|
106
99
|
encoder.text_token match, :float
|
107
100
|
|
108
101
|
elsif match = scan(/\\N/)
|
109
|
-
encoder.text_token match, :
|
102
|
+
encoder.text_token match, :pre_constant
|
110
103
|
|
111
104
|
else
|
112
105
|
encoder.text_token getch, :error
|
@@ -15,8 +15,9 @@ module Scanners
|
|
15
15
|
|
16
16
|
def scan_tokens encoder, options
|
17
17
|
|
18
|
+
value_expected = nil
|
18
19
|
state = :initial
|
19
|
-
key_indent =
|
20
|
+
key_indent = indent = 0
|
20
21
|
|
21
22
|
until eos?
|
22
23
|
|
@@ -54,16 +55,14 @@ module Scanners
|
|
54
55
|
when match = scan(/[|>][-+]?/)
|
55
56
|
encoder.begin_group :string
|
56
57
|
encoder.text_token match, :delimiter
|
57
|
-
string_indent = key_indent || column(pos - match.size
|
58
|
+
string_indent = key_indent || column(pos - match.size - 1)
|
58
59
|
encoder.text_token matched, :content if scan(/(?:\n+ {#{string_indent + 1}}.*)+/)
|
59
60
|
encoder.end_group :string
|
60
61
|
next
|
61
62
|
when match = scan(/(?![!"*&]).+?(?=$|\s+#)/)
|
62
|
-
encoder.
|
63
|
-
|
64
|
-
|
65
|
-
encoder.text_token matched, :content if scan(/(?:\n+ {#{string_indent + 1}}.*)+/)
|
66
|
-
encoder.end_group :string
|
63
|
+
encoder.text_token match, :string
|
64
|
+
string_indent = key_indent || column(pos - match.size - 1)
|
65
|
+
encoder.text_token matched, :string if scan(/(?:\n+ {#{string_indent + 1}}.*)+/)
|
67
66
|
next
|
68
67
|
end
|
69
68
|
|
@@ -78,7 +77,7 @@ module Scanners
|
|
78
77
|
next
|
79
78
|
when state == :initial && match = scan(/[\w.() ]*\S(?= *:(?: |$))/)
|
80
79
|
encoder.text_token match, :key
|
81
|
-
key_indent = column(pos - match.size
|
80
|
+
key_indent = column(pos - match.size - 1)
|
82
81
|
state = :colon
|
83
82
|
next
|
84
83
|
when match = scan(/(?:"[^"\n]*"|'[^'\n]*')(?= *:(?: |$))/)
|
@@ -87,7 +86,7 @@ module Scanners
|
|
87
86
|
encoder.text_token match[1..-2], :content
|
88
87
|
encoder.text_token match[-1,1], :delimiter
|
89
88
|
encoder.end_group :key
|
90
|
-
key_indent = column(pos - match.size
|
89
|
+
key_indent = column(pos - match.size - 1)
|
91
90
|
state = :colon
|
92
91
|
next
|
93
92
|
when match = scan(/(![\w\/]+)(:([\w:]+))?/)
|
@@ -107,10 +106,10 @@ module Scanners
|
|
107
106
|
encoder.text_token match, :class_variable
|
108
107
|
next
|
109
108
|
when match = scan(/\d\d:\d\d:\d\d/)
|
110
|
-
encoder.text_token match, :
|
109
|
+
encoder.text_token match, :oct
|
111
110
|
next
|
112
111
|
when match = scan(/\d\d\d\d-\d\d-\d\d\s\d\d:\d\d:\d\d(\.\d+)? [-+]\d\d:\d\d/)
|
113
|
-
encoder.text_token match, :
|
112
|
+
encoder.text_token match, :oct
|
114
113
|
next
|
115
114
|
when match = scan(/:\w+/)
|
116
115
|
encoder.text_token match, :symbol
|