module AtCoderFriends::Parser::InputFormat

parses input data format and generates input definitons

Public Instance Methods

find_fmt(pbm) click to toggle source
# File lib/at_coder_friends/parser/input_format.rb, line 451
def find_fmt(pbm)
  str = nil
  SECTIONS.any? do |key|
    (str = pbm.sections[key]&.code_block_html) && !str.empty?
  end
  str
end
parse(str) click to toggle source
# File lib/at_coder_friends/parser/input_format.rb, line 459
def parse(str)
  lines = normalize_fmt(str)
  parse_fmt(lines)
end
parse_fmt(lines) click to toggle source
# File lib/at_coder_friends/parser/input_format.rb, line 464
def parse_fmt(lines)
  matcher = nil
  (lines + ['']).each_with_object([]) do |line, ret|
    if matcher
      next if matcher.match2(line)

      ret << matcher.to_inpdef
    end
    if (matcher = MATCHERS.find { |m| m.match(line) })
    elsif !line.empty?
      puts "unknown format: #{line}"
      ret << unknown_fmt(line)
    end
  end
end
process(pbm) click to toggle source
# File lib/at_coder_friends/parser/input_format.rb, line 444
def process(pbm)
  return unless (str = find_fmt(pbm))

  inpdefs = parse(str)
  pbm.formats_src = inpdefs
end
unknown_fmt(line) click to toggle source
# File lib/at_coder_friends/parser/input_format.rb, line 480
def unknown_fmt(line)
  Problem::InputFormat.new(container: :unknown, item: line)
end