Sha256: 06aef5d7c066937d0c34354f110178c650eb027f868803fee5627d454c39034d

Contents?: true

Size: 782 Bytes

Versions: 1

Compression:

Stored size: 782 Bytes

Contents

#!/usr/bin/env ruby
$Debug=true
require 'rubylexer'
require 'getoptlong'

#def puts(x) end

#a Token#inspect that omits the object id
class RubyLexer
class Token
  def strify
    [self.class.name[/[^:]+$/],": ",instance_variables.sort.collect{|v| 
      [v,"=",instance_variable_get(v).inspect," "]
    }].to_s
  end
end
end

file=nil

#allow -e
opts=GetoptLong.new(["--eval", "-e", GetoptLong::REQUIRED_ARGUMENT])
opts.each{|opt,arg|
  opt=='--eval' or raise :impossible
  file=arg
  name='-e'
}
     
#determine input file and its name if not already known
file||=if name=ARGV.first
    File.open(name)
  else 
    name='-'
    $stdin
  end

lexer=RubyLexer.new(name, file) 
until RubyLexer::EoiToken===(tok=lexer.get1token)
  puts tok.strify
end
puts tok.strify #print eoi token

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubylexer-0.7.0 test/code/dumptokens.rb