Class: TypedSexp
Instance Method Summary collapse
- #==(obj) ⇒ Object
- #_set_sexp_type(o) ⇒ Object
-
#initialize(*args) ⇒ TypedSexp
constructor
A new instance of TypedSexp.
- #inspect ⇒ Object
- #pretty_print(q) ⇒ Object
- #sexp_type ⇒ Object
- #sexp_type=(o) ⇒ Object
- #sexp_types ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
Instance Method Details
#==(obj) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/typed_sexp.rb', line 10 def ==(obj) case obj when TypedSexp super && sexp_type == obj.sexp_type else false end end |
#_set_sexp_type(o) ⇒ Object
19 20 21 |
# File 'lib/typed_sexp.rb', line 19 def _set_sexp_type(o) @sexp_type = o end |
#inspect ⇒ Object
29 30 31 32 33 |
# File 'lib/typed_sexp.rb', line 29 def inspect sexp_str = self.map {|x|x.inspect}.join(', ') sexp_type_str = (sexp_str.empty? ? "" : ", ") + "#{array_type? ? sexp_types.inspect : sexp_type}" unless sexp_type.nil? return "t(#{sexp_str}#{sexp_type_str})" end |
#pretty_print(q) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/typed_sexp.rb', line 35 def pretty_print(q) q.group(1, 't(', ')') do q.seplist(self) {|v| q.pp v } unless @sexp_type.nil? then q.text ", " unless self.empty? q.pp @sexp_type end end end |
#sexp_type ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/typed_sexp.rb', line 45 def sexp_type unless array_type? then @sexp_type else types = self.sexp_types.flatten.uniq if types.size > 1 then Type.hetero else Type.homo end end end |
#sexp_type=(o) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/typed_sexp.rb', line 59 def sexp_type=(o) raise "You shouldn't call this on an #{first}" if array_type? raise "You shouldn't call this a second time, ever" unless @sexp_type.nil? or @sexp_type == Type.unknown _set_sexp_type(o) end |
#sexp_types ⇒ Object
66 67 68 69 |
# File 'lib/typed_sexp.rb', line 66 def sexp_types raise "You shouldn't call this if not an #{@@array_types.join(' or ')}, was #{first} (#{self.inspect})" unless array_type? self.grep(Sexp).map { |x| x.sexp_type } end |
#to_a ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/typed_sexp.rb', line 71 def to_a result = super if defined?(@sexp_type) and not @sexp_type.nil? then result += [ @sexp_type ] end result end |
#to_s ⇒ Object
79 80 81 |
# File 'lib/typed_sexp.rb', line 79 def to_s inspect end |