On May 12, 2006, at 8:35 PM, Meador Inge wrote: > Is there lightweight lexer for Ruby? I have seen a few lexer > generators out there, but I want something simple that can be used > without generating the lexer first. I really just need the basic > functionaliy of matching a pattern and associating an action with that > pattern. For example, I was thinking something like: > class MyLexer < Lexer > rule /a/ do > # action for pattern a > end > rule /b/ do > # action for pattern b > end > rule /c/ do > # action for pattern c > end > end > > l = MyLexer.new(input_stream) > l.each_token do |token| > # do something with token > end > > I have something similar to the above that I have created. However, I > wanted to check and see what is out there first before I invested too > much time in it. If no one knows of anything else and\or is interested > in what I have described let me know and I will clean it up and > publish it. > > --Meador > StringScanner is close if you combine it with ifs.