Sha256: b2774b44de341833ebc08dee6550b5e0604cec749e57ccb4764041256f02c4d3

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'rubygems'
require 'sexp_processor'

module SexpPath
  
  # SexpPath Matchers are used to build SexpPath queries.
  #
  # See also: SexpQueryBuilder
  module Matcher  
  end
end

sexp_path_root = File.dirname(__FILE__)+'/sexp_path/'
%w[
  traverse 
  sexp_query_builder
  ruby_query_builder
  sexp_result
  sexp_collection
    
  matcher/base
  matcher/any
  matcher/all
  matcher/not
  matcher/child
  matcher/block
  matcher/atom
  matcher/pattern
  matcher/type
  matcher/wild
  matcher/remaining
  matcher/include
  matcher/sibling
  
].each do |path|
  require sexp_path_root+path
end

# Pattern building helper, see SexpQueryBuilder
def Q?(&block)
  SexpPath::SexpQueryBuilder.do(&block)
end

# Ruby specific builder
def R?(&block)
  SexpPath::RubyQueryBuilder.do(&block)
end

# SexpPath extends Sexp with Traverse.
# This adds support for searching S-Expressions
class Sexp
  include SexpPath::Traverse
  
  # Extends Sexp to allow any Sexp to be used as a SexpPath matcher
  def satisfy?(o, data={})
    return false unless o.is_a? Sexp
    return false unless (length == o.length || last.is_a?(SexpPath::Matcher::Remaining) )
    each_with_index{|c,i| return false unless c.is_a?(Sexp) ? c.satisfy?( o[i], data ) : c == o[i] }

    capture_match(o, data)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sexp_path-0.5.0 lib/sexp_path.rb