Chris@909: module CodeRay Chris@909: module Scanners Chris@909: Chris@909: # = Debug Scanner Chris@909: # Chris@909: # Parses the output of the Encoders::Debug encoder. Chris@909: class Raydebug < Scanner Chris@909: Chris@909: register_for :raydebug Chris@909: file_extension 'raydebug' Chris@909: title 'CodeRay Token Dump' 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] Chris@909: encoder.text_token kind, :class Chris@909: encoder.text_token '(', :operator Chris@909: match = self[2] Chris@909: encoder.text_token match, kind.to_sym Chris@909: encoder.text_token match, :operator if match = scan(/\)/) Chris@909: Chris@909: elsif match = scan(/ (\w+) ([<\[]) /x) Chris@909: kind = self[1] Chris@909: case self[2] Chris@909: when '<' Chris@909: encoder.text_token kind, :class Chris@909: when '[' Chris@909: encoder.text_token kind, :class Chris@909: else Chris@909: raise 'CodeRay bug: This case should not be reached.' Chris@909: end Chris@909: kind = kind.to_sym Chris@909: opened_tokens << kind Chris@909: encoder.begin_group kind Chris@909: encoder.text_token self[2], :operator Chris@909: Chris@909: elsif !opened_tokens.empty? && match = scan(/ [>\]] /x) Chris@909: encoder.text_token match, :operator Chris@909: encoder.end_group 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