class Sie::Parser
Constants
- BEGINNING_OF_ARRAY
- END_OF_ARRAY
- ENTRY
TODO: Could this format knowledge be shared with
Tokenizer
? It's slightly different there.- ENTRY_TYPES
Public Class Methods
new(options = {})
click to toggle source
# File lib/sie/parser.rb, line 14 def initialize(options = {}) @options = options end
Public Instance Methods
parse(io)
click to toggle source
# File lib/sie/parser.rb, line 18 def parse(io) stack = [] sie_file = SieFile.new current = sie_file io.each_line do |line| line = line.chomp case line when BEGINNING_OF_ARRAY stack << current current = current.entries.last when END_OF_ARRAY current = stack.pop when ENTRY current.entries << parse_line(line) end end sie_file end
Private Instance Methods
lenient()
click to toggle source
# File lib/sie/parser.rb, line 48 def lenient options.fetch(:lenient, false) end
parse_line(line)
click to toggle source
# File lib/sie/parser.rb, line 42 def parse_line(line) LineParser.new(line, lenient: lenient).parse rescue BuildEntry::InvalidEntryError => ex raise ex, "#{ex.message}. Pass 'lenient: true' to Parser.new to avoid this exception." end