annotate vendor/gems/coderay-1.0.0/lib/coderay/scanners/raydebug.rb @ 1169:492ff72268e3 bug_521

Close obsolete branch bug_521
author Chris Cannam
date Thu, 18 Oct 2012 10:42:48 +0100
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 # Parses the output of the Encoders::Debug encoder.
Chris@909 7 class Raydebug < Scanner
Chris@909 8
Chris@909 9 register_for :raydebug
Chris@909 10 file_extension 'raydebug'
Chris@909 11 title 'CodeRay Token Dump'
Chris@909 12
Chris@909 13 protected
Chris@909 14
Chris@909 15 def scan_tokens encoder, options
Chris@909 16
Chris@909 17 opened_tokens = []
Chris@909 18
Chris@909 19 until eos?
Chris@909 20
Chris@909 21 if match = scan(/\s+/)
Chris@909 22 encoder.text_token match, :space
Chris@909 23
Chris@909 24 elsif match = scan(/ (\w+) \( ( [^\)\\]* ( \\. [^\)\\]* )* ) /x)
Chris@909 25 kind = self[1]
Chris@909 26 encoder.text_token kind, :class
Chris@909 27 encoder.text_token '(', :operator
Chris@909 28 match = self[2]
Chris@909 29 encoder.text_token match, kind.to_sym
Chris@909 30 encoder.text_token match, :operator if match = scan(/\)/)
Chris@909 31
Chris@909 32 elsif match = scan(/ (\w+) ([<\[]) /x)
Chris@909 33 kind = self[1]
Chris@909 34 case self[2]
Chris@909 35 when '<'
Chris@909 36 encoder.text_token kind, :class
Chris@909 37 when '['
Chris@909 38 encoder.text_token kind, :class
Chris@909 39 else
Chris@909 40 raise 'CodeRay bug: This case should not be reached.'
Chris@909 41 end
Chris@909 42 kind = kind.to_sym
Chris@909 43 opened_tokens << kind
Chris@909 44 encoder.begin_group kind
Chris@909 45 encoder.text_token self[2], :operator
Chris@909 46
Chris@909 47 elsif !opened_tokens.empty? && match = scan(/ [>\]] /x)
Chris@909 48 encoder.text_token match, :operator
Chris@909 49 encoder.end_group opened_tokens.pop
Chris@909 50
Chris@909 51 else
Chris@909 52 encoder.text_token getch, :space
Chris@909 53
Chris@909 54 end
Chris@909 55
Chris@909 56 end
Chris@909 57
Chris@909 58 encoder.end_group opened_tokens.pop until opened_tokens.empty?
Chris@909 59
Chris@909 60 encoder
Chris@909 61 end
Chris@909 62
Chris@909 63 end
Chris@909 64
Chris@909 65 end
Chris@909 66 end