annotate vendor/gems/coderay-1.0.0/lib/coderay/scanners/debug.rb @ 1022:f2ec92061fca browsing

Merge from live branch
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Tue, 13 Nov 2012 10:35:40 +0000
parents cbb26bc654de
children
rev   line source
Chris@909 1 module CodeRay
Chris@909 2 module Scanners
Chris@909 3
Chris@909 4 # = Debug Scanner
Chris@909 5 #
Chris@909 6 # Interprets the output of the Encoders::Debug encoder.
Chris@909 7 class Debug < Scanner
Chris@909 8
Chris@909 9 register_for :debug
Chris@909 10 title 'CodeRay Token Dump Import'
Chris@909 11
Chris@909 12 protected
Chris@909 13
Chris@909 14 def scan_tokens encoder, options
Chris@909 15
Chris@909 16 opened_tokens = []
Chris@909 17
Chris@909 18 until eos?
Chris@909 19
Chris@909 20 if match = scan(/\s+/)
Chris@909 21 encoder.text_token match, :space
Chris@909 22
Chris@909 23 elsif match = scan(/ (\w+) \( ( [^\)\\]* ( \\. [^\)\\]* )* ) \)? /x)
Chris@909 24 kind = self[1].to_sym
Chris@909 25 match = self[2].gsub(/\\(.)/m, '\1')
Chris@909 26 unless TokenKinds.has_key? kind
Chris@909 27 kind = :error
Chris@909 28 match = matched
Chris@909 29 end
Chris@909 30 encoder.text_token match, kind
Chris@909 31
Chris@909 32 elsif match = scan(/ (\w+) ([<\[]) /x)
Chris@909 33 kind = self[1].to_sym
Chris@909 34 opened_tokens << kind
Chris@909 35 case self[2]
Chris@909 36 when '<'
Chris@909 37 encoder.begin_group kind
Chris@909 38 when '['
Chris@909 39 encoder.begin_line kind
Chris@909 40 else
Chris@909 41 raise 'CodeRay bug: This case should not be reached.'
Chris@909 42 end
Chris@909 43
Chris@909 44 elsif !opened_tokens.empty? && match = scan(/ > /x)
Chris@909 45 encoder.end_group opened_tokens.pop
Chris@909 46
Chris@909 47 elsif !opened_tokens.empty? && match = scan(/ \] /x)
Chris@909 48 encoder.end_line opened_tokens.pop
Chris@909 49
Chris@909 50 else
Chris@909 51 encoder.text_token getch, :space
Chris@909 52
Chris@909 53 end
Chris@909 54
Chris@909 55 end
Chris@909 56
Chris@909 57 encoder.end_group opened_tokens.pop until opened_tokens.empty?
Chris@909 58
Chris@909 59 encoder
Chris@909 60 end
Chris@909 61
Chris@909 62 end
Chris@909 63
Chris@909 64 end
Chris@909 65 end