giga-fast-rb 0.0.1
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.
- checksums.yaml +7 -0
- data/coderay-1.1.3/MIT-LICENSE +22 -0
- data/coderay-1.1.3/README_INDEX.rdoc +123 -0
- data/coderay-1.1.3/bin/coderay +215 -0
- data/coderay-1.1.3/lib/coderay/duo.rb +81 -0
- data/coderay-1.1.3/lib/coderay/encoders/_map.rb +17 -0
- data/coderay-1.1.3/lib/coderay/encoders/comment_filter.rb +25 -0
- data/coderay-1.1.3/lib/coderay/encoders/count.rb +39 -0
- data/coderay-1.1.3/lib/coderay/encoders/debug.rb +49 -0
- data/coderay-1.1.3/lib/coderay/encoders/debug_lint.rb +63 -0
- data/coderay-1.1.3/lib/coderay/encoders/div.rb +23 -0
- data/coderay-1.1.3/lib/coderay/encoders/encoder.rb +190 -0
- data/coderay-1.1.3/lib/coderay/encoders/filter.rb +58 -0
- data/coderay-1.1.3/lib/coderay/encoders/html/css.rb +65 -0
- data/coderay-1.1.3/lib/coderay/encoders/html/numbering.rb +108 -0
- data/coderay-1.1.3/lib/coderay/encoders/html/output.rb +164 -0
- data/coderay-1.1.3/lib/coderay/encoders/html.rb +333 -0
- data/coderay-1.1.3/lib/coderay/encoders/json.rb +83 -0
- data/coderay-1.1.3/lib/coderay/encoders/lines_of_code.rb +45 -0
- data/coderay-1.1.3/lib/coderay/encoders/lint.rb +59 -0
- data/coderay-1.1.3/lib/coderay/encoders/null.rb +18 -0
- data/coderay-1.1.3/lib/coderay/encoders/page.rb +24 -0
- data/coderay-1.1.3/lib/coderay/encoders/span.rb +23 -0
- data/coderay-1.1.3/lib/coderay/encoders/statistic.rb +95 -0
- data/coderay-1.1.3/lib/coderay/encoders/terminal.rb +195 -0
- data/coderay-1.1.3/lib/coderay/encoders/text.rb +46 -0
- data/coderay-1.1.3/lib/coderay/encoders/token_kind_filter.rb +111 -0
- data/coderay-1.1.3/lib/coderay/encoders/xml.rb +72 -0
- data/coderay-1.1.3/lib/coderay/encoders/yaml.rb +50 -0
- data/coderay-1.1.3/lib/coderay/encoders.rb +18 -0
- data/coderay-1.1.3/lib/coderay/for_redcloth.rb +95 -0
- data/coderay-1.1.3/lib/coderay/helpers/file_type.rb +151 -0
- data/coderay-1.1.3/lib/coderay/helpers/plugin.rb +55 -0
- data/coderay-1.1.3/lib/coderay/helpers/plugin_host.rb +221 -0
- data/coderay-1.1.3/lib/coderay/helpers/word_list.rb +72 -0
- data/coderay-1.1.3/lib/coderay/scanners/_map.rb +24 -0
- data/coderay-1.1.3/lib/coderay/scanners/c.rb +189 -0
- data/coderay-1.1.3/lib/coderay/scanners/clojure.rb +217 -0
- data/coderay-1.1.3/lib/coderay/scanners/cpp.rb +217 -0
- data/coderay-1.1.3/lib/coderay/scanners/css.rb +196 -0
- data/coderay-1.1.3/lib/coderay/scanners/debug.rb +75 -0
- data/coderay-1.1.3/lib/coderay/scanners/delphi.rb +144 -0
- data/coderay-1.1.3/lib/coderay/scanners/diff.rb +221 -0
- data/coderay-1.1.3/lib/coderay/scanners/erb.rb +81 -0
- data/coderay-1.1.3/lib/coderay/scanners/go.rb +208 -0
- data/coderay-1.1.3/lib/coderay/scanners/groovy.rb +268 -0
- data/coderay-1.1.3/lib/coderay/scanners/haml.rb +168 -0
- data/coderay-1.1.3/lib/coderay/scanners/html.rb +275 -0
- data/coderay-1.1.3/lib/coderay/scanners/java/builtin_types.rb +421 -0
- data/coderay-1.1.3/lib/coderay/scanners/java.rb +174 -0
- data/coderay-1.1.3/lib/coderay/scanners/java_script.rb +236 -0
- data/coderay-1.1.3/lib/coderay/scanners/json.rb +98 -0
- data/coderay-1.1.3/lib/coderay/scanners/lua.rb +280 -0
- data/coderay-1.1.3/lib/coderay/scanners/php.rb +527 -0
- data/coderay-1.1.3/lib/coderay/scanners/python.rb +287 -0
- data/coderay-1.1.3/lib/coderay/scanners/raydebug.rb +75 -0
- data/coderay-1.1.3/lib/coderay/scanners/ruby/patterns.rb +178 -0
- data/coderay-1.1.3/lib/coderay/scanners/ruby/string_state.rb +79 -0
- data/coderay-1.1.3/lib/coderay/scanners/ruby.rb +477 -0
- data/coderay-1.1.3/lib/coderay/scanners/sass.rb +232 -0
- data/coderay-1.1.3/lib/coderay/scanners/scanner.rb +337 -0
- data/coderay-1.1.3/lib/coderay/scanners/sql.rb +169 -0
- data/coderay-1.1.3/lib/coderay/scanners/taskpaper.rb +36 -0
- data/coderay-1.1.3/lib/coderay/scanners/text.rb +26 -0
- data/coderay-1.1.3/lib/coderay/scanners/xml.rb +17 -0
- data/coderay-1.1.3/lib/coderay/scanners/yaml.rb +140 -0
- data/coderay-1.1.3/lib/coderay/scanners.rb +27 -0
- data/coderay-1.1.3/lib/coderay/styles/_map.rb +7 -0
- data/coderay-1.1.3/lib/coderay/styles/alpha.rb +153 -0
- data/coderay-1.1.3/lib/coderay/styles/style.rb +18 -0
- data/coderay-1.1.3/lib/coderay/styles.rb +15 -0
- data/coderay-1.1.3/lib/coderay/token_kinds.rb +85 -0
- data/coderay-1.1.3/lib/coderay/tokens.rb +164 -0
- data/coderay-1.1.3/lib/coderay/tokens_proxy.rb +55 -0
- data/coderay-1.1.3/lib/coderay/version.rb +3 -0
- data/coderay-1.1.3/lib/coderay.rb +284 -0
- data/giga-fast-rb.gemspec +12 -0
- metadata +117 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
require 'set'
|
|
2
|
+
|
|
3
|
+
module CodeRay
|
|
4
|
+
module Scanners
|
|
5
|
+
|
|
6
|
+
# = Debug Scanner
|
|
7
|
+
#
|
|
8
|
+
# Interprets the output of the Encoders::Debug encoder (basically the inverse function).
|
|
9
|
+
class Debug < Scanner
|
|
10
|
+
|
|
11
|
+
register_for :debug
|
|
12
|
+
title 'CodeRay Token Dump Import'
|
|
13
|
+
|
|
14
|
+
protected
|
|
15
|
+
|
|
16
|
+
def setup
|
|
17
|
+
super
|
|
18
|
+
@known_token_kinds = TokenKinds.keys.map(&:to_s).to_set
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def scan_tokens encoder, options
|
|
22
|
+
|
|
23
|
+
opened_tokens = []
|
|
24
|
+
|
|
25
|
+
until eos?
|
|
26
|
+
|
|
27
|
+
if match = scan(/\s+/)
|
|
28
|
+
encoder.text_token match, :space
|
|
29
|
+
|
|
30
|
+
elsif match = scan(/ (\w+) \( ( [^\)\\]* ( \\. [^\)\\]* )* ) \)? /x)
|
|
31
|
+
if @known_token_kinds.include? self[1]
|
|
32
|
+
encoder.text_token self[2].gsub(/\\(.)/m, '\1'), self[1].to_sym
|
|
33
|
+
else
|
|
34
|
+
encoder.text_token matched, :unknown
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
elsif match = scan(/ (\w+) ([<\[]) /x)
|
|
38
|
+
if @known_token_kinds.include? self[1]
|
|
39
|
+
kind = self[1].to_sym
|
|
40
|
+
else
|
|
41
|
+
kind = :unknown
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
opened_tokens << kind
|
|
45
|
+
case self[2]
|
|
46
|
+
when '<'
|
|
47
|
+
encoder.begin_group kind
|
|
48
|
+
when '['
|
|
49
|
+
encoder.begin_line kind
|
|
50
|
+
else
|
|
51
|
+
raise 'CodeRay bug: This case should not be reached.'
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
elsif !opened_tokens.empty? && match = scan(/ > /x)
|
|
55
|
+
encoder.end_group opened_tokens.pop
|
|
56
|
+
|
|
57
|
+
elsif !opened_tokens.empty? && match = scan(/ \] /x)
|
|
58
|
+
encoder.end_line opened_tokens.pop
|
|
59
|
+
|
|
60
|
+
else
|
|
61
|
+
encoder.text_token getch, :space
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
encoder.end_group opened_tokens.pop until opened_tokens.empty?
|
|
68
|
+
|
|
69
|
+
encoder
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
module CodeRay
|
|
2
|
+
module Scanners
|
|
3
|
+
|
|
4
|
+
# Scanner for the Delphi language (Object Pascal).
|
|
5
|
+
#
|
|
6
|
+
# Alias: +pascal+
|
|
7
|
+
class Delphi < Scanner
|
|
8
|
+
|
|
9
|
+
register_for :delphi
|
|
10
|
+
file_extension 'pas'
|
|
11
|
+
|
|
12
|
+
KEYWORDS = [
|
|
13
|
+
'and', 'array', 'as', 'at', 'asm', 'at', 'begin', 'case', 'class',
|
|
14
|
+
'const', 'constructor', 'destructor', 'dispinterface', 'div', 'do',
|
|
15
|
+
'downto', 'else', 'end', 'except', 'exports', 'file', 'finalization',
|
|
16
|
+
'finally', 'for', 'function', 'goto', 'if', 'implementation', 'in',
|
|
17
|
+
'inherited', 'initialization', 'inline', 'interface', 'is', 'label',
|
|
18
|
+
'library', 'mod', 'nil', 'not', 'object', 'of', 'or', 'out', 'packed',
|
|
19
|
+
'procedure', 'program', 'property', 'raise', 'record', 'repeat',
|
|
20
|
+
'resourcestring', 'set', 'shl', 'shr', 'string', 'then', 'threadvar',
|
|
21
|
+
'to', 'try', 'type', 'unit', 'until', 'uses', 'var', 'while', 'with',
|
|
22
|
+
'xor', 'on',
|
|
23
|
+
] # :nodoc:
|
|
24
|
+
|
|
25
|
+
DIRECTIVES = [
|
|
26
|
+
'absolute', 'abstract', 'assembler', 'at', 'automated', 'cdecl',
|
|
27
|
+
'contains', 'deprecated', 'dispid', 'dynamic', 'export',
|
|
28
|
+
'external', 'far', 'forward', 'implements', 'local',
|
|
29
|
+
'near', 'nodefault', 'on', 'overload', 'override',
|
|
30
|
+
'package', 'pascal', 'platform', 'private', 'protected', 'public',
|
|
31
|
+
'published', 'read', 'readonly', 'register', 'reintroduce',
|
|
32
|
+
'requires', 'resident', 'safecall', 'stdcall', 'stored', 'varargs',
|
|
33
|
+
'virtual', 'write', 'writeonly',
|
|
34
|
+
] # :nodoc:
|
|
35
|
+
|
|
36
|
+
IDENT_KIND = WordList::CaseIgnoring.new(:ident).
|
|
37
|
+
add(KEYWORDS, :keyword).
|
|
38
|
+
add(DIRECTIVES, :directive) # :nodoc:
|
|
39
|
+
|
|
40
|
+
NAME_FOLLOWS = WordList::CaseIgnoring.new(false).
|
|
41
|
+
add(%w(procedure function .)) # :nodoc:
|
|
42
|
+
|
|
43
|
+
protected
|
|
44
|
+
|
|
45
|
+
def scan_tokens encoder, options
|
|
46
|
+
|
|
47
|
+
state = :initial
|
|
48
|
+
last_token = ''
|
|
49
|
+
|
|
50
|
+
until eos?
|
|
51
|
+
|
|
52
|
+
if state == :initial
|
|
53
|
+
|
|
54
|
+
if match = scan(/ \s+ /x)
|
|
55
|
+
encoder.text_token match, :space
|
|
56
|
+
next
|
|
57
|
+
|
|
58
|
+
elsif match = scan(%r! \{ \$ [^}]* \}? | \(\* \$ (?: .*? \*\) | .* ) !mx)
|
|
59
|
+
encoder.text_token match, :preprocessor
|
|
60
|
+
next
|
|
61
|
+
|
|
62
|
+
elsif match = scan(%r! // [^\n]* | \{ [^}]* \}? | \(\* (?: .*? \*\) | .* ) !mx)
|
|
63
|
+
encoder.text_token match, :comment
|
|
64
|
+
next
|
|
65
|
+
|
|
66
|
+
elsif match = scan(/ <[>=]? | >=? | :=? | [-+=*\/;,@\^|\(\)\[\]] | \.\. /x)
|
|
67
|
+
encoder.text_token match, :operator
|
|
68
|
+
|
|
69
|
+
elsif match = scan(/\./)
|
|
70
|
+
encoder.text_token match, :operator
|
|
71
|
+
next if last_token == 'end'
|
|
72
|
+
|
|
73
|
+
elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x)
|
|
74
|
+
encoder.text_token match, NAME_FOLLOWS[last_token] ? :ident : IDENT_KIND[match]
|
|
75
|
+
|
|
76
|
+
elsif match = skip(/ ' ( [^\n']|'' ) (?:'|$) /x)
|
|
77
|
+
encoder.begin_group :char
|
|
78
|
+
encoder.text_token "'", :delimiter
|
|
79
|
+
encoder.text_token self[1], :content
|
|
80
|
+
encoder.text_token "'", :delimiter
|
|
81
|
+
encoder.end_group :char
|
|
82
|
+
next
|
|
83
|
+
|
|
84
|
+
elsif match = scan(/ ' /x)
|
|
85
|
+
encoder.begin_group :string
|
|
86
|
+
encoder.text_token match, :delimiter
|
|
87
|
+
state = :string
|
|
88
|
+
|
|
89
|
+
elsif match = scan(/ \# (?: \d+ | \$[0-9A-Fa-f]+ ) /x)
|
|
90
|
+
encoder.text_token match, :char
|
|
91
|
+
|
|
92
|
+
elsif match = scan(/ \$ [0-9A-Fa-f]+ /x)
|
|
93
|
+
encoder.text_token match, :hex
|
|
94
|
+
|
|
95
|
+
elsif match = scan(/ (?: \d+ ) (?![eE]|\.[^.]) /x)
|
|
96
|
+
encoder.text_token match, :integer
|
|
97
|
+
|
|
98
|
+
elsif match = scan(/ \d+ (?: \.\d+ (?: [eE][+-]? \d+ )? | [eE][+-]? \d+ ) /x)
|
|
99
|
+
encoder.text_token match, :float
|
|
100
|
+
|
|
101
|
+
else
|
|
102
|
+
encoder.text_token getch, :error
|
|
103
|
+
next
|
|
104
|
+
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
elsif state == :string
|
|
108
|
+
if match = scan(/[^\n']+/)
|
|
109
|
+
encoder.text_token match, :content
|
|
110
|
+
elsif match = scan(/''/)
|
|
111
|
+
encoder.text_token match, :char
|
|
112
|
+
elsif match = scan(/'/)
|
|
113
|
+
encoder.text_token match, :delimiter
|
|
114
|
+
encoder.end_group :string
|
|
115
|
+
state = :initial
|
|
116
|
+
next
|
|
117
|
+
elsif match = scan(/\n/)
|
|
118
|
+
encoder.end_group :string
|
|
119
|
+
encoder.text_token match, :space
|
|
120
|
+
state = :initial
|
|
121
|
+
else
|
|
122
|
+
raise "else case \' reached; %p not handled." % peek(1), encoder
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
else
|
|
126
|
+
raise 'else-case reached', encoder
|
|
127
|
+
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
last_token = match
|
|
131
|
+
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
if state == :string
|
|
135
|
+
encoder.end_group state
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
encoder
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
end
|
|
144
|
+
end
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
module CodeRay
|
|
2
|
+
module Scanners
|
|
3
|
+
|
|
4
|
+
# Scanner for output of the diff command.
|
|
5
|
+
#
|
|
6
|
+
# Alias: +patch+
|
|
7
|
+
class Diff < Scanner
|
|
8
|
+
|
|
9
|
+
register_for :diff
|
|
10
|
+
title 'diff output'
|
|
11
|
+
|
|
12
|
+
DEFAULT_OPTIONS = {
|
|
13
|
+
:highlight_code => true,
|
|
14
|
+
:inline_diff => true,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
protected
|
|
18
|
+
|
|
19
|
+
def scan_tokens encoder, options
|
|
20
|
+
|
|
21
|
+
line_kind = nil
|
|
22
|
+
state = :initial
|
|
23
|
+
deleted_lines_count = 0
|
|
24
|
+
scanners = Hash.new do |h, lang|
|
|
25
|
+
h[lang] = Scanners[lang].new '', :keep_tokens => true, :keep_state => true
|
|
26
|
+
end
|
|
27
|
+
content_scanner = scanners[:plain]
|
|
28
|
+
content_scanner_entry_state = nil
|
|
29
|
+
|
|
30
|
+
until eos?
|
|
31
|
+
|
|
32
|
+
if match = scan(/\n/)
|
|
33
|
+
deleted_lines_count = 0 unless line_kind == :delete
|
|
34
|
+
if line_kind
|
|
35
|
+
encoder.end_line line_kind
|
|
36
|
+
line_kind = nil
|
|
37
|
+
end
|
|
38
|
+
encoder.text_token match, :space
|
|
39
|
+
next
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
case state
|
|
43
|
+
|
|
44
|
+
when :initial
|
|
45
|
+
if match = scan(/--- |\+\+\+ |=+|_+/)
|
|
46
|
+
encoder.begin_line line_kind = :head
|
|
47
|
+
encoder.text_token match, :head
|
|
48
|
+
if match = scan(/[^\x00\n]+?(?=$|[\t\n]| \(revision)/)
|
|
49
|
+
encoder.text_token match, :filename
|
|
50
|
+
if options[:highlight_code] && match != '/dev/null'
|
|
51
|
+
file_type = CodeRay::FileType.fetch(match, :text)
|
|
52
|
+
file_type = :text if file_type == :diff
|
|
53
|
+
content_scanner = scanners[file_type]
|
|
54
|
+
content_scanner_entry_state = nil
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
next unless match = scan(/.+/)
|
|
58
|
+
encoder.text_token match, :plain
|
|
59
|
+
elsif match = scan(/Index: |Property changes on: /)
|
|
60
|
+
encoder.begin_line line_kind = :head
|
|
61
|
+
encoder.text_token match, :head
|
|
62
|
+
next unless match = scan(/.+/)
|
|
63
|
+
encoder.text_token match, :plain
|
|
64
|
+
elsif match = scan(/Added: /)
|
|
65
|
+
encoder.begin_line line_kind = :head
|
|
66
|
+
encoder.text_token match, :head
|
|
67
|
+
next unless match = scan(/.+/)
|
|
68
|
+
encoder.text_token match, :plain
|
|
69
|
+
state = :added
|
|
70
|
+
elsif match = scan(/\\ .*/)
|
|
71
|
+
encoder.text_token match, :comment
|
|
72
|
+
elsif match = scan(/@@(?>[^@\n]+)@@/)
|
|
73
|
+
content_scanner.state = :initial unless match?(/\n\+/)
|
|
74
|
+
content_scanner_entry_state = nil
|
|
75
|
+
if check(/\n|$/)
|
|
76
|
+
encoder.begin_line line_kind = :change
|
|
77
|
+
else
|
|
78
|
+
encoder.begin_group :change
|
|
79
|
+
end
|
|
80
|
+
encoder.text_token match[0,2], :change
|
|
81
|
+
encoder.text_token match[2...-2], :plain
|
|
82
|
+
encoder.text_token match[-2,2], :change
|
|
83
|
+
encoder.end_group :change unless line_kind
|
|
84
|
+
next unless match = scan(/.+/)
|
|
85
|
+
if options[:highlight_code]
|
|
86
|
+
content_scanner.tokenize match, :tokens => encoder
|
|
87
|
+
else
|
|
88
|
+
encoder.text_token match, :plain
|
|
89
|
+
end
|
|
90
|
+
next
|
|
91
|
+
elsif match = scan(/\+/)
|
|
92
|
+
encoder.begin_line line_kind = :insert
|
|
93
|
+
encoder.text_token match, :insert
|
|
94
|
+
next unless match = scan(/.+/)
|
|
95
|
+
if options[:highlight_code]
|
|
96
|
+
content_scanner.tokenize match, :tokens => encoder
|
|
97
|
+
else
|
|
98
|
+
encoder.text_token match, :plain
|
|
99
|
+
end
|
|
100
|
+
next
|
|
101
|
+
elsif match = scan(/-/)
|
|
102
|
+
deleted_lines_count += 1
|
|
103
|
+
if options[:inline_diff] && deleted_lines_count == 1 && (changed_lines_count = 1 + check(/.*(?:\n\-.*)*/).count("\n")) && changed_lines_count <= 100_000 && match?(/(?>.*(?:\n\-.*){#{changed_lines_count - 1}}(?:\n\+.*){#{changed_lines_count}})$(?!\n\+)/)
|
|
104
|
+
deleted_lines = Array.new(changed_lines_count) { |i| skip(/\n\-/) if i > 0; scan(/.*/) }
|
|
105
|
+
inserted_lines = Array.new(changed_lines_count) { |i| skip(/\n\+/) ; scan(/.*/) }
|
|
106
|
+
|
|
107
|
+
deleted_lines_tokenized = []
|
|
108
|
+
inserted_lines_tokenized = []
|
|
109
|
+
for deleted_line, inserted_line in deleted_lines.zip(inserted_lines)
|
|
110
|
+
pre, deleted_part, inserted_part, post = diff deleted_line, inserted_line
|
|
111
|
+
content_scanner_entry_state = content_scanner.state
|
|
112
|
+
deleted_lines_tokenized << content_scanner.tokenize([pre, deleted_part, post], :tokens => Tokens.new)
|
|
113
|
+
content_scanner.state = content_scanner_entry_state || :initial
|
|
114
|
+
inserted_lines_tokenized << content_scanner.tokenize([pre, inserted_part, post], :tokens => Tokens.new)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
for pre, deleted_part, post in deleted_lines_tokenized
|
|
118
|
+
encoder.begin_line :delete
|
|
119
|
+
encoder.text_token '-', :delete
|
|
120
|
+
encoder.tokens pre
|
|
121
|
+
unless deleted_part.empty?
|
|
122
|
+
encoder.begin_group :eyecatcher
|
|
123
|
+
encoder.tokens deleted_part
|
|
124
|
+
encoder.end_group :eyecatcher
|
|
125
|
+
end
|
|
126
|
+
encoder.tokens post
|
|
127
|
+
encoder.end_line :delete
|
|
128
|
+
encoder.text_token "\n", :space
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
for pre, inserted_part, post in inserted_lines_tokenized
|
|
132
|
+
encoder.begin_line :insert
|
|
133
|
+
encoder.text_token '+', :insert
|
|
134
|
+
encoder.tokens pre
|
|
135
|
+
unless inserted_part.empty?
|
|
136
|
+
encoder.begin_group :eyecatcher
|
|
137
|
+
encoder.tokens inserted_part
|
|
138
|
+
encoder.end_group :eyecatcher
|
|
139
|
+
end
|
|
140
|
+
encoder.tokens post
|
|
141
|
+
changed_lines_count -= 1
|
|
142
|
+
if changed_lines_count > 0
|
|
143
|
+
encoder.end_line :insert
|
|
144
|
+
encoder.text_token "\n", :space
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
line_kind = :insert
|
|
149
|
+
|
|
150
|
+
elsif match = scan(/.*/)
|
|
151
|
+
encoder.begin_line line_kind = :delete
|
|
152
|
+
encoder.text_token '-', :delete
|
|
153
|
+
if options[:highlight_code]
|
|
154
|
+
if deleted_lines_count == 1
|
|
155
|
+
content_scanner_entry_state = content_scanner.state
|
|
156
|
+
end
|
|
157
|
+
content_scanner.tokenize match, :tokens => encoder unless match.empty?
|
|
158
|
+
if !match?(/\n-/)
|
|
159
|
+
if match?(/\n\+/)
|
|
160
|
+
content_scanner.state = content_scanner_entry_state || :initial
|
|
161
|
+
end
|
|
162
|
+
content_scanner_entry_state = nil
|
|
163
|
+
end
|
|
164
|
+
else
|
|
165
|
+
encoder.text_token match, :plain
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
next
|
|
169
|
+
elsif match = scan(/ .*/)
|
|
170
|
+
if options[:highlight_code]
|
|
171
|
+
content_scanner.tokenize match, :tokens => encoder
|
|
172
|
+
else
|
|
173
|
+
encoder.text_token match, :plain
|
|
174
|
+
end
|
|
175
|
+
next
|
|
176
|
+
elsif match = scan(/.+/)
|
|
177
|
+
encoder.begin_line line_kind = :comment
|
|
178
|
+
encoder.text_token match, :plain
|
|
179
|
+
else
|
|
180
|
+
raise_inspect 'else case rached'
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
when :added
|
|
184
|
+
if match = scan(/ \+/)
|
|
185
|
+
encoder.begin_line line_kind = :insert
|
|
186
|
+
encoder.text_token match, :insert
|
|
187
|
+
next unless match = scan(/.+/)
|
|
188
|
+
encoder.text_token match, :plain
|
|
189
|
+
else
|
|
190
|
+
state = :initial
|
|
191
|
+
next
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
encoder.end_line line_kind if line_kind
|
|
198
|
+
|
|
199
|
+
encoder
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
private
|
|
203
|
+
|
|
204
|
+
def diff a, b
|
|
205
|
+
# i will be the index of the leftmost difference from the left.
|
|
206
|
+
i_max = [a.size, b.size].min
|
|
207
|
+
i = 0
|
|
208
|
+
i += 1 while i < i_max && a[i] == b[i]
|
|
209
|
+
# j_min will be the index of the leftmost difference from the right.
|
|
210
|
+
j_min = i - i_max
|
|
211
|
+
# j will be the index of the rightmost difference from the right which
|
|
212
|
+
# does not precede the leftmost one from the left.
|
|
213
|
+
j = -1
|
|
214
|
+
j -= 1 while j >= j_min && a[j] == b[j]
|
|
215
|
+
return a[0...i], a[i..j], b[i..j], (j < -1) ? a[j + 1..-1] : ''
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
end
|
|
221
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
module CodeRay
|
|
2
|
+
module Scanners
|
|
3
|
+
|
|
4
|
+
load :html
|
|
5
|
+
load :ruby
|
|
6
|
+
|
|
7
|
+
# Scanner for HTML ERB templates.
|
|
8
|
+
class ERB < Scanner
|
|
9
|
+
|
|
10
|
+
register_for :erb
|
|
11
|
+
title 'HTML ERB Template'
|
|
12
|
+
|
|
13
|
+
KINDS_NOT_LOC = HTML::KINDS_NOT_LOC
|
|
14
|
+
|
|
15
|
+
ERB_RUBY_BLOCK = /
|
|
16
|
+
(<%(?!%)[-=\#]?)
|
|
17
|
+
((?>
|
|
18
|
+
[^\-%]* # normal*
|
|
19
|
+
(?> # special
|
|
20
|
+
(?: %(?!>) | -(?!%>) )
|
|
21
|
+
[^\-%]* # normal*
|
|
22
|
+
)*
|
|
23
|
+
))
|
|
24
|
+
((?: -?%> )?)
|
|
25
|
+
/x # :nodoc:
|
|
26
|
+
|
|
27
|
+
START_OF_ERB = /
|
|
28
|
+
<%(?!%)
|
|
29
|
+
/x # :nodoc:
|
|
30
|
+
|
|
31
|
+
protected
|
|
32
|
+
|
|
33
|
+
def setup
|
|
34
|
+
@ruby_scanner = CodeRay.scanner :ruby, :tokens => @tokens, :keep_tokens => true
|
|
35
|
+
@html_scanner = CodeRay.scanner :html, :tokens => @tokens, :keep_tokens => true, :keep_state => true
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def reset_instance
|
|
39
|
+
super
|
|
40
|
+
@html_scanner.reset
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def scan_tokens encoder, options
|
|
44
|
+
|
|
45
|
+
until eos?
|
|
46
|
+
|
|
47
|
+
if (match = scan_until(/(?=#{START_OF_ERB})/o) || scan_rest) and not match.empty?
|
|
48
|
+
@html_scanner.tokenize match, :tokens => encoder
|
|
49
|
+
|
|
50
|
+
elsif match = scan(/#{ERB_RUBY_BLOCK}/o)
|
|
51
|
+
start_tag = self[1]
|
|
52
|
+
code = self[2]
|
|
53
|
+
end_tag = self[3]
|
|
54
|
+
|
|
55
|
+
encoder.begin_group :inline
|
|
56
|
+
encoder.text_token start_tag, :inline_delimiter
|
|
57
|
+
|
|
58
|
+
if start_tag == '<%#'
|
|
59
|
+
encoder.text_token code, :comment
|
|
60
|
+
else
|
|
61
|
+
@ruby_scanner.tokenize code, :tokens => encoder
|
|
62
|
+
end unless code.empty?
|
|
63
|
+
|
|
64
|
+
encoder.text_token end_tag, :inline_delimiter unless end_tag.empty?
|
|
65
|
+
encoder.end_group :inline
|
|
66
|
+
|
|
67
|
+
else
|
|
68
|
+
raise_inspect 'else-case reached!', encoder
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
encoder
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
end
|