alphalang 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab47be57b758b60ecfd23d623f079f39cad75aff9e55d44abbcb848bf981892f
4
- data.tar.gz: 722308d6394542dc4afc4cf6ea88b6403e0ed7db5a3ccf39e891b14eb6505526
3
+ metadata.gz: dbfdb16caf742bce82c36b55c0ac51952e472fb3f286c26e1a3f1114579b6968
4
+ data.tar.gz: 3da5256af5667909386065af82d90d34f470ab4203fde1a36fa02dc95b4ba16d
5
5
  SHA512:
6
- metadata.gz: 8cfd7fabcd48b1b5b50e12c9f24c42e6e25bd464a36d47954af1c9401de63b5832cb3ca063b6dde1bd3fe575ae761c8da9507b6eb185ef1ae3a1e593436b8add
7
- data.tar.gz: d4b0aa62aac244dad17fe2898fc4e21a1dbc0fa54a0bb51e980a80d15f2491dd42fdf6e6ed17574e4761a4e1e7b5a491565048610acfa4a43f1dffc73fd81055
6
+ metadata.gz: 859580c36eb816c5a7f726b693784f41b0d59fa436d40ce5b9d6ff44661d15041a248c21d896e40c9fbebb9633f1b701298edd933ac1b77ed8a1ab79a4ac92cd
7
+ data.tar.gz: e0afd18953789ded0647fba4bece0ae465684957a6d127c3ca17b3d7b1aa1c82679d62c273289800fc510b5dba5c72175c371b5606401f816914ffd826a3ee3c
@@ -137,6 +137,16 @@ class BinaryOperationNode < Node
137
137
  return @value = @lhs.evaluate.append(@rhs.evaluate)
138
138
  end
139
139
 
140
+ if @rhs.evaluate.is_a?(ArrayNode) && @op == '-'
141
+ return @value = @rhs.evaluate - @lhs.evaluate
142
+ elsif @lhs.evaluate.is_a?(Array) && @op == '-'
143
+ return @lhs.evaluate.reject { |v| v.evaluate == @rhs.evaluate }
144
+ end
145
+
146
+ if @rhs.evaluate.is_a?(ArrayNode) or @rhs.evaluate.is_a?(Array) and @lhs.evaluate.is_a?(Numeric)
147
+ raise SyntaxError, "You can't subtract and array from a number! #{@lhs.evaluate} #{@op} #{@rhs.name}"
148
+ end
149
+
140
150
  if @op == '/'
141
151
  @value = @lhs.evaluate.to_f.send(@op, @rhs.evaluate)
142
152
  else
@@ -186,8 +196,16 @@ class ArrayNode < Node
186
196
  puts @value.join(', ')
187
197
  end
188
198
 
189
- def +(index)
190
- @value.append(index)
199
+ def to_s
200
+ @value.join(', ')
201
+ end
202
+
203
+ def +(value)
204
+ @value.append(value)
205
+ end
206
+
207
+ def -(value)
208
+ @value.reject { |v| v.evaluate == value }
191
209
  end
192
210
 
193
211
  def [](index)
@@ -188,8 +188,10 @@ class PrintNode
188
188
 
189
189
  def evaluate
190
190
  if @value.evaluate.is_a?(ArrayNode)
191
- @value.evaluate.display_on_one_line
191
+ print "Array #{@value.name}: "
192
+ puts @value.evaluate
192
193
  elsif @value.evaluate.is_a?(Array)
194
+ print "Array #{@value.name}: "
193
195
  puts @value.evaluate.join(', ')
194
196
  else
195
197
  puts @value.evaluate
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alphalang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - mattias, victor