Module: AtCoderFriends::Parser::InputFormatMatcherConstants
- Includes:
- InputFormatConstants
- Included in:
- InputFormat
- Defined in:
- lib/at_coder_friends/parser/input_format.rb
Overview
matcher constants
Constant Summary collapse
- MATRIX_MATCHER =
InputFormatMatcher.new( container: :matrix, pat: / \A (?<v>#{RE_ITEM})#{RE_IX_00} (\s+(\.+|\k<v>#{RE_IX}))* \s+\k<v>#{RE_SZ} \z /x, gen_names: ->(m) { [m[:v]] }, gen_pat2: lambda { |(v)| / \A #{v}#{RE_IX} (\s+(\.+|#{v}#{RE_IX}))* \s+(\.+|#{v}#{RE_SZ}) \z /x } )
- MATRIX_CHAR_MATCHER =
InputFormatMatcher.new( container: :matrix, item: :char, pat: / \A (?<v>#{RE_ITEM})#{RE_IX_00} (\s*\.+\s*|\k<v>#{RE_IX})* \k<v>#{RE_SZ} \z /x, gen_names: ->(m) { [m[:v]] }, gen_pat2: lambda { |(v)| / \A (#{v}#{RE_IX})+ (\s*\.+\s*|#{v}#{RE_IX})* (\s*\.+\s*|#{v}#{RE_SZ}) \z /x } )
- HARRAY_MATCHER =
InputFormatMatcher.new( container: :harray, pat: / \A (?<v>#{RE_ITEM})#{RE_IX_0} (\s+(\.+|\k<v>#{RE_IX}))* \s+\k<v>#{RE_SZ} \z /x, gen_names: ->(m) { [m[:v]] } )
- HARRAY_CHAR_MATCHER =
InputFormatMatcher.new( container: :harray, item: :char, pat: / \A (?<v>#{RE_ITEM})#{RE_IX_0} (\s*\.+\s*|\k<v>#{RE_IX})* \k<v>#{RE_SZ} \z /x, gen_names: ->(m) { [m[:v]] } )
- VARRAY_MATRIX_MATCHER =
InputFormatMatcher.new( container: :varray_matrix, pat: / \A (?<vs>#{RE_ITEM}#{RE_SZ2_0} (\s+#{RE_ITEM}#{RE_SZ2_REF})*) \s+(?<m>#{RE_ITEM})#{RE_IX_00} (\s+(\.+|\k<m>#{RE_IX}))* \s+\k<m>#{RE_SZ} \z /x, gen_names: ->(m) { [*m[:vs].split.map { |w| w.scan(RE_ITEM)[0] }, m[:m]] }, gen_pat2: lambda { |vs| ws = vs[0..-2].map { |v| v + RE_IX.source }.join('\s+') m = vs[-1] / \A #{ws} \s+#{m}#{RE_IX} (\s+(\.+|#{m}#{RE_IX}))* \s+(\.+|#{m}#{RE_SZ}) \z /x } )
- VARRAY_MATRIX_CHAR_MATCHER =
InputFormatMatcher.new( container: :varray_matrix, item: :char, pat: / \A (?<vs>#{RE_ITEM}#{RE_SZ2_0} (\s+#{RE_ITEM}#{RE_SZ2_REF})*) \s+(?<m>#{RE_ITEM})#{RE_IX_00} (\s*\.+\s*|\k<m>#{RE_IX})* \k<m>#{RE_SZ} \z /x, gen_names: ->(m) { [*m[:vs].split.map { |w| w.scan(RE_ITEM)[0] }, m[:m]] }, gen_pat2: lambda { |vs| ws = vs[0..-2].map { |v| v + RE_IX.source }.join('\s+') m = vs[-1] / \A #{ws} \s+#{m}#{RE_IX} (\s*\.+\s*|#{m}#{RE_IX})* (\s*\.+\s*|#{m}#{RE_SZ}) \z /x } )
- MATRIX_VARRAY_MATCHER =
InputFormatMatcher.new( container: :matrix_varray, pat: / \A (?<m>#{RE_ITEM})#{RE_IX_00} (\s+(\.+|\k<m>#{RE_IX}))* \s+\k<m>#{RE_SZ} \s+(?<vs>#{RE_ITEM}#{RE_SZ2_0} (\s+#{RE_ITEM}#{RE_SZ2_REF})*) \z /x, gen_names: ->(m) { [m[:m], *m[:vs].split.map { |w| w.scan(RE_ITEM)[0] }] }, gen_pat2: lambda { |vs| m = vs[0] ws = vs[1..].map { |v| v + RE_IX.source }.join('\s+') / \A #{m}#{RE_IX} (\s+(\.+|#{m}#{RE_IX}))* \s+(\.+|#{m}#{RE_SZ}) \s+#{ws} \z /x } )
- VMATRIX_MATCHER =
InputFormatMatcher.new( container: :vmatrix, pat: / \A #{RE_ITEM}#{RE_SZ_00} (\s+#{RE_ITEM}#{RE_SZ_REF})* \z /x, gen_names: ->(m) { m[0].split.map { |w| w.scan(RE_ITEM)[0] } }, gen_pat2: lambda { |vs| ws = [ vs[0] + RE_SZ.source, *vs[1..]&.map { |v| v + RE_IX.source } ].join('\s+') /\A#{ws}\z/ } )
- HMATRIX_MATCHER =
InputFormatMatcher.new( container: :hmatrix, pat: / \A #{RE_ITEM}#{RE_IX_00} (\s+(\.+|#{RE_ITEM}#{RE_IX_99}))* \s+#{RE_ITEM}#{RE_SZ_99} \z /x, gen_names: ->(m) { m[0].split.map { |w| w.scan(RE_ITEM)[0] }.uniq }, gen_pat2: lambda { |vs| ws1 = vs.map { |v| v + RE_IX.source }.join('\s+') ws2 = [ vs[0] + RE_SZ.source, *vs[1..]&.map { |v| v + RE_IX.source } ].join('\s+') / \A #{ws1} (\s+(\.+|#{ws1}))* \s+(\.+|#{ws2}) \z /x } )
- VARRAY_MATCHER =
InputFormatMatcher.new( container: :varray, pat: / \A #{RE_ITEM}#{RE_SZ_0} (\s+#{RE_ITEM}#{RE_SZ_REF})* \z /x, gen_names: ->(m) { m[0].split.map { |w| w.scan(RE_ITEM)[0] } }, gen_pat2: lambda { |vs| ws = [ vs[0] + RE_SZ.source, *vs[1..]&.map { |v| v + RE_IX.source } ].join('\s+') /\A#{ws}\z/ } )
- SINGLE_MATCHER =
InputFormatMatcher.new( container: :single, pat: /\A(.*\s)?#{RE_SINGLE}(\s.*)?\z/, gen_names: ->(m) { m[0].split.grep(/\A#{RE_SINGLE}\z/) } )
- MATCHERS =
[ MATRIX_MATCHER, MATRIX_CHAR_MATCHER, HARRAY_MATCHER, HARRAY_CHAR_MATCHER, VARRAY_MATRIX_MATCHER, VARRAY_MATRIX_CHAR_MATCHER, MATRIX_VARRAY_MATCHER, VMATRIX_MATCHER, HMATRIX_MATCHER, VARRAY_MATCHER, SINGLE_MATCHER ].freeze
Constants included from InputFormatConstants
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