Sha256: ec2d71407f3cb409ac84d1cf42c6f82b5595d40873cf05f606bd5813f20d3e18

Contents?: true

Size: 850 Bytes

Versions: 2

Compression:

Stored size: 850 Bytes

Contents

module Opal
  class Sexp

    attr_accessor :line
    attr_accessor :end_line
    attr_reader :array

    def initialize(args)
      @array = args
    end

    def type
      @array[0]
    end

    def type=(type)
      @array[0] = type
    end

    def children
      @array[1..-1]
    end

    def method_missing(sym, *args, &block)
      @array.send sym, *args, &block
    end

    def <<(other)
      @array << other
      self
    end

    def push(*parts)
      @array.push(*parts)
      self
    end

    def to_ary
      @array
    end

    def dup
      Sexp.new(@array.dup)
    end

    def ==(other)
      if other.is_a? Sexp
        @array == other.array
      else
        @array == other
      end
    end

    alias eql? ==

    def inspect
      "(#{@array.map { |e| e.inspect }.join ' '})"
    end

    alias to_s inspect
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
opal-0.5.5 lib/opal/parser/sexp.rb
opal-0.5.4 lib/opal/parser/sexp.rb