= RubyLexer * rubyforge.net/projects/rubylexer * github.com/coatl/rubylexer === DESCRIPTION: RubyLexer is a lexer library for Ruby, written in Ruby. Rubylexer is meant as a lexer for Ruby that's complete and correct; all legal Ruby code should be lexed correctly by RubyLexer as well. Just enough parsing capability is included to give RubyLexer enough context to tokenize correctly in all cases. (This turned out to be more parsing than I had thought or wanted to take on at first.) RubyLexer handles the hard things like complicated strings, the ambiguous nature of some punctuation characters and keywords in ruby, and distinguishing methods and local variables. It should be able to correctly lex 99.9+% of legal ruby code. RubyLexer is not particularly clean code. As I progressed in writing this, I've learned a little about how these things are supposed to be done; the lexer is not supposed to have any state of it's own, instead it gets whatever it needs to know from the parser. As a stand-alone lexer, Rubylexer maintains quite a lot of state. Every instance variable in the RubyLexer class is some sort of lexer state. Most of the complication and ugly code in RubyLexer is in maintaining or using this state. For information about using RubyLexer in your program, please see howtouse.txt. For my notes on the testing of RubyLexer, see testing.txt. If you have any questions, comments, problems, new feature requests, or just want to figure out how to make it work for what you need to do, contact me: rubylexer _at_ inforadical _dot_ net Bugs or problems with rubylexer should be submitted to the bug stream for rubylexer's github project: http://github.com/coatl/rubylexer/bugs ==SYNOPSIS: require "rubylexer.rb" #then later lexer=RubyLexer.new(a_file_name, opened_File_or_String) until EoiToken===(token=lexer.get1token) #...do stuff w/ token... end == Status RubyLexer can correctly lex all legal Ruby 1.8 and 1.9 code that I've been able to find. (And I've found quite a bit.) It can also handle (most of) my catalog of nasty test cases (see below for known problems). Modulo some very obscure bugs, RubyLexer can correctly distinguish these ambiguous uses of the following operators, depending on context: % can be modulus operator or start of fancy string / can be division operator or start of regex * & + - :: can be unary or binary operator [] can be for array literal or [] method (or []=) << can be here document or left shift operator (or in class<