sexp_processor 4.12.1 → 4.17.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -34,7 +34,7 @@ require "sexp"
34
34
  class SexpProcessor
35
35
 
36
36
  # duh
37
- VERSION = "4.12.1"
37
+ VERSION = "4.17.1"
38
38
 
39
39
  ##
40
40
  # Automatically shifts off the Sexp type before handing the
data/lib/strict_sexp.rb CHANGED
@@ -36,6 +36,7 @@
36
36
  # 4 = sexp << => no
37
37
 
38
38
  class Sexp
39
+ # alias :_concat :concat in sexp.rb so we have access to the original
39
40
  alias :safe_idx :[]
40
41
  alias :safe_asgn :[]=
41
42
  alias :sexp_type= :sexp_type=
@@ -43,9 +44,10 @@ class Sexp
43
44
  alias :shift :shift
44
45
 
45
46
  def self.nuke_method name, level
47
+ return unless __strict >= level
46
48
  define_method name do |*args|
47
49
  raise "no mutation allowed on sexps: %s.%s %s" % [self, name, args]
48
- end if __strict >= level
50
+ end
49
51
  end
50
52
 
51
53
  def self.__strict
@@ -81,13 +83,14 @@ class Sexp
81
83
  self.safe_asgn i, v
82
84
  end
83
85
 
84
- def first
85
- raise "use sexp_type"
86
+ def first(n = nil)
87
+ raise "use sexp_type" unless n
88
+ super
86
89
  end
87
90
 
88
91
  nuke_method :collect!, 4
89
92
  nuke_method :compact!, 4
90
- # nuke_method :concat, 4 # HACK: using self.class.new.concat(...) for speed
93
+ nuke_method :concat, 4 # HACK: using self.class.new.concat(...) for speed
91
94
  nuke_method :flatten!, 4
92
95
  nuke_method :map!, 4
93
96
  nuke_method :pop, 4
@@ -111,7 +114,7 @@ class Sexp
111
114
  end
112
115
 
113
116
  def sexp_body from = 1
114
- self.new.concat(safe_idx(from..-1) || [])
117
+ self.new._concat(safe_idx(from..-1) || [])
115
118
  end
116
119
 
117
120
  def sexp_type= v
@@ -123,4 +126,24 @@ class Sexp
123
126
  end
124
127
  end unless Sexp.new.respond_to? :safe_asgn if ENV["STRICT_SEXP"]
125
128
 
129
+ if ENV["SP_DEBUG"] && !ENV["STRICT_SEXP"] then
130
+ class Sexp
131
+ mutators = %i[
132
+ []= clear collect! compact! concat delete delete_at
133
+ delete_if drop drop_while fill flatten! replace insert
134
+ keep_if map! pop push reject! reverse! rotate! select!
135
+ shift shuffle! slice! sort! sort_by! transpose uniq!
136
+ unshift
137
+ ]
138
+
139
+ mutators.each do |method|
140
+ define_method method do |*args|
141
+ warn "Sexp modified by %p at %s" % [__method__, caller.first] if
142
+ ENV["VERBOSE"] or (defined?(@hash) and @hash)
143
+ super(*args)
144
+ end
145
+ end
146
+ end
147
+ end
148
+
126
149
  # :startdoc: