class Hocon::Impl::Tokenizer::TokenIterator::WhitespaceSaver
Public Class Methods
Source
# File lib/hocon/impl/tokenizer.rb, line 55 def initialize @whitespace = StringIO.new @last_token_was_simple_value = false end
Public Instance Methods
Source
# File lib/hocon/impl/tokenizer.rb, line 64 def check(t, base_origin, line_number) if TokenIterator.simple_value?(t) next_is_a_simple_value(base_origin, line_number) else next_is_not_a_simple_value(base_origin, line_number) end end
Private Instance Methods
Source
# File lib/hocon/impl/tokenizer.rb, line 90 def create_whitespace_token_from_saver(base_origin, line_number) return nil unless @whitespace.length > 0 if (@last_token_was_simple_value) t = Tokens.new_unquoted_text( Hocon::Impl::Tokenizer::TokenIterator.line_origin(base_origin, line_number), String.new(@whitespace.string) ) else t = Tokens.new_ignored_whitespace( Hocon::Impl::Tokenizer::TokenIterator.line_origin(base_origin, line_number), String.new(@whitespace.string) ) end @whitespace.string = "" t end
Source
# File lib/hocon/impl/tokenizer.rb, line 84 def next_is_a_simple_value(base_origin, line_number) t = create_whitespace_token_from_saver(base_origin, line_number) @last_token_was_simple_value = true unless @last_token_was_simple_value t end
called if the next token IS a simple value, so creates a whitespace token if the previous token also was.
Source
# File lib/hocon/impl/tokenizer.rb, line 76 def next_is_not_a_simple_value(base_origin, line_number) @last_token_was_simple_value = false create_whitespace_token_from_saver(base_origin, line_number) end
called if the next token is not a simple value; discards any whitespace we were saving between simple values.