rubymotionlisp 1.0.13 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rubylisp/atom.rb +4 -0
- data/lib/rubylisp/cons_cell.rb +195 -0
- data/lib/rubylisp/parser.rb +56 -46
- data/lib/rubylisp/tokenizer.rb +29 -28
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 5de6ce4210bcf029285a399dcdcbfcbfb9e694b0
         | 
| 4 | 
            +
              data.tar.gz: aa4cf373497533635555b76d401d197dad8ab060
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: ad066de387e6c61c70e5b27e3022f4690a6673aba8bc42f8323618d2d6b6f7f423fdc8b244973bc06d8528a29e6670ee8544c2b3f6a72f924f39213f081272c8
         | 
| 7 | 
            +
              data.tar.gz: d7b568d0fdbc79539e9dbc91c380a4defd3e5bef226a2433728519c4f1702d77f5d7ead5b6c12d78796717b1f5fae95067cd1d51259c0ac6ebcc00950e552d3d
         | 
    
        data/lib/rubylisp/atom.rb
    CHANGED
    
    
    
        data/lib/rubylisp/cons_cell.rb
    CHANGED
    
    | @@ -4,6 +4,10 @@ module Lisp | |
| 4 4 | 
             
                include Enumerable
         | 
| 5 5 | 
             
                attr_reader :car, :cdr
         | 
| 6 6 |  | 
| 7 | 
            +
                def set_location(type, package, file, start, length)
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                
         | 
| 7 11 | 
             
                def self.cons(a=nil, b=nil)
         | 
| 8 12 | 
             
                  b = nil if b.pair? && b.empty?
         | 
| 9 13 | 
             
                  ConsCell.new(a, b)
         | 
| @@ -17,6 +21,197 @@ module Lisp | |
| 17 21 | 
             
                def value
         | 
| 18 22 | 
             
                  self
         | 
| 19 23 | 
             
                end
         | 
| 24 | 
            +
                
         | 
| 25 | 
            +
                def set_car!(d)
         | 
| 26 | 
            +
                  @car = d
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                def lisp_object?
         | 
| 30 | 
            +
                  true
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
                
         | 
| 33 | 
            +
                def set_cdr!(d)
         | 
| 34 | 
            +
                  @cdr = d
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
             | 
| 38 | 
            +
                def set_nth!(n, d)
         | 
| 39 | 
            +
                  return nil if empty?
         | 
| 40 | 
            +
                  c = self
         | 
| 41 | 
            +
                  n.times {|i| c = c.cdr}
         | 
| 42 | 
            +
                  c.set_car!(d)
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                
         | 
| 46 | 
            +
                def empty?
         | 
| 47 | 
            +
                  @car.nil? && @cdr.nil?
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                def string?
         | 
| 51 | 
            +
                  false
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                def character?
         | 
| 55 | 
            +
                  false
         | 
| 56 | 
            +
                end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                def number?
         | 
| 59 | 
            +
                  false
         | 
| 60 | 
            +
                end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                def positive?
         | 
| 63 | 
            +
                  false
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                def zero?
         | 
| 67 | 
            +
                  false
         | 
| 68 | 
            +
                end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                def negative?
         | 
| 71 | 
            +
                  false
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                def symbol?
         | 
| 75 | 
            +
                  false
         | 
| 76 | 
            +
                end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                def primitive?
         | 
| 79 | 
            +
                  false
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                def special?
         | 
| 83 | 
            +
                  false
         | 
| 84 | 
            +
                end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                def function?
         | 
| 87 | 
            +
                  false
         | 
| 88 | 
            +
                end
         | 
| 89 | 
            +
             | 
| 90 | 
            +
                def macro?
         | 
| 91 | 
            +
                  false
         | 
| 92 | 
            +
                end
         | 
| 93 | 
            +
             | 
| 94 | 
            +
                def pair?
         | 
| 95 | 
            +
                  true
         | 
| 96 | 
            +
                end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                def list?
         | 
| 99 | 
            +
                  true
         | 
| 100 | 
            +
                end
         | 
| 101 | 
            +
             | 
| 102 | 
            +
                def frame?
         | 
| 103 | 
            +
                  false
         | 
| 104 | 
            +
                end
         | 
| 105 | 
            +
             | 
| 106 | 
            +
                def vector?
         | 
| 107 | 
            +
                  false
         | 
| 108 | 
            +
                end
         | 
| 109 | 
            +
             | 
| 110 | 
            +
                def eq?(other)
         | 
| 111 | 
            +
                  return true if empty? && (other.nil? || (other.pair? && other.empty?))
         | 
| 112 | 
            +
                  other.pair? && self == other
         | 
| 113 | 
            +
                end
         | 
