Module: AtCoderFriends::Parser::InputFormat
Overview
parses input data format and generates input definitons
Constant Summary
AtCoderFriends::Parser::InputFormatConstants::ADD_TAG, AtCoderFriends::Parser::InputFormatConstants::DELIMS, AtCoderFriends::Parser::InputFormatConstants::DIMENSION_TBL, AtCoderFriends::Parser::InputFormatConstants::RE_0, AtCoderFriends::Parser::InputFormatConstants::RE_00, AtCoderFriends::Parser::InputFormatConstants::RE_99, AtCoderFriends::Parser::InputFormatConstants::RE_BLOCK, AtCoderFriends::Parser::InputFormatConstants::RE_ITEM, AtCoderFriends::Parser::InputFormatConstants::RE_IX, AtCoderFriends::Parser::InputFormatConstants::RE_IX_0, AtCoderFriends::Parser::InputFormatConstants::RE_IX_00, AtCoderFriends::Parser::InputFormatConstants::RE_IX_99, AtCoderFriends::Parser::InputFormatConstants::RE_SINGLE, AtCoderFriends::Parser::InputFormatConstants::RE_SZ, AtCoderFriends::Parser::InputFormatConstants::RE_SZ2_0, AtCoderFriends::Parser::InputFormatConstants::RE_SZ2_REF, AtCoderFriends::Parser::InputFormatConstants::RE_SZ_0, AtCoderFriends::Parser::InputFormatConstants::RE_SZ_00, AtCoderFriends::Parser::InputFormatConstants::RE_SZ_99, AtCoderFriends::Parser::InputFormatConstants::RE_SZ_REF, AtCoderFriends::Parser::InputFormatConstants::SECTIONS, AtCoderFriends::Parser::InputFormatConstants::TO_SUFFIX, AtCoderFriends::Parser::InputFormatConstants::TO_SUFFIX_STR
AtCoderFriends::Parser::InputFormatMatcherConstants::HARRAY_CHAR_MATCHER, AtCoderFriends::Parser::InputFormatMatcherConstants::HARRAY_MATCHER, AtCoderFriends::Parser::InputFormatMatcherConstants::HMATRIX_MATCHER, AtCoderFriends::Parser::InputFormatMatcherConstants::MATCHERS, AtCoderFriends::Parser::InputFormatMatcherConstants::MATRIX_CHAR_MATCHER, AtCoderFriends::Parser::InputFormatMatcherConstants::MATRIX_MATCHER, AtCoderFriends::Parser::InputFormatMatcherConstants::MATRIX_VARRAY_MATCHER, AtCoderFriends::Parser::InputFormatMatcherConstants::SINGLE_MATCHER, AtCoderFriends::Parser::InputFormatMatcherConstants::VARRAY_MATCHER, AtCoderFriends::Parser::InputFormatMatcherConstants::VARRAY_MATRIX_CHAR_MATCHER, AtCoderFriends::Parser::InputFormatMatcherConstants::VARRAY_MATRIX_MATCHER, AtCoderFriends::Parser::InputFormatMatcherConstants::VMATRIX_MATCHER
Class Method Summary
collapse
extract_delim, normalize_fmt, normalize_name, normalize_names, normalize_size, size_array, split_size
Class Method Details
.find_fmt(pbm) ⇒ Object
455
456
457
458
459
460
461
|
# File 'lib/at_coder_friends/parser/input_format.rb', line 455
def find_fmt(pbm)
str = nil
SECTIONS.any? do |key|
(str = pbm.sections[key]&.code_block_html) && !str.empty?
end
str
end
|
.parse(str) ⇒ Object
463
464
465
466
|
# File 'lib/at_coder_friends/parser/input_format.rb', line 463
def parse(str)
lines = normalize_fmt(str)
parse_fmt(lines)
end
|
.parse_fmt(lines) ⇒ Object
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
|
# File 'lib/at_coder_friends/parser/input_format.rb', line 468
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
matcher = MATCHERS.find { |m| m.match(line) }
if !line.empty? && matcher.nil?
puts "unknown format: #{line}"
ret << unknown_fmt(line)
end
end
end
|
.process(pbm) ⇒ Object
448
449
450
451
452
453
|
# File 'lib/at_coder_friends/parser/input_format.rb', line 448
def process(pbm)
return unless (str = find_fmt(pbm))
inpdefs = parse(str)
pbm.formats_src = inpdefs
end
|
.unknown_fmt(line) ⇒ Object
484
485
486
|
# File 'lib/at_coder_friends/parser/input_format.rb', line 484
def unknown_fmt(line)
Problem::InputFormat.new(container: :unknown, item: line)
end
|