Quoting flgr / ccan.de, on Fri, Mar 25, 2005 at 02:34:48AM +0900:
> Sam Roberts wrote:
> 
> >>why not ParseTree or ripper ?
> >
> >I have no idea what ripper does, but parse tree just gives symbols, it
> >doesn't have enough information for me to build a regex, as above, does
> >it?
> 
> Ripper basically is Ruby's integrated Ruby parser. It will invoke 
> callbacks for every kind of construct it encounters.

Hm, look like it returns whitespace, and other non-syntactic elements.
Good.  Does it return end-of-line, and is it just a lexer, or is it a
parser, too?

I.e., does

  MyParser.new.parse("class Foo; Bar = 4; end;")

tell me that the Foo is a class name, and Bar is a constant name, or do
I have to deduce that?

If so, maybe i'll try.

The rubyforge page makes it look as if it may be written in C based on
ruby's parser, using lex&yacc. If so, that would be sweet, because it
might be fast.

Thanks,
Sam

> This code snippet ought to get you started with it:
> 
> irb(main):017:0> class MyParser < Ripper
> irb(main):018:1>   def method_missing(name, *args)
> irb(main):019:2>     puts "#{name}: #{args.inspect}"
> irb(main):020:2>   end
> irb(main):021:1> end
> => nil
> irb(main):022:0> MyParser.new.parse("puts 'Hello World!' if true")
> on__scan: ["puts"]
> on__IDENTIFIER: ["puts"]
> on__scan: [" "]
> on__space: [" "]
> on__scan: ["'"]
> on__new_string: ["'"]
> on__scan: ["Hello World!"]
> on__add_string: [nil, "Hello World!"]
> on__scan: ["'"]
> on__string_end: [nil, "'"]
> on__scan: [" "]
> on__space: [" "]
> on__scan: ["if"]
> on__KEYWORD: ["if"]
> on__argstart: ["Hello World!"]
> on__fcall: [:puts, nil]
> on__scan: [" "]
> on__space: [" "]
> on__scan: ["true"]
> on__KEYWORD: ["true"]
> on__varref: [:true]
> on__if_mod: [nil, nil]
> => nil
>