Mercurial > hg > soundsoftware-site
comparison vendor/gems/coderay-1.0.0/lib/coderay/scanners/debug.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
1 module CodeRay | |
2 module Scanners | |
3 | |
4 # = Debug Scanner | |
5 # | |
6 # Interprets the output of the Encoders::Debug encoder. | |
7 class Debug < Scanner | |
8 | |
9 register_for :debug | |
10 title 'CodeRay Token Dump Import' | |
11 | |
12 protected | |
13 | |
14 def scan_tokens encoder, options | |
15 | |
16 opened_tokens = [] | |
17 | |
18 until eos? | |
19 | |
20 if match = scan(/\s+/) | |
21 encoder.text_token match, :space | |
22 | |
23 elsif match = scan(/ (\w+) \( ( [^\)\\]* ( \\. [^\)\\]* )* ) \)? /x) | |
24 kind = self[1].to_sym | |
25 match = self[2].gsub(/\\(.)/m, '\1') | |
26 unless TokenKinds.has_key? kind | |
27 kind = :error | |
28 match = matched | |
29 end | |
30 encoder.text_token match, kind | |
31 | |
32 elsif match = scan(/ (\w+) ([<\[]) /x) | |
33 kind = self[1].to_sym | |
34 opened_tokens << kind | |
35 case self[2] | |
36 when '<' | |
37 encoder.begin_group kind | |
38 when '[' | |
39 encoder.begin_line kind | |
40 else | |
41 raise 'CodeRay bug: This case should not be reached.' | |
42 end | |
43 | |
44 elsif !opened_tokens.empty? && match = scan(/ > /x) | |
45 encoder.end_group opened_tokens.pop | |
46 | |
47 elsif !opened_tokens.empty? && match = scan(/ \] /x) | |
48 encoder.end_line opened_tokens.pop | |
49 | |
50 else | |
51 encoder.text_token getch, :space | |
52 | |
53 end | |
54 | |
55 end | |
56 | |
57 encoder.end_group opened_tokens.pop until opened_tokens.empty? | |
58 | |
59 encoder | |
60 end | |
61 | |
62 end | |
63 | |
64 end | |
65 end |