Lexer taken verbatim from OboParser and other mjy gems.
# File lib/splitter/lexer.rb, line 6 def initialize(input, token_list = nil) raise Taxonifi::Splitter::SplitterError, "Invalid token list passed to Lexer." if (!token_list.nil? && !Taxonifi::Splitter::TOKEN_LISTS.include?(token_list) ) token_list = :global_token_list if token_list.nil? @input = input @token_list = token_list @next_token = nil end
Checks whether the next token is of the specified class.
# File lib/splitter/lexer.rb, line 17 def peek(token_class, token_list = nil) token = read_next_token(token_class) return token.class == token_class end
Return (and delete) the next token from the input stream, or raise an exception if the next token is not of the given class.
# File lib/splitter/lexer.rb, line 24 def pop(token_class) token = read_next_token(token_class) @next_token = nil if token.class != token_class raise(Taxonifi::Splitter::SplitterError, "expected #{token_class.to_s} but received #{token.class.to_s} at #{@input[0..10]}...", caller) else return token end end