Class: Elparser::SExpList

Inherits:
AbstractSExpCons show all
Defined in:
lib/elparser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractSExpCons

#cons?

Methods inherited from AbstractSExp

#==, #atom?, #cons?

Constructor Details

#initialize(list) ⇒ SExpList

Returns a new instance of SExpList.



143
144
145
# File 'lib/elparser.rb', line 143

def initialize(list)
  @list = list
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



142
143
144
# File 'lib/elparser.rb', line 142

def list
  @list
end

Instance Method Details

#alist?Boolean

Returns:

  • (Boolean)


168
169
170
# File 'lib/elparser.rb', line 168

def alist?
  @list.all? {|i| i.cons? }
end

#carObject



146
147
148
# File 'lib/elparser.rb', line 146

def car
  @list[0]
end

#cdrObject



149
150
151
152
153
154
155
# File 'lib/elparser.rb', line 149

def cdr
  if @list.size == 1
    SExpNil.new
  else
    SExpList.new @list.slice(1..-1)
  end
end

#list?Boolean

Returns:

  • (Boolean)


156
157
158
# File 'lib/elparser.rb', line 156

def list?
  true
end

#to_hObject

alist -> hash



172
173
174
175
176
177
178
# File 'lib/elparser.rb', line 172

def to_h
  ret = Hash.new
  @list.each do |i|
    ret[i.car.to_ruby] = i.cdr.to_ruby
  end
  ret
end

#to_rubyObject



165
166
167
# File 'lib/elparser.rb', line 165

def to_ruby
  @list.map {|i| i.to_ruby}
end

#to_sObject



159
160
161
# File 'lib/elparser.rb', line 159

def to_s
  "("+@list.map{|i| i.to_s }.join(" ")+")"
end

#visit(&block) ⇒ Object



162
163
164
# File 'lib/elparser.rb', line 162

def visit(&block)
  @list = @list.map(&block)
end