raldred-coderay 0.9.0 → 0.9.339
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/README +128 -0
- data/lib/coderay.rb +319 -0
- data/lib/coderay/duo.rb +85 -0
- data/lib/coderay/encoder.rb +187 -0
- data/lib/coderay/encoders/_map.rb +9 -0
- data/lib/coderay/encoders/count.rb +21 -0
- data/lib/coderay/encoders/debug.rb +49 -0
- data/lib/coderay/encoders/div.rb +20 -0
- data/lib/coderay/encoders/html.rb +306 -0
- data/lib/coderay/encoders/html/css.rb +70 -0
- data/lib/coderay/encoders/html/numerization.rb +133 -0
- data/lib/coderay/encoders/html/output.rb +206 -0
- data/lib/coderay/encoders/json.rb +19 -0
- data/lib/coderay/encoders/null.rb +26 -0
- data/lib/coderay/encoders/page.rb +21 -0
- data/lib/coderay/encoders/span.rb +20 -0
- data/lib/coderay/encoders/statistic.rb +77 -0
- data/lib/coderay/encoders/term.rb +114 -0
- data/lib/coderay/encoders/text.rb +32 -0
- data/lib/coderay/encoders/tokens.rb +44 -0
- data/lib/coderay/encoders/xml.rb +71 -0
- data/lib/coderay/encoders/yaml.rb +22 -0
- data/lib/coderay/for_redcloth.rb +73 -0
- data/lib/coderay/helpers/file_type.rb +226 -0
- data/lib/coderay/helpers/gzip_simple.rb +123 -0
- data/lib/coderay/helpers/plugin.rb +339 -0
- data/lib/coderay/helpers/word_list.rb +124 -0
- data/lib/coderay/scanner.rb +271 -0
- data/lib/coderay/scanners/_map.rb +21 -0
- data/lib/coderay/scanners/c.rb +166 -0
- data/lib/coderay/scanners/css.rb +202 -0
- data/lib/coderay/scanners/debug.rb +61 -0
- data/lib/coderay/scanners/delphi.rb +150 -0
- data/lib/coderay/scanners/diff.rb +104 -0
- data/lib/coderay/scanners/groovy.rb +271 -0
- data/lib/coderay/scanners/html.rb +175 -0
- data/lib/coderay/scanners/java.rb +173 -0
- data/lib/coderay/scanners/java/builtin_types.rb +419 -0
- data/lib/coderay/scanners/java_script.rb +195 -0
- data/lib/coderay/scanners/json.rb +107 -0
- data/lib/coderay/scanners/nitro_xhtml.rb +132 -0
- data/lib/coderay/scanners/php.rb +404 -0
- data/lib/coderay/scanners/plaintext.rb +18 -0
- data/lib/coderay/scanners/python.rb +232 -0
- data/lib/coderay/scanners/rhtml.rb +71 -0
- data/lib/coderay/scanners/ruby.rb +386 -0
- data/lib/coderay/scanners/ruby/patterns.rb +232 -0
- data/lib/coderay/scanners/scheme.rb +142 -0
- data/lib/coderay/scanners/sql.rb +162 -0
- data/lib/coderay/scanners/xml.rb +17 -0
- data/lib/coderay/scanners/yaml.rb +142 -0
- data/lib/coderay/style.rb +20 -0
- data/lib/coderay/styles/_map.rb +7 -0
- data/lib/coderay/styles/cycnus.rb +151 -0
- data/lib/coderay/styles/murphy.rb +132 -0
- data/lib/coderay/token_classes.rb +86 -0
- data/lib/coderay/tokens.rb +387 -0
- metadata +59 -1
@@ -0,0 +1,202 @@
|
|
1
|
+
module CodeRay
|
2
|
+
module Scanners
|
3
|
+
|
4
|
+
class CSS < Scanner
|
5
|
+
|
6
|
+
register_for :css
|
7
|
+
|
8
|
+
module RE
|
9
|
+
NonASCII = /[\x80-\xFF]/
|
10
|
+
Hex = /[0-9a-fA-F]/
|
11
|
+
Unicode = /\\#{Hex}{1,6}(?:\r\n|\s)?/ # differs from standard because it allows uppercase hex too
|
12
|
+
Escape = /#{Unicode}|\\[^\r\n\f0-9a-fA-F]/
|
13
|
+
NMChar = /[-_a-zA-Z0-9]|#{NonASCII}|#{Escape}/
|
14
|
+
NMStart = /[_a-zA-Z]|#{NonASCII}|#{Escape}/
|
15
|
+
NL = /\r\n|\r|\n|\f/
|
16
|
+
String1 = /"(?:[^\n\r\f\\"]|\\#{NL}|#{Escape})*"?/ # FIXME: buggy regexp
|
17
|
+
String2 = /'(?:[^\n\r\f\\']|\\#{NL}|#{Escape})*'?/ # FIXME: buggy regexp
|
18
|
+
String = /#{String1}|#{String2}/
|
19
|
+
|
20
|
+
HexColor = /#(?:#{Hex}{6}|#{Hex}{3})/
|
21
|
+
Color = /#{HexColor}/
|
22
|
+
|
23
|
+
Num = /-?(?:[0-9]+|[0-9]*\.[0-9]+)/
|
24
|
+
Name = /#{NMChar}+/
|
25
|
+
Ident = /-?#{NMStart}#{NMChar}*/
|
26
|
+
AtKeyword = /@#{Ident}/
|
27
|
+
Percentage = /#{Num}%/
|
28
|
+
|
29
|
+
reldimensions = %w[em ex px]
|
30
|
+
absdimensions = %w[in cm mm pt pc]
|
31
|
+
Unit = Regexp.union(*(reldimensions + absdimensions))
|
32
|
+
|
33
|
+
Dimension = /#{Num}#{Unit}/
|
34
|
+
|
35
|
+
Comment = %r! /\* (?: .*? \*/ | .* ) !mx
|
36
|
+
Function = /(?:url|alpha)\((?:[^)\n\r\f]|\\\))*\)?/
|
37
|
+
|
38
|
+
Id = /##{Name}/
|
39
|
+
Class = /\.#{Name}/
|
40
|
+
PseudoClass = /:#{Name}/
|
41
|
+
AttributeSelector = /\[[^\]]*\]?/
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def scan_tokens tokens, options
|
46
|
+
|
47
|
+
value_expected = nil
|
48
|
+
states = [:initial]
|
49
|
+
|
50
|
+
until eos?
|
51
|
+
|
52
|
+
kind = nil
|
53
|
+
match = nil
|
54
|
+
|
55
|
+
if scan(/\s+/)
|
56
|
+
kind = :space
|
57
|
+
|
58
|
+
elsif case states.last
|
59
|
+
when :initial, :media
|
60
|
+
if scan(/(?>#{RE::Ident})(?!\()|\*/ox)
|
61
|
+
kind = :keyword
|
62
|
+
elsif scan RE::Class
|
63
|
+
kind = :class
|
64
|
+
elsif scan RE::Id
|
65
|
+
kind = :constant
|
66
|
+
elsif scan RE::PseudoClass
|
67
|
+
kind = :pseudo_class
|
68
|
+
elsif match = scan(RE::AttributeSelector)
|
69
|
+
# TODO: Improve highlighting inside of attribute selectors.
|
70
|
+
tokens << [:open, :string]
|
71
|
+
tokens << [match[0,1], :delimiter]
|
72
|
+
tokens << [match[1..-2], :content] if match.size > 2
|
73
|
+
tokens << [match[-1,1], :delimiter] if match[-1] == ?]
|
74
|
+
tokens << [:close, :string]
|
75
|
+
next
|
76
|
+
elsif match = scan(/@media/)
|
77
|
+
kind = :directive
|
78
|
+
states.push :media_before_name
|
79
|
+
end
|
80
|
+
|
81
|
+
when :block
|
82
|
+
if scan(/(?>#{RE::Ident})(?!\()/ox)
|
83
|
+
if value_expected
|
84
|
+
kind = :value
|
85
|
+
else
|
86
|
+
kind = :key
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
when :media_before_name
|
91
|
+
if scan RE::Ident
|
92
|
+
kind = :type
|
93
|
+
states[-1] = :media_after_name
|
94
|
+
end
|
95
|
+
|
96
|
+
when :media_after_name
|
97
|
+
if scan(/\{/)
|
98
|
+
kind = :operator
|
99
|
+
states[-1] = :media
|
100
|
+
end
|
101
|
+
|
102
|
+
when :comment
|
103
|
+
if scan(/(?:[^*\s]|\*(?!\/))+/)
|
104
|
+
kind = :comment
|
105
|
+
elsif scan(/\*\//)
|
106
|
+
kind = :comment
|
107
|
+
states.pop
|
108
|
+
elsif scan(/\s+/)
|
109
|
+
kind = :space
|
110
|
+
end
|
111
|
+
|
112
|
+
else
|
113
|
+
raise_inspect 'Unknown state', tokens
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
elsif scan(/\/\*/)
|
118
|
+
kind = :comment
|
119
|
+
states.push :comment
|
120
|
+
|
121
|
+
elsif scan(/\{/)
|
122
|
+
value_expected = false
|
123
|
+
kind = :operator
|
124
|
+
states.push :block
|
125
|
+
|
126
|
+
elsif scan(/\}/)
|
127
|
+
value_expected = false
|
128
|
+
if states.last == :block || states.last == :media
|
129
|
+
kind = :operator
|
130
|
+
states.pop
|
131
|
+
else
|
132
|
+
kind = :error
|
133
|
+
end
|
134
|
+
|
135
|
+
elsif match = scan(/#{RE::String}/o)
|
136
|
+
tokens << [:open, :string]
|
137
|
+
tokens << [match[0, 1], :delimiter]
|
138
|
+
tokens << [match[1..-2], :content] if match.size > 2
|
139
|
+
tokens << [match[-1, 1], :delimiter] if match.size >= 2
|
140
|
+
tokens << [:close, :string]
|
141
|
+
next
|
142
|
+
|
143
|
+
elsif match = scan(/#{RE::Function}/o)
|
144
|
+
tokens << [:open, :string]
|
145
|
+
start = match[/^\w+\(/]
|
146
|
+
tokens << [start, :delimiter]
|
147
|
+
if match[-1] == ?)
|
148
|
+
tokens << [match[start.size..-2], :content]
|
149
|
+
tokens << [')', :delimiter]
|
150
|
+
else
|
151
|
+
tokens << [match[start.size..-1], :content]
|
152
|
+
end
|
153
|
+
tokens << [:close, :string]
|
154
|
+
next
|
155
|
+
|
156
|
+
elsif scan(/(?: #{RE::Dimension} | #{RE::Percentage} | #{RE::Num} )/ox)
|
157
|
+
kind = :float
|
158
|
+
|
159
|
+
elsif scan(/#{RE::Color}/o)
|
160
|
+
kind = :color
|
161
|
+
|
162
|
+
elsif scan(/! *important/)
|
163
|
+
kind = :important
|
164
|
+
|
165
|
+
elsif scan(/rgb\([^()\n]*\)?/)
|
166
|
+
kind = :color
|
167
|
+
|
168
|
+
elsif scan(/#{RE::AtKeyword}/o)
|
169
|
+
kind = :directive
|
170
|
+
|
171
|
+
elsif match = scan(/ [+>:;,.=()\/] /x)
|
172
|
+
if match == ':'
|
173
|
+
value_expected = true
|
174
|
+
elsif match == ';'
|
175
|
+
value_expected = false
|
176
|
+
end
|
177
|
+
kind = :operator
|
178
|
+
|
179
|
+
else
|
180
|
+
getch
|
181
|
+
kind = :error
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
match ||= matched
|
186
|
+
if $DEBUG and not kind
|
187
|
+
raise_inspect 'Error token %p in line %d' %
|
188
|
+
[[match, kind], line], tokens
|
189
|
+
end
|
190
|
+
raise_inspect 'Empty token', tokens unless match
|
191
|
+
|
192
|
+
tokens << [match, kind]
|
193
|
+
|
194
|
+
end
|
195
|
+
|
196
|
+
tokens
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
202
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module CodeRay
|
2
|
+
module Scanners
|
3
|
+
|
4
|
+
# = Debug Scanner
|
5
|
+
class Debug < Scanner
|
6
|
+
|
7
|
+
include Streamable
|
8
|
+
register_for :debug
|
9
|
+
file_extension 'raydebug'
|
10
|
+
|
11
|
+
protected
|
12
|
+
def scan_tokens tokens, options
|
13
|
+
|
14
|
+
opened_tokens = []
|
15
|
+
|
16
|
+
until eos?
|
17
|
+
|
18
|
+
kind = nil
|
19
|
+
match = nil
|
20
|
+
|
21
|
+
if scan(/\s+/)
|
22
|
+
tokens << [matched, :space]
|
23
|
+
next
|
24
|
+
|
25
|
+
elsif scan(/ (\w+) \( ( [^\)\\]* ( \\. [^\)\\]* )* ) \) /x)
|
26
|
+
kind = self[1].to_sym
|
27
|
+
match = self[2].gsub(/\\(.)/, '\1')
|
28
|
+
|
29
|
+
elsif scan(/ (\w+) < /x)
|
30
|
+
kind = self[1].to_sym
|
31
|
+
opened_tokens << kind
|
32
|
+
match = :open
|
33
|
+
|
34
|
+
elsif scan(/ > /x)
|
35
|
+
kind = opened_tokens.pop
|
36
|
+
match = :close
|
37
|
+
|
38
|
+
else
|
39
|
+
kind = :error
|
40
|
+
getch
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
match ||= matched
|
45
|
+
if $DEBUG and not kind
|
46
|
+
raise_inspect 'Error token %p in line %d' %
|
47
|
+
[[match, kind], line], tokens
|
48
|
+
end
|
49
|
+
raise_inspect 'Empty token', tokens unless match
|
50
|
+
|
51
|
+
tokens << [match, kind]
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
tokens
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
module CodeRay
|
2
|
+
module Scanners
|
3
|
+
|
4
|
+
class Delphi < Scanner
|
5
|
+
|
6
|
+
register_for :delphi
|
7
|
+
file_extension 'pas'
|
8
|
+
|
9
|
+
RESERVED_WORDS = [
|
10
|
+
'and', 'array', 'as', 'at', 'asm', 'at', 'begin', 'case', 'class',
|
11
|
+
'const', 'constructor', 'destructor', 'dispinterface', 'div', 'do',
|
12
|
+
'downto', 'else', 'end', 'except', 'exports', 'file', 'finalization',
|
13
|
+
'finally', 'for', 'function', 'goto', 'if', 'implementation', 'in',
|
14
|
+
'inherited', 'initialization', 'inline', 'interface', 'is', 'label',
|
15
|
+
'library', 'mod', 'nil', 'not', 'object', 'of', 'or', 'out', 'packed',
|
16
|
+
'procedure', 'program', 'property', 'raise', 'record', 'repeat',
|
17
|
+
'resourcestring', 'set', 'shl', 'shr', 'string', 'then', 'threadvar',
|
18
|
+
'to', 'try', 'type', 'unit', 'until', 'uses', 'var', 'while', 'with',
|
19
|
+
'xor', 'on'
|
20
|
+
]
|
21
|
+
|
22
|
+
DIRECTIVES = [
|
23
|
+
'absolute', 'abstract', 'assembler', 'at', 'automated', 'cdecl',
|
24
|
+
'contains', 'deprecated', 'dispid', 'dynamic', 'export',
|
25
|
+
'external', 'far', 'forward', 'implements', 'local',
|
26
|
+
'near', 'nodefault', 'on', 'overload', 'override',
|
27
|
+
'package', 'pascal', 'platform', 'private', 'protected', 'public',
|
28
|
+
'published', 'read', 'readonly', 'register', 'reintroduce',
|
29
|
+
'requires', 'resident', 'safecall', 'stdcall', 'stored', 'varargs',
|
30
|
+
'virtual', 'write', 'writeonly'
|
31
|
+
]
|
32
|
+
|
33
|
+
IDENT_KIND = CaseIgnoringWordList.new(:ident, caching=true).
|
34
|
+
add(RESERVED_WORDS, :reserved).
|
35
|
+
add(DIRECTIVES, :directive)
|
36
|
+
|
37
|
+
NAME_FOLLOWS = CaseIgnoringWordList.new(false, caching=true).
|
38
|
+
add(%w(procedure function .))
|
39
|
+
|
40
|
+
private
|
41
|
+
def scan_tokens tokens, options
|
42
|
+
|
43
|
+
state = :initial
|
44
|
+
last_token = ''
|
45
|
+
|
46
|
+
until eos?
|
47
|
+
|
48
|
+
kind = nil
|
49
|
+
match = nil
|
50
|
+
|
51
|
+
if state == :initial
|
52
|
+
|
53
|
+
if scan(/ \s+ /x)
|
54
|
+
tokens << [matched, :space]
|
55
|
+
next
|
56
|
+
|
57
|
+
elsif scan(%r! \{ \$ [^}]* \}? | \(\* \$ (?: .*? \*\) | .* ) !mx)
|
58
|
+
tokens << [matched, :preprocessor]
|
59
|
+
next
|
60
|
+
|
61
|
+
elsif scan(%r! // [^\n]* | \{ [^}]* \}? | \(\* (?: .*? \*\) | .* ) !mx)
|
62
|
+
tokens << [matched, :comment]
|
63
|
+
next
|
64
|
+
|
65
|
+
elsif match = scan(/ <[>=]? | >=? | :=? | [-+=*\/;,@\^|\(\)\[\]] | \.\. /x)
|
66
|
+
kind = :operator
|
67
|
+
|
68
|
+
elsif match = scan(/\./)
|
69
|
+
kind = :operator
|
70
|
+
if last_token == 'end'
|
71
|
+
tokens << [match, kind]
|
72
|
+
next
|
73
|
+
end
|
74
|
+
|
75
|
+
elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x)
|
76
|
+
kind = NAME_FOLLOWS[last_token] ? :ident : IDENT_KIND[match]
|
77
|
+
|
78
|
+
elsif match = scan(/ ' ( [^\n']|'' ) (?:'|$) /x)
|
79
|
+
tokens << [:open, :char]
|
80
|
+
tokens << ["'", :delimiter]
|
81
|
+
tokens << [self[1], :content]
|
82
|
+
tokens << ["'", :delimiter]
|
83
|
+
tokens << [:close, :char]
|
84
|
+
next
|
85
|
+
|
86
|
+
elsif match = scan(/ ' /x)
|
87
|
+
tokens << [:open, :string]
|
88
|
+
state = :string
|
89
|
+
kind = :delimiter
|
90
|
+
|
91
|
+
elsif scan(/ \# (?: \d+ | \$[0-9A-Fa-f]+ ) /x)
|
92
|
+
kind = :char
|
93
|
+
|
94
|
+
elsif scan(/ \$ [0-9A-Fa-f]+ /x)
|
95
|
+
kind = :hex
|
96
|
+
|
97
|
+
elsif scan(/ (?: \d+ ) (?![eE]|\.[^.]) /x)
|
98
|
+
kind = :integer
|
99
|
+
|
100
|
+
elsif scan(/ \d+ (?: \.\d+ (?: [eE][+-]? \d+ )? | [eE][+-]? \d+ ) /x)
|
101
|
+
kind = :float
|
102
|
+
|
103
|
+
else
|
104
|
+
kind = :error
|
105
|
+
getch
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
elsif state == :string
|
110
|
+
if scan(/[^\n']+/)
|
111
|
+
kind = :content
|
112
|
+
elsif scan(/''/)
|
113
|
+
kind = :char
|
114
|
+
elsif scan(/'/)
|
115
|
+
tokens << ["'", :delimiter]
|
116
|
+
tokens << [:close, :string]
|
117
|
+
state = :initial
|
118
|
+
next
|
119
|
+
elsif scan(/\n/)
|
120
|
+
tokens << [:close, :string]
|
121
|
+
kind = :error
|
122
|
+
state = :initial
|
123
|
+
else
|
124
|
+
raise "else case \' reached; %p not handled." % peek(1), tokens
|
125
|
+
end
|
126
|
+
|
127
|
+
else
|
128
|
+
raise 'else-case reached', tokens
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
match ||= matched
|
133
|
+
if $DEBUG and not kind
|
134
|
+
raise_inspect 'Error token %p in line %d' %
|
135
|
+
[[match, kind], line], tokens, state
|
136
|
+
end
|
137
|
+
raise_inspect 'Empty token', tokens unless match
|
138
|
+
|
139
|
+
last_token = match
|
140
|
+
tokens << [match, kind]
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
tokens
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module CodeRay
|
2
|
+
module Scanners
|
3
|
+
|
4
|
+
class Diff < Scanner
|
5
|
+
|
6
|
+
register_for :diff
|
7
|
+
|
8
|
+
def scan_tokens tokens, options
|
9
|
+
|
10
|
+
line_kind = nil
|
11
|
+
state = :initial
|
12
|
+
|
13
|
+
until eos?
|
14
|
+
kind = match = nil
|
15
|
+
|
16
|
+
if match = scan(/\n/)
|
17
|
+
if line_kind
|
18
|
+
tokens << [:end_line, line_kind]
|
19
|
+
line_kind = nil
|
20
|
+
end
|
21
|
+
tokens << [match, :space]
|
22
|
+
next
|
23
|
+
end
|
24
|
+
|
25
|
+
case state
|
26
|
+
|
27
|
+
when :initial
|
28
|
+
if match = scan(/--- |\+\+\+ |=+|_+/)
|
29
|
+
tokens << [:begin_line, line_kind = :head]
|
30
|
+
tokens << [match, :head]
|
31
|
+
next unless match = scan(/.+/)
|
32
|
+
kind = :plain
|
33
|
+
elsif match = scan(/Index: |Property changes on: /)
|
34
|
+
tokens << [:begin_line, line_kind = :head]
|
35
|
+
tokens << [match, :head]
|
36
|
+
next unless match = scan(/.+/)
|
37
|
+
kind = :plain
|
38
|
+
elsif match = scan(/Added: /)
|
39
|
+
tokens << [:begin_line, line_kind = :head]
|
40
|
+
tokens << [match, :head]
|
41
|
+
next unless match = scan(/.+/)
|
42
|
+
kind = :plain
|
43
|
+
state = :added
|
44
|
+
elsif match = scan(/\\ /)
|
45
|
+
tokens << [:begin_line, line_kind = :change]
|
46
|
+
tokens << [match, :change]
|
47
|
+
next unless match = scan(/.+/)
|
48
|
+
kind = :plain
|
49
|
+
elsif scan(/(@@)((?>[^@\n]*))(@@)/)
|
50
|
+
tokens << [:begin_line, line_kind = :change]
|
51
|
+
tokens << [self[1], :change]
|
52
|
+
tokens << [self[2], :plain]
|
53
|
+
tokens << [self[3], :change]
|
54
|
+
next unless match = scan(/.+/)
|
55
|
+
kind = :plain
|
56
|
+
elsif match = scan(/\+/)
|
57
|
+
tokens << [:begin_line, line_kind = :insert]
|
58
|
+
tokens << [match, :insert]
|
59
|
+
next unless match = scan(/.+/)
|
60
|
+
kind = :plain
|
61
|
+
elsif match = scan(/-/)
|
62
|
+
tokens << [:begin_line, line_kind = :delete]
|
63
|
+
tokens << [match, :delete]
|
64
|
+
next unless match = scan(/.+/)
|
65
|
+
kind = :plain
|
66
|
+
elsif scan(/ .*/)
|
67
|
+
kind = :comment
|
68
|
+
elsif scan(/.+/)
|
69
|
+
tokens << [:begin_line, line_kind = :head]
|
70
|
+
kind = :plain
|
71
|
+
else
|
72
|
+
raise_inspect 'else case rached'
|
73
|
+
end
|
74
|
+
|
75
|
+
when :added
|
76
|
+
if match = scan(/ \+/)
|
77
|
+
tokens << [:begin_line, line_kind = :insert]
|
78
|
+
tokens << [match, :insert]
|
79
|
+
next unless match = scan(/.+/)
|
80
|
+
kind = :plain
|
81
|
+
else
|
82
|
+
state = :initial
|
83
|
+
next
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
match ||= matched
|
88
|
+
if $DEBUG and not kind
|
89
|
+
raise_inspect 'Error token %p in line %d' %
|
90
|
+
[[match, kind], line], tokens
|
91
|
+
end
|
92
|
+
raise_inspect 'Empty token', tokens unless match
|
93
|
+
|
94
|
+
tokens << [match, kind]
|
95
|
+
end
|
96
|
+
|
97
|
+
tokens << [:end_line, line_kind] if line_kind
|
98
|
+
tokens
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|