| 114 | 
            +
             | 
| 115 | 
            +
                def eqv?(other)
         | 
| 116 | 
            +
                  return true if empty? && (other.nil? || (other.pair? && other.empty?))
         | 
| 117 | 
            +
                  other.pair? && self == other
         | 
| 118 | 
            +
                end
         | 
| 119 | 
            +
                
         | 
| 120 | 
            +
                def equal?(other)
         | 
| 121 | 
            +
                  return true if empty? && (other.nil? || (other.pair? && other.empty?))
         | 
| 122 | 
            +
                  return false unless other.pair?
         | 
| 123 | 
            +
                  @car.equal?(other.car) && @cdr.equal?(other.cdr)
         | 
| 124 | 
            +
                end
         | 
| 125 | 
            +
                
         | 
| 126 | 
            +
                def type
         | 
| 127 | 
            +
                  :pair
         | 
| 128 | 
            +
                end
         | 
| 129 | 
            +
             | 
| 130 | 
            +
                def to_s_helper
         | 
| 131 | 
            +
                  return "#{@car.to_s}" if @cdr.nil?
         | 
| 132 | 
            +
                  return "#{@car.to_s} . #{@cdr.to_s}" unless @cdr.pair?
         | 
| 133 | 
            +
                  "#{@car.to_s} #{@cdr.to_s_helper}"
         | 
| 134 | 
            +
                end
         | 
| 135 | 
            +
             | 
| 136 | 
            +
                def to_s
         | 
| 137 | 
            +
                  return "()" if self.empty?
         | 
| 138 | 
            +
                  return "'#{@cdr.car.to_s}" if @car.symbol? && @car.name == "quote"
         | 
| 139 | 
            +
                  return "{#{@cdr.to_s_helper}}" if @car.symbol? && @car.name == "make-frame"
         | 
| 140 | 
            +
                  return "#(#{@cdr.to_s_helper})" if @car.symbol? && @car.name == "make-vector"
         | 
| 141 | 
            +
                  return "(#{@car.to_s} . #{@cdr.to_s})" if !@cdr.nil? && !@cdr.pair?
         | 
| 142 | 
            +
                  return "(#{self.to_s_helper})"
         | 
| 143 | 
            +
                end
         | 
| 144 | 
            +
             | 
| 145 | 
            +
                def print_string_helper
         | 
| 146 | 
            +
                  @cdr.nil? ? "#{@car.print_string}" : "#{@car.print_string} #{@cdr.print_string_helper}"
         | 
| 147 | 
            +
                end
         | 
| 148 | 
            +
             | 
| 149 | 
            +
                def print_string
         | 
| 150 | 
            +
                  return "()" if self.empty?
         | 
| 151 | 
            +
                  return "'#{@cdr.car.print_string}" if @car.symbol? && @car.name == "quote"
         | 
| 152 | 
            +
                  return "{#{@cdr.print_string_helper}}" if @car.symbol? && @car.name == "make-frame"
         | 
| 153 | 
            +
                  return "#(#{@cdr.print_string_helper})" if @car.symbol? && @car.name == "make-vector"
         | 
| 154 | 
            +
                  return "(#{@car.print_string} . #{@cdr.print_string})" if !@cdr.nil? && !@cdr.pair?
         | 
| 155 | 
            +
                  return "(#{self.print_string_helper})"
         | 
| 156 | 
            +
                end
         | 
| 157 | 
            +
             | 
| 158 | 
            +
                def to_a
         | 
| 159 | 
            +
                  a = []
         | 
| 160 | 
            +
                  return a if empty?
         | 
| 161 | 
            +
                  c = self
         | 
| 162 | 
            +
                  until c.nil?
         | 
| 163 | 
            +
                    a << c.car
         | 
| 164 | 
            +
                    c = c.cdr
         | 
| 165 | 
            +
                  end
         | 
| 166 | 
            +
                  a
         | 
| 167 | 
            +
                end
         | 
| 168 | 
            +
             | 
| 169 | 
            +
                def each &block
         | 
| 170 | 
            +
                  return if empty?
         | 
| 171 | 
            +
                  c = self
         | 
| 172 | 
            +
                  if self.length > 0
         | 
| 173 | 
            +
                    until c.nil?
         | 
| 174 | 
            +
                      yield c.car 
         | 
| 175 | 
            +
                      c = c.cdr
         | 
| 176 | 
            +
                    end
         | 
| 177 | 
            +
                  end
         | 
| 178 | 
            +
                end
         | 
| 179 | 
            +
             | 
| 180 | 
            +
                def self.array_to_list(cells, tail=nil)
         | 
| 181 | 
            +
                  return cons() if cells.empty? && tail.nil?
         | 
