Class: RubyLexer::SimpleTokenPrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/rubylexer/tokenprinter.rb

Overview


Constant Summary collapse

TOKENSPERLINE =
8
TOKENSMAGICMAP =
"\n"+' '*(TOKENSPERLINE-1)

Instance Method Summary collapse

Constructor Details

#initialize(*bogus) ⇒ SimpleTokenPrinter

Returns a new instance of SimpleTokenPrinter.



30
31
32
# File 'lib/rubylexer/tokenprinter.rb', line 30

def initialize(*bogus)
   @tokens=@srclines=0
end

Instance Method Details

#pprint(tok, output = $stdout) ⇒ Object



37
# File 'lib/rubylexer/tokenprinter.rb', line 37

def pprint(tok,output=$stdout) output.print(sprint(tok)) end

#sprint(tok) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/rubylexer/tokenprinter.rb', line 39

def sprint(tok)
   case tok
   when Newline then "#{@lastfal if ((@srclines+=1)%16==0)} #; "
   when FileAndLineToken then @lastfal=tok;''
   when IgnoreToken then ''  #skip comments&whitespace
   else tok.to_s + TOKENSMAGICMAP[ (@tokens+=1) % TOKENSPERLINE, 1 ]
   end
end