2007-08-16 00:20:18 +04:00
|
|
|
module CodeRay
|
|
|
|
module Scanners
|
|
|
|
|
|
|
|
# = Debug Scanner
|
|
|
|
class Debug < Scanner
|
|
|
|
|
|
|
|
include Streamable
|
|
|
|
register_for :debug
|
2010-03-16 23:29:12 +03:00
|
|
|
file_extension 'raydebug'
|
|
|
|
title 'CodeRay Token Dump'
|
2007-08-16 00:20:18 +04:00
|
|
|
|
|
|
|
protected
|
|
|
|
def scan_tokens tokens, options
|
|
|
|
|
|
|
|
opened_tokens = []
|
|
|
|
|
|
|
|
until eos?
|
|
|
|
|
|
|
|
kind = nil
|
|
|
|
match = nil
|
|
|
|
|
|
|
|
if scan(/\s+/)
|
|
|
|
tokens << [matched, :space]
|
|
|
|
next
|
|
|
|
|
|
|
|
elsif scan(/ (\w+) \( ( [^\)\\]* ( \\. [^\)\\]* )* ) \) /x)
|
|
|
|
kind = self[1].to_sym
|
|
|
|
match = self[2].gsub(/\\(.)/, '\1')
|
|
|
|
|
|
|
|
elsif scan(/ (\w+) < /x)
|
|
|
|
kind = self[1].to_sym
|
|
|
|
opened_tokens << kind
|
|
|
|
match = :open
|
|
|
|
|
2010-03-16 23:29:12 +03:00
|
|
|
elsif !opened_tokens.empty? && scan(/ > /x)
|
|
|
|
kind = opened_tokens.pop || :error
|
2007-08-16 00:20:18 +04:00
|
|
|
match = :close
|
|
|
|
|
|
|
|
else
|
|
|
|
kind = :error
|
|
|
|
getch
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
match ||= matched
|
2010-03-16 23:29:12 +03:00
|
|
|
if $CODERAY_DEBUG and not kind
|
2007-08-16 00:20:18 +04:00
|
|
|
raise_inspect 'Error token %p in line %d' %
|
|
|
|
[[match, kind], line], tokens
|
|
|
|
end
|
|
|
|
raise_inspect 'Empty token', tokens unless match
|
|
|
|
|
|
|
|
tokens << [match, kind]
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
tokens
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|