Class: Sexp::Type

Inherits:
Matcher show all
Defined in:
lib/sexp_matcher.rb

Overview

Matches anything having the same sexp_type, which is the first value in a Sexp.

examples:

s(:a, :b) / s{ t(:a) }        #=> [s(:a, :b)]
s(:a, :b) / s{ t(:b) }        #=> []
s(:a, s(:b, :c)) / s{ t(:b) } #=> [s(:b, :c)]

Constant Summary

Constants inherited from Sexp

UNASSIGNED

Instance Attribute Summary collapse

Attributes inherited from Sexp

#comments, #file, #line, #line_max

Instance Method Summary collapse

Methods inherited from Matcher

#&, #-@, #/, #=~, #>>, #greedy?, match_subs=, match_subs?, parse, #|

Methods inherited from Sexp

#/, #=~, _, ___, all, any, #array_type?, atom, child, #compact, #deep_each, #depth, #each_of_type, #each_sexp, #eql?, #find_and_replace_all, #find_node, #find_nodes, from_array, #gsub, #hash, include, k, m, #map, #mass, #method_missing, #new, not?, q, #replace_sexp, #respond_to?, s, #search_each, #sexp_body, #sexp_body=, #sexp_type=, #shift, #structure, #sub, t, #to_a, #value

Constructor Details

#initialize(type) ⇒ Type

Creates a Matcher which will match any Sexp who’s type is type, where a type is the first element in the Sexp.



904
905
906
# File 'lib/sexp_matcher.rb', line 904

def initialize type
  @sexp_type = type
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Sexp

Instance Attribute Details

#sexp_typeObject (readonly)

Returns the value of attribute sexp_type.



898
899
900
# File 'lib/sexp_matcher.rb', line 898

def sexp_type
  @sexp_type
end

Instance Method Details

#==(o) ⇒ Object

:nodoc:



908
909
910
# File 'lib/sexp_matcher.rb', line 908

def == o # :nodoc:
  super && self.sexp_type == o.sexp_type
end

#inspectObject

:nodoc:



919
920
921
# File 'lib/sexp_matcher.rb', line 919

def inspect # :nodoc:
  "t(%p)" % sexp_type
end

#pretty_print(q) ⇒ Object

:nodoc:



923
924
925
926
927
# File 'lib/sexp_matcher.rb', line 923

def pretty_print q # :nodoc:
  q.group 1, "t(", ")" do
    q.pp sexp_type
  end
end

#satisfy?(o) ⇒ Boolean

Satisfied if the sexp_type of o is type.

Returns:

  • (Boolean)


915
916
917
# File 'lib/sexp_matcher.rb', line 915

def satisfy? o
  o.kind_of?(Sexp) && o.sexp_type == sexp_type
end