I use StringScanner for lexical analysis as follows:
def next @scanner.skip(/\s+/) value,kind=nil,nil TOKEN_DEF.each{|tok,regex| (kind=tok;break) if @scanner.scan(regex)} return Token.new(kind,value,@line,@scanner.pos) end
In a first approximation, this works well, except that I cannot figure out how to get the @line number now.
I read a document where begin_of_line? the method seems appropriate, but I cannot figure out how to use it.
source share