Class: XmlUtils::Tokenizer

Inherits:
Object
  • Object
show all
Defined in:
lib/xmlutils/tokenizer.rb

Constant Summary collapse

XML_NAME_PATTERN =
/[A-Za-z_][A-Za-z0-9_.:-]*/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Tokenizer

Returns a new instance of Tokenizer.



44
45
46
47
48
49
50
# File 'lib/xmlutils/tokenizer.rb', line 44

def initialize(source)
  @source = source.respond_to?(:read) ? source.read : source.to_s
  @pos = 0
  @line = 1
  @col = 1
  @tokens = []
end

Instance Method Details

#tokenizeObject



52
53
54
55
56
57
58
# File 'lib/xmlutils/tokenizer.rb', line 52

def tokenize
  until @pos >= @source.length
    @tokens << next_token
  end
  @tokens << Token.new(:eof)
  @tokens
end