| 182 | 
            +
                  head = ConsCell.new
         | 
| 183 | 
            +
                  last_cell = head
         | 
| 184 | 
            +
                  (0...cells.length).each do |i|
         | 
| 185 | 
            +
                    new_cell = self.cons(cells[i], nil)
         | 
| 186 | 
            +
                    last_cell.set_cdr!(new_cell)
         | 
| 187 | 
            +
                    last_cell = new_cell
         | 
| 188 | 
            +
                  end
         | 
| 189 | 
            +
                  last_cell.set_cdr!(tail)
         | 
| 190 | 
            +
                  head.cdr
         | 
| 191 | 
            +
                end
         | 
| 192 | 
            +
             | 
| 193 | 
            +
                def traverse(path)
         | 
| 194 | 
            +
                  next_cell = self
         | 
| 195 | 
            +
                  path.chars.each do |p|
         | 
| 196 | 
            +
                    return nil if next_cell.nil?  || !next_cell.pair?
         | 
| 197 | 
            +
                    next_cell = ((p == ?a) ? next_cell.car : next_cell.cdr)
         | 
| 198 | 
            +
                  end
         | 
| 199 | 
            +
                  next_cell
         | 
| 200 | 
            +
                end
         | 
| 201 | 
            +
             | 
| 202 | 
            +
                def method_missing(name, *args, &block)
         | 
| 203 | 
            +
                  if name[0] == ?c && name[-1] == ?r && (name[1..-2].chars.all? {|e| "ad".include?(e)})
         | 
| 204 | 
            +
                    self.traverse(name[1..-2].reverse)
         | 
| 205 | 
            +
                  else
         | 
| 206 | 
            +
                    super
         | 
| 207 | 
            +
                  end
         | 
| 208 | 
            +
                end
         | 
| 209 | 
            +
             | 
| 210 | 
            +
                def nth(n)
         | 
| 211 | 
            +
                  c = self
         | 
| 212 | 
            +
                  n.times {|i| c = c.cdr}
         | 
| 213 | 
            +
                  c.car
         | 
| 214 | 
            +
                end
         | 
| 20 215 |  | 
| 21 216 | 
             
                def nth_tail(n)
         | 
| 22 217 | 
             
                  c = self
         | 
    
        data/lib/rubylisp/parser.rb
    CHANGED
    
    | @@ -5,47 +5,37 @@ module Lisp | |
| 5 5 | 
             
                def initialize
         | 
| 6 6 | 
             
                end
         | 
