Sha256: d4cbb10b0d7ac3d8cadb46703c988e9ad7dcb06c853954d76255fd640d4ed10f
Contents?: true
Size: 1.94 KB
Versions: 1
Compression:
Stored size: 1.94 KB
Contents
module Pickle class Parser module Matchers def match_ordinal '(?:\d+(?:st|nd|rd|th))' end def match_index "(?:first|last|#{match_ordinal})" end def match_prefix '(?:(?:1|a|an|another|the|that) )' end def match_quoted '(?:[^\\"]|\\.)*' end def match_label "(?::? \"#{match_quoted}\")" end def match_field "(?:\\w+: \"#{match_quoted}\")" end def match_fields "(?:#{match_field}, )*#{match_field}" end def match_mapping config.mappings.any? ? "(?:#{config.mappings.map(&:search).join('|')})" : "" end def match_factory "(?:#{config.factory_names.map{|n| n.gsub('_','[_ ]')}.join('|')})" end def match_plural_factory "(?:#{config.factory_names.map{|n| n.pluralize.gsub('_','[_ ]')}.join('|')})" end def match_indexed_model "(?:(?:#{match_index} )?#{match_factory})" end def match_labeled_model "(?:#{match_factory}#{match_label})" end def match_model "(?:#{match_mapping}|#{match_prefix}?(?:#{match_indexed_model}|#{match_labeled_model}))" end # create capture analogues of match methods instance_methods.select{|m| m =~ /^match_/}.each do |method| eval <<-end_eval def #{method.sub('match_', 'capture_')} # def capture_field "(" + #{method} + ")" # "(" + match_field + ")" end # end end_eval end # special capture methods def capture_number_in_ordinal '(?:(\d+)(?:st|nd|rd|th))' end def capture_name_in_label "(?::? \"(#{match_quoted})\")" end def capture_key_and_value_in_field "(?:(\\w+): \"(#{match_quoted})\")" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ianwhite-pickle-0.1.4 | lib/pickle/parser/matchers.rb |