[ANN] Wirble 0.1.1: Irb Enhancements for the Masses

L

Logan Capaldo

You can use the lexer built into irb. I forget how it's
done, but I did it two years ago. ;)

You certainly can steal irb's lexer. Here's an example from some code
I've been kicking around for a while, so you can see how it works:

(This code understands a very minimal set of ruby and turns it into a
sort of Sexpr)

require 'irb/ruby-lex'
module RubyMerge
class ParseSkeleton
def initialize(io)
@io = io
end

def skeleton
lexer = RubyLex.new
stack = []
results = []
lexer.set_input( @io )
while current = lexer.token
case current
when RubyLex::TkDEF, RubyLex::TkMODULE
if stack.empty?
results << current.name.to_sym
ident = nil
1 while ( ident = lexer.token ).kind_of? RubyLex::TkSPACE
results << ident.name
else
if results.last.kind_of? Array
results.last << current.name.to_sym
ident = nil
1 while ( ident = lexer.token ).kind_of? RubyLex::TkSPACE
results.last << ident.name
else
results << []
results.last << current.name.to_sym
ident = nil
1 while ( ident = lexer.token ).kind_of? RubyLex::TkSPACE
results.last << ident.name
end
end
stack.push current
when RubyLex::TkEND
stack.pop
end
end
results
end
end
end
 
B

Benjohn Barnes


Am I doing this wrong? ...
benjohn # sudo gem instal wirble --source http://pablotron.org/
files/gems/wirble-0.1.2.gem
ERROR: While executing gem ... (Gem::RemoteSourceException)
HTTP Response 404
benjohn #

Thanks,
Benjohn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top