#!/usr/bin/env ruby -dw require 'rubylexer' require 'getoptlong' #a Token#inspect that omits the object id class Token def inspect ["#<",self.class,": ",instance_variables.sort.collect{|v| [v,"=",instance_variable_get(v).inspect," "] }].to_s.sub(/ $/,'>') 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='-' $stdout end lexer=RubyLexer.new(name, file) until EoiToken===(tok=lexer.get1token) p tok end p tok #print eoi token