Chris@909: module CodeRay Chris@909: module Scanners Chris@909: Chris@909: # = Debug Scanner Chris@909: # Chris@909: # Interprets the output of the Encoders::Debug encoder. Chris@909: class Debug < Scanner Chris@909: Chris@909: register_for :debug Chris@909: title 'CodeRay Token Dump Import' Chris@909: Chris@909: protected Chris@909: Chris@909: def scan_tokens encoder, options Chris@909: Chris@909: opened_tokens = [] Chris@909: Chris@909: until eos? Chris@909: Chris@909: if match = scan(/\s+/) Chris@909: encoder.text_token match, :space Chris@909: Chris@909: elsif match = scan(/ (\w+) \( ( [^\)\\]* ( \\. [^\)\\]* )* ) \)? /x) Chris@909: kind = self[1].to_sym Chris@909: match = self[2].gsub(/\\(.)/m, '\1') Chris@909: unless TokenKinds.has_key? kind Chris@909: kind = :error Chris@909: match = matched Chris@909: end Chris@909: encoder.text_token match, kind Chris@909: Chris@909: elsif match = scan(/ (\w+) ([<\[]) /x) Chris@909: kind = self[1].to_sym Chris@909: opened_tokens << kind Chris@909: case self[2] Chris@909: when '<' Chris@909: encoder.begin_group kind Chris@909: when '[' Chris@909: encoder.begin_line kind Chris@909: else Chris@909: raise 'CodeRay bug: This case should not be reached.' Chris@909: end Chris@909: Chris@909: elsif !opened_tokens.empty? && match = scan(/ > /x) Chris@909: encoder.end_group opened_tokens.pop Chris@909: Chris@909: elsif !opened_tokens.empty? && match = scan(/ \] /x) Chris@909: encoder.end_line opened_tokens.pop Chris@909: Chris@909: else Chris@909: encoder.text_token getch, :space Chris@909: Chris@909: end Chris@909: Chris@909: end Chris@909: Chris@909: encoder.end_group opened_tokens.pop until opened_tokens.empty? Chris@909: Chris@909: encoder Chris@909: end Chris@909: Chris@909: end Chris@909: Chris@909: end Chris@909: end