From dc30b8b6c1cab994ab62c78e101fded0516f9e79 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Thu, 7 Jul 2016 18:31:45 -0700 Subject: [PATCH] Remove Lexer#reset method Resolves https://github.com/YorickPeterse/oga/issues/153. --- lib/oga/xml/lexer.rb | 18 +----------------- lib/oga/xml/parser.rll | 2 +- spec/oga/xml/lexer/io_spec.rb | 8 -------- 3 files changed, 2 insertions(+), 26 deletions(-) diff --git a/lib/oga/xml/lexer.rb b/lib/oga/xml/lexer.rb index 23eb975..fee0f42 100644 --- a/lib/oga/xml/lexer.rb +++ b/lib/oga/xml/lexer.rb @@ -112,19 +112,8 @@ module Oga @data = data @html = options[:html] @strict = options[:strict] || false - - reset - end - - # Resets the internal state of the lexer. Typically you don't need to - # call this method yourself as its called by #lex after lexing a given - # String. - def reset @line = 1 @elements = [] - - @data.rewind if @data.respond_to?(:rewind) - reset_native end @@ -149,9 +138,6 @@ module Oga # Gathers all the tokens for the input and returns them as an Array. # - # This method resets the internal state of the lexer after consuming the - # input. - # # @see #advance # @return [Array] def lex @@ -161,7 +147,7 @@ module Oga tokens << [type, value, line] end - reset + reset_native tokens end @@ -178,8 +164,6 @@ module Oga # This method stores the supplied block in `@block` and resets it after # the lexer loop has finished. # - # This method does *not* reset the internal state of the lexer. - # # @yieldparam [Symbol] type # @yieldparam [String] value # @yieldparam [Fixnum] line diff --git a/lib/oga/xml/parser.rll b/lib/oga/xml/parser.rll index 506fac1..192e86a 100644 --- a/lib/oga/xml/parser.rll +++ b/lib/oga/xml/parser.rll @@ -245,7 +245,7 @@ string_body def reset @line = 1 - @lexer.reset + @lexer.reset_native end # Yields the next token from the lexer. diff --git a/spec/oga/xml/lexer/io_spec.rb b/spec/oga/xml/lexer/io_spec.rb index e7e0c3c..a32b7d6 100644 --- a/spec/oga/xml/lexer/io_spec.rb +++ b/spec/oga/xml/lexer/io_spec.rb @@ -17,14 +17,6 @@ describe Oga::XML::Lexer do ] end - it 'rewinds input when resetting the lexer' do - io = StringIO.new("

\nHello

") - lexer = described_class.new(io) - - lexer.lex.empty?.should == false - lexer.lex.empty?.should == false - end - it 'lexes an attribute value starting with a newline' do io = StringIO.new("") lexer = described_class.new(io)