| 7 7 |  | 
| 8 | 
            -
                def make_number(str | 
| 9 | 
            -
                  Lisp::Number.with_value(str.to_i) | 
| 10 | 
            -
                    obj.set_location(pos, str.length)
         | 
| 11 | 
            -
                  end
         | 
| 8 | 
            +
                def make_number(str)
         | 
| 9 | 
            +
                  Lisp::Number.with_value(str.to_i)
         | 
| 12 10 | 
             
                end
         | 
| 13 11 |  | 
| 14 12 | 
             
                def make_hex_number(str)
         | 
| 15 | 
            -
                  Lisp::Number.with_value(["0x", str].join.to_i(0)) | 
| 16 | 
            -
                    obj.set_location(pos, str.length)
         | 
| 17 | 
            -
                  end
         | 
| 13 | 
            +
                  Lisp::Number.with_value(["0x", str].join.to_i(0))
         | 
| 18 14 | 
             
                end
         | 
| 19 15 |  | 
| 20 16 | 
             
                def make_float(str)
         | 
| 21 | 
            -
                  Lisp::Number.with_value(str.to_f) | 
| 22 | 
            -
                    obj.set_location(pos, str.length)
         | 
| 23 | 
            -
                  end
         | 
| 17 | 
            +
                  Lisp::Number.with_value(str.to_f)
         | 
| 24 18 | 
             
                end
         | 
| 25 19 |  | 
| 26 20 | 
             
                def make_string(str)
         | 
| 27 | 
            -
                  Lisp::String.with_value(str) | 
| 28 | 
            -
                    obj.set_location(pos, str.length)
         | 
| 29 | 
            -
                  end
         | 
| 21 | 
            +
                  Lisp::String.with_value(str)
         | 
| 30 22 | 
             
                end
         | 
| 31 23 |  | 
| 32 24 | 
             
                def make_symbol(str)
         | 
| 33 | 
            -
                  Lisp::Symbol.named(str) | 
| 34 | 
            -
                    obj.set_location(pos, str.length)
         | 
| 35 | 
            -
                  end
         | 
| 25 | 
            +
                  Lisp::Symbol.named(str)
         | 
| 36 26 | 
             
                end
         | 
| 37 27 |  | 
| 38 28 | 
             
                def make_character(ch)
         | 
| 39 | 
            -
                  Lisp::Character.with_value(ch) | 
| 40 | 
            -
                    obj.set_location(pos, str.length)
         | 
| 41 | 
            -
                  end
         | 
| 29 | 
            +
                  Lisp::Character.with_value(ch)
         | 
| 42 30 | 
             
                end
         | 
| 43 31 |  | 
| 44 | 
            -
                def parse_cons_cell(tokens)
         | 
| 45 | 
            -
                  tok, lit = tokens.next_token
         | 
| 32 | 
            +
                def parse_cons_cell(start_pos, tokens)
         | 
| 33 | 
            +
                  pos, tok, lit = tokens.next_token
         | 
| 46 34 | 
             
                  if tok == :RPAREN
         | 
| 47 35 | 
             
                    tokens.consume_token
         | 
| 48 | 
            -
                    return Lisp::ConsCell.cons()
         | 
| 36 | 
            +
                    return Lisp::ConsCell.cons().tap do |obj|
         | 
| 37 | 
            +
                      obj.set_location(start_pos, pos - start_pos + 1) if @parse_for_debugging
         | 
| 38 | 
            +
                    end
         | 
| 49 39 | 
             
                  end
         | 
| 50 40 |  | 
| 51 41 | 
             
                  car = nil
         | 
| @@ -56,31 +46,39 @@ module Lisp | |
| 56 46 | 
             
                      tokens.consume_token
         | 
| 57 47 | 
             
                      cdr = self.parse_sexpr(tokens)
         | 
| 58 48 | 
             
                      return nil if tokens.next_token[0] == :EOF
         | 
| 59 | 
            -
                      tok, lit = tokens.next_token
         | 
| 49 | 
            +
                      pos, tok, lit = tokens.next_token
         | 
| 60 50 | 
             
                      return Lisp::Debug.process_error("Expected ')' to follow a dotted tail on line #{tokens.line_number}", Lisp::EnvironmentFrame.global) if tok != :RPAREN
         | 
| 61 51 | 
             
                      tokens.consume_token
         | 
| 62 | 
            -
                      return Lisp::ConsCell.array_to_list(cells, cdr)
         | 
| 52 | 
            +
                      return Lisp::ConsCell.array_to_list(cells, cdr).tap do |obj|
         | 
| 53 | 
            +
                        obj.set_location(start_pos, pos - start_pos + 1) if @parse_for_debugging
         | 
| 54 | 
            +
                      end
         | 
| 63 55 | 
             
                    else
         | 
| 64 56 | 
             
                      car = self.parse_sexpr(tokens)
         | 
| 65 57 | 
             
                      return Lisp::Debug.process_error("Unexpected EOF (expected ')') on line #{tokens.line_number}", Lisp::EnvironmentFrame.global) if tokens.next_token[0] == :EOF
         | 
| 66 58 | 
             
                      cells << car
         | 
| 67 59 | 
             
                    end
         | 
| 68 | 
            -
                    tok, lit = tokens.next_token
         | 
| 60 | 
            +
                    pos, tok, lit = tokens.next_token
         | 
| 69 61 | 
             
                  end
         | 
| 70 62 |  | 
| 71 63 | 
             
                  tokens.consume_token
         | 
| 72 | 
            -
                  Lisp::ConsCell.array_to_list(cells)
         | 
| 64 | 
            +
                  Lisp::ConsCell.array_to_list(cells).tap do |obj|
         | 
| 65 | 
            +
                    obj.set_location(start_pos, pos - start_pos + 1) if @parse_for_debugging
         | 
| 66 | 
            +
                  end
         | 
| 73 67 | 
             
                end
         | 
| 74 68 |  | 
| 75 | 
            -
                def parse_frame(tokens, literal)
         | 
| 69 | 
            +
                def parse_frame(start_pos, tokens, literal)
         | 
| 76 70 | 
             
                  m = {}
         | 
| 77 | 
            -
                  tok, lit = tokens.next_token
         | 
| 71 | 
            +
                  pos, tok, lit = tokens.next_token
         | 
| 78 72 | 
             
                  if tok == :RBRACE
         | 
| 79 73 | 
             
                    tokens.consume_token
         | 
| 80 74 | 
             
                    if literal
         | 
| 81 | 
            -
                      Lisp::Frame.new
         | 
| 75 | 
            +
                      Lisp::Frame.new.tap do |obj|
         | 
| 76 | 
            +
                        obj.set_location(start_pos, pos - start_pos + 1) if @parse_for_debugging
         | 
| 77 | 
            +
                      end
         | 
| 82 78 | 
             
                    else
         | 
| 83 | 
            -
                      Lisp::ConsCell.cons(Lisp::Symbol.named("make-frame"), nil)
         | 
| 79 | 
            +
                      Lisp::ConsCell.cons(Lisp::Symbol.named("make-frame"), nil).tap do |obj|
         | 
| 80 | 
            +
                        obj.set_location(start_pos, pos - start_pos + 1) if @parse_for_debugging
         | 
| 81 | 
            +
                      end
         | 
| 84 82 | 
             
                    end
         | 
| 85 83 | 
             
                  else
         | 
| 86 84 | 
             
                    cells = []
         | 
| @@ -88,29 +86,37 @@ module Lisp | |
| 88 86 | 
             
                      item = self.parse_sexpr(tokens)
         | 
| 89 87 | 
             
                      return Lisp::Debug.process_error("Unexpected EOF (expected '}') on line #{tokens.line_number}", env) if tokens.next_token[0] == :EOF
         | 
| 90 88 | 
             
                      cells << item
         | 
| 91 | 
            -
                      tok, lit = tokens.next_token
         | 
| 89 | 
            +
                      pos, tok, lit = tokens.next_token
         | 
| 92 90 | 
             
                    end
         | 
| 93 91 |  | 
| 94 92 | 
             
                    tokens.consume_token
         | 
| 95 93 | 
             
                    keys_and_values = Lisp::ConsCell.array_to_list(cells)
         | 
| 96 94 | 
             
                    if literal
         | 
| 97 | 
            -
                      Lisp::PrimFrame.make_frame_impl(keys_and_values, Lisp::EnvironmentFrame.global)
         | 
| 95 | 
            +
                      Lisp::PrimFrame.make_frame_impl(keys_and_values, Lisp::EnvironmentFrame.global).tap do |obj|
         | 
| 96 | 
            +
                        obj.set_location(start_pos, pos - start_pos + 1) if @parse_for_debugging
         | 
| 97 | 
            +
                      end
         | 
| 98 98 | 
             
                    else
         | 
| 99 | 
            -
                      Lisp::ConsCell.cons(Lisp::Symbol.named("make-frame"), keys_and_values)
         | 
| 99 | 
            +
                      Lisp::ConsCell.cons(Lisp::Symbol.named("make-frame"), keys_and_values).tap do |obj|
         | 
| 100 | 
            +
                        obj.set_location(start_pos, pos - start_pos + 1) if @parse_for_debugging
         | 
| 101 | 
            +
                      end
         | 
| 100 102 | 
             
                    end
         | 
| 101 103 | 
             
                  end
         | 
| 102 104 | 
             
                end
         | 
| 103 105 |  | 
| 104 106 |  | 
| 105 | 
            -
                def parse_vector(tokens, literal)
         | 
| 107 | 
            +
                def parse_vector(start_pos, tokens, literal)
         | 
| 106 108 | 
             
                  v = []
         | 
| 107 | 
            -
                  tok, lit = tokens.next_token
         | 
| 109 | 
            +
                  pos, tok, lit = tokens.next_token
         | 
| 108 110 | 
             
                  if tok == :RPAREN
         | 
| 109 111 | 
             
                    tokens.consume_token
         | 
| 110 112 | 
             
                    if literal
         | 
| 111 | 
            -
                      Lisp::Vector.new
         | 
| 113 | 
            +
                      Lisp::Vector.new.tap do |obj|
         | 
| 114 | 
            +
                        obj.set_location(start_pos, pos - start_pos + 1) if @parse_for_debugging
         | 
| 115 | 
            +
                      end
         | 
| 112 116 | 
             
                    else
         | 
| 113 | 
            -
                      Lisp::ConsCell.cons(Lis::Symbol.named("vector"), nil)
         | 
| 117 | 
            +
                      Lisp::ConsCell.cons(Lis::Symbol.named("vector"), nil).tap do |obj|
         | 
| 118 | 
            +
                        obj.set_location(start_pos, pos - start_pos + 1) if @parse_for_debugging
         | 
| 119 | 
            +
                      end
         | 
| 114 120 | 
             
                    end
         | 
| 115 121 | 
             
                  else
         | 
| 116 122 | 
             
                    cells = []
         | 
| @@ -118,15 +124,19 @@ module Lisp | |
| 118 124 | 
             
                      item = self.parse_sexpr(tokens)
         | 
| 119 125 | 
             
                      return Lisp::Debug.process_error("Unexpected EOF (expected ')') on line #{tokens.line_number}", env) if tokens.next_token[0] == :EOF
         | 
| 120 126 | 
             
                      cells << item
         | 
| 121 | 
            -
                      tok, lit = tokens.next_token
         | 
| 127 | 
            +
                      pos, tok, lit = tokens.next_token
         | 
| 122 128 | 
             
                    end
         | 
| 123 129 |  | 
| 124 130 | 
             
                    tokens.consume_token
         | 
| 125 131 |  | 
| 126 132 | 
             
                    if literal
         | 
| 127 | 
            -
                      Lisp::Vector.with_array(cells)
         | 
| 133 | 
            +
                      Lisp::Vector.with_array(cells).tap do |obj|
         | 
| 134 | 
            +
                        obj.set_location(start_pos, pos - start_pos + 1) if @parse_for_debugging
         | 
| 135 | 
            +
                      end
         | 
| 128 136 | 
             
                    else
         | 
| 129 | 
            -
                      Lisp::ConsCell.cons(Lisp::Symbol.named("vector"), Lisp::ConsCell.array_to_list(cells))
         | 
| 137 | 
            +
                      Lisp::ConsCell.cons(Lisp::Symbol.named("vector"), Lisp::ConsCell.array_to_list(cells)).tap do |obj|
         | 
| 138 | 
            +
                        obj.set_location(start_pos, pos - start_pos + 1) if @parse_for_debugging
         | 
| 139 | 
            +
                      end
         | 
| 130 140 | 
             
                    end
         | 
| 131 141 | 
             
                  end
         | 
| 132 142 | 
             
                end
         | 
| @@ -134,7 +144,7 @@ module Lisp | |
| 134 144 |  | 
| 135 145 | 
             
                def parse_sexpr(tokens)
         | 
| 136 146 | 
             
                  while true
         | 
| 137 | 
            -
                    tok, lit = tokens.next_token
         | 
| 147 | 
            +
                    pos, tok, lit = tokens.next_token
         | 
| 138 148 | 
             
                    # puts "token: <#{tok}, #{lit}>"
         | 
| 139 149 | 
             
                    return nil if tok == :EOF
         | 
| 140 150 | 
             
                    tokens.consume_token
         | 
| @@ -162,15 +172,15 @@ module Lisp | |
| 162 172 | 
             
                        obj.set_location(pos, lit.length) if @parse_for_debugging
         | 
| 163 173 | 
             
                      end
         | 
| 164 174 | 
             
                    when :LPAREN
         | 
| 165 | 
            -
                      return parse_cons_cell(tokens)
         | 
| 175 | 
            +
                      return parse_cons_cell(pos, tokens)
         | 
| 166 176 | 
             
                    when :LBRACE
         | 
| 167 | 
            -
                      return parse_frame(tokens, false)
         | 
| 177 | 
            +
                      return parse_frame(pos, tokens, false)
         | 
| 168 178 | 
             
                    when :QUOTE_LBRACE
         | 
| 169 | 
            -
                      return parse_frame(tokens, true)
         | 
| 179 | 
            +
                      return parse_frame(pos, tokens, true)
         | 
| 170 180 | 
             
                    when :HASH_LPAREN
         | 
| 171 | 
            -
                      return parse_vector(tokens, false)
         | 
| 181 | 
            +
                      return parse_vector(pos, tokens, false)
         | 
| 172 182 | 
             
                    when :QUOTE_HASH_LPAREN
         | 
| 173 | 
            -
                      return parse_vector(tokens, true)
         | 
| 183 | 
            +
                      return parse_vector(pos, tokens, true)
         | 
| 174 184 | 
             
                    when :SYMBOL
         | 
| 175 185 | 
             
                      return make_symbol(lit).tap do |obj|
         | 
| 176 186 | 
             
                        obj.set_location(pos, lit.length) if @parse_for_debugging
         | 
    
        data/lib/rubylisp/tokenizer.rb
    CHANGED
    
    | @@ -15,6 +15,7 @@ module Lisp | |
| 15 15 | 
             
                def initialize(src, absorb_space=true)
         | 
| 16 16 | 
             
                  @absorb_whitespace = absorb_space
         | 
| 17 17 | 
             
                  @source = src
         | 
| 18 | 
            +
                  @position = 0
         | 
| 18 19 | 
             
                  @lookahead_token = nil
         | 
| 19 20 | 
             
                  @lookahead_literal = ''
         | 
| 20 21 | 
             
                  @eof = false
         | 
| @@ -112,7 +113,7 @@ module Lisp | |
| 112 113 | 
             
                  end
         | 
| 113 114 |  | 
| 114 115 | 
             
                  tok ||= :SYMBOL
         | 
| 115 | 
            -
                  return  | 
| 116 | 
            +
                  return tok, case tok
         | 
| 116 117 | 
             
                              when :SYMBOL, :FFI_STATIC_SYMBOL
         | 
| 117 118 | 
             
                                lit
         | 
| 118 119 | 
             
                              when :FFI_SEND_SYMBOL
         | 
| @@ -143,7 +144,7 @@ module Lisp | |
| 143 144 | 
             
                          :NUMBER
         | 
| 144 145 | 
             
                        end
         | 
| 145 146 |  | 
| 146 | 
            -
                  return  | 
| 147 | 
            +
                  return tok, lit
         | 
| 147 148 | 
             
                end
         | 
| 148 149 |  | 
| 149 150 |  | 
| @@ -183,9 +184,9 @@ module Lisp | |
| 183 184 | 
             
                    advance
         | 
| 184 185 | 
             
                  end
         | 
| 185 186 |  | 
| 186 | 
            -
                  return  | 
| 187 | 
            +
                  return :EOF, '' if eof?
         | 
| 187 188 | 
             
                  advance
         | 
| 188 | 
            -
                  return  | 
| 189 | 
            +
                  return :STRING, process_escapes(lit)
         | 
| 189 190 | 
             
                end
         | 
| 190 191 |  | 
| 191 192 |  | 
| @@ -203,27 +204,26 @@ module Lisp | |
| 203 204 | 
             
                    advance
         | 
| 204 205 | 
             
                  end
         | 
| 205 206 |  | 
| 206 | 
            -
                  return  | 
| 207 | 
            +
                  return :CHARACTER, lit
         | 
| 207 208 | 
             
                end
         | 
| 208 209 |  | 
| 209 210 |  | 
| 210 211 | 
             
                def read_next_token
         | 
| 211 | 
            -
                   | 
| 212 | 
            -
                  
         | 
| 213 | 
            -
                  return @position, :EOF, '' if eof?
         | 
| 212 | 
            +
                  return :EOF, '' if eof?
         | 
| 214 213 |  | 
| 215 214 | 
             
                  if @absorb_whitespace
         | 
| 216 215 | 
             
                    while space?(@current_ch)
         | 
| 217 216 | 
             
                      @line_number += 1 if @current_ch == "\n"
         | 
| 218 217 | 
             
                      advance
         | 
| 219 | 
            -
                       | 
| 218 | 
            +
                      @position = @source.pos
         | 
| 219 | 
            +
                      return :EOF, '' if eof?
         | 
| 220 220 | 
             
                    end
         | 
| 221 221 | 
             
                  end
         | 
| 222 222 |  | 
| 223 223 | 
             
                  if !@absorb_whitespace && space?(@current_ch)
         | 
| 224 224 | 
             
                    @line_number += 1 if @current_ch == "\n"
         | 
| 225 225 | 
             
                    advance
         | 
| 226 | 
            -
                    return  | 
| 226 | 
            +
                    return :WHITESPACE, " "
         | 
| 227 227 | 
             
                  elsif number?(@current_ch)
         | 
| 228 228 | 
             
                    return read_number(false)
         | 
| 229 229 | 
             
                  elsif @current_ch == '-' && number?(@next_ch)
         | 
| @@ -242,50 +242,50 @@ module Lisp | |
| 242 242 | 
             
                  elsif @current_ch == '\'' && @next_ch == '{'
         | 
| 243 243 | 
             
                    advance
         | 
| 244 244 | 
             
                    advance
         | 
| 245 | 
            -
                    return  | 
| 245 | 
            +
                    return :QUOTE_LBRACE, "'{"
         | 
| 246 246 | 
             
                  elsif @current_ch == '\'' && @next_ch == '#' && @next_next_ch == '('
         | 
| 247 247 | 
             
                    advance
         | 
| 248 248 | 
             
                    advance
         | 
| 249 249 | 
             
                    advance
         | 
| 250 | 
            -
                    return  | 
| 250 | 
            +
                    return :QUOTE_HASH_LPAREN, "'#("
         | 
| 251 251 | 
             
                  elsif @current_ch == '\''
         | 
| 252 252 | 
             
                    advance
         | 
| 253 | 
            -
                    return  | 
| 253 | 
            +
                    return :QUOTE, "'"
         | 
| 254 254 | 
             
                  elsif @current_ch == '`'
         | 
| 255 255 | 
             
                    advance
         | 
| 256 | 
            -
                    return  | 
| 256 | 
            +
                    return :BACKQUOTE, "`"
         | 
| 257 257 | 
             
                  elsif @current_ch == ',' && @next_ch == '@'
         | 
| 258 258 | 
             
                    advance
         | 
| 259 259 | 
             
                    advance
         | 
| 260 | 
            -
                    return  | 
| 260 | 
            +
                    return :COMMAAT, ",@"
         | 
| 261 261 | 
             
                  elsif @current_ch == ','
         | 
| 262 262 | 
             
                    advance
         | 
| 263 | 
            -
                    return  | 
| 263 | 
            +
                    return :COMMA, ","
         | 
| 264 264 | 
             
                  elsif @current_ch == '('
         | 
| 265 265 | 
             
                    advance
         | 
| 266 | 
            -
                    return  | 
| 266 | 
            +
                    return :LPAREN, "("
         | 
| 267 267 | 
             
                  elsif @current_ch == '#' && @next_ch == '('
         | 
| 268 268 | 
             
                    advance
         | 
| 269 269 | 
             
                    advance
         | 
| 270 | 
            -
                    return  | 
| 270 | 
            +
                    return :HASH_LPAREN, "#("
         | 
| 271 271 | 
             
                  elsif @current_ch == ')'
         | 
| 272 272 | 
             
                    advance
         | 
| 273 | 
            -
                    return  | 
| 273 | 
            +
                    return :RPAREN, ")"
         | 
| 274 274 | 
             
                  elsif @current_ch == '{'
         | 
| 275 275 | 
             
                    advance
         | 
| 276 | 
            -
                     | 
| 276 | 
            +
                    return :LBRACE, "{"
         | 
| 277 277 | 
             
                  elsif @current_ch == '}'
         | 
| 278 278 | 
             
                    advance
         | 
| 279 | 
            -
                    return  | 
| 279 | 
            +
                    return :RBRACE, "}"
         | 
| 280 280 | 
             
                  elsif @current_ch == '['
         | 
| 281 281 | 
             
                    advance
         | 
| 282 | 
            -
                    return  | 
| 282 | 
            +
                    return :LBRACKET, "["
         | 
| 283 283 | 
             
                  elsif @current_ch == ']'
         | 
| 284 284 | 
             
                    advance
         | 
| 285 | 
            -
                    return  | 
| 285 | 
            +
                    return :RBRACKET, "]"
         | 
| 286 286 | 
             
                  elsif @current_ch == '.' && space?(@next_ch)
         | 
| 287 287 | 
             
                    advance
         | 
| 288 | 
            -
                    return  | 
| 288 | 
            +
                    return :PERIOD, "."
         | 
| 289 289 | 
             
                  elsif @current_ch == '.' && symbol_character?(@next_ch)
         | 
| 290 290 | 
             
                    return read_symbol
         | 
| 291 291 | 
             
                    elsif symbol_character?(@current_ch)
         | 
| @@ -293,24 +293,25 @@ module Lisp | |
| 293 293 | 
             
                    elsif @current_ch == '#' && @next_ch == 't'
         | 
| 294 294 | 
             
                    advance
         | 
| 295 295 | 
             
                    advance
         | 
| 296 | 
            -
                    return  | 
| 296 | 
            +
                    return :TRUE, "#t"
         | 
| 297 297 | 
             
                  elsif @current_ch == '#' && @next_ch == 'f'
         | 
| 298 298 | 
             
                    advance
         | 
| 299 299 | 
             
                    advance
         | 
| 300 | 
            -
                    return  | 
| 300 | 
            +
                    return :FALSE, "#f"
         | 
| 301 301 | 
             
                  elsif @current_ch == ';'
         | 
| 302 302 | 
             
                    lit = ""
         | 
| 303 303 | 
             
                    while true
         | 
| 304 | 
            -
                      return  | 
| 304 | 
            +
                      return :COMMENT, lit if eof? || @current_ch == "\n"
         | 
| 305 305 | 
             
                      lit << @current_ch
         | 
| 306 306 | 
             
                      advance
         | 
| 307 307 | 
             
                    end
         | 
| 308 308 | 
             
                  else
         | 
| 309 | 
            -
                    return  | 
| 309 | 
            +
                    return :ILLEGAL, @current_ch
         | 
| 310 310 | 
             
                  end
         | 
| 311 311 | 
             
                end
         | 
| 312 312 |  | 
| 313 313 | 
             
                def consume_token
         | 
| 314 | 
            +
                  @position = @source.pos
         | 
| 314 315 | 
             
                  @lookahead_token, @lookahead_literal = self.read_next_token
         | 
| 315 316 | 
             
                  consume_token if @lookahead_token == :COMMENT
         | 
| 316 317 | 
             
                end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rubymotionlisp
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0. | 
| 4 | 
            +
              version: 1.0.14
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Dave Astels
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2016-03- | 
| 11 | 
            +
            date: 2016-03-13 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 13 | 
             
            description: An embeddable Lisp as an extension language for RubyMotion
         | 
| 14 14 | 
             
            email: dastels@icloud.com
         |