To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 56 / 560f0241ba8e6899cca067c7cd63919a0ce16a9c.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (1.51 KB)
| 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 |