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