module LINE

Top-level LINE module.

Constants

BEL_PARSERS

Public Class Methods

map_comment_line(string) click to toggle source
# File lib/bel_parser/parsers/line_parser.rb, line 76
def self.map_comment_line(string)
  if LINE.match_comment_line(string)
    nil
  else
    string
  end
end
map_empty_line(string) click to toggle source
# File lib/bel_parser/parsers/line_parser.rb, line 68
def self.map_empty_line(string)
  if LINE.match_empty_line(string)
    nil
  else
    string
  end
end
match_comment_line(string) click to toggle source
# File lib/bel_parser/parsers/line_parser.rb, line 88
def self.match_comment_line(string)
  string =~ /^\s*#/
end
match_empty_line(string) click to toggle source
# File lib/bel_parser/parsers/line_parser.rb, line 84
def self.match_empty_line(string)
  string =~ /^\s*$/
end
normalize_line_terminators(string) click to toggle source
# File lib/bel_parser/parsers/line_parser.rb, line 63
def self.normalize_line_terminators(string)
  return nil unless string
  string.strip + "\n"
end
parse(io) click to toggle source

rubocop:disable MethodLength, AbcSize

# File lib/bel_parser/parsers/line_parser.rb, line 32
def self.parse(io)
  # single line transform
  line_enum = io
              .each_line
              .lazy
              .map { |line| LINE.normalize_line_terminators(line) }

  # multi-line transform
  loop do
    begin
      line = line_enum.next

      while line.end_with?("\\\n")
        line.chomp!("\\\n")
        line += line_enum.next
      end

      BEL_PARSERS.each do |parser|
        # rubocop:disable BlockDelimiters
        parser.parse(line) { |obj|
          puts "parser: #{parser.inspect},"\
               "line: #{line.strip},"\
               "object: \n#{obj.inspect}"
        }
      end
    rescue StopIteration
      return
    end
  end
end