alphalang 0.2.3 → 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: c46055bf730f2a26ce876fcc685a711359a5e80710da1e86e7eac6e7554af007
4
- data.tar.gz: d2751a739b78101ce213c6b29db88fbcc57a0c33dad4282f5bf1d5e385ba7461
3
+ metadata.gz: dbfdb16caf742bce82c36b55c0ac51952e472fb3f286c26e1a3f1114579b6968
4
+ data.tar.gz: 3da5256af5667909386065af82d90d34f470ab4203fde1a36fa02dc95b4ba16d
5
5
  SHA512:
6
- metadata.gz: c873cf09f9c0831cbfd15a9f7cdc01a29e2bbe035cf9b04033ea5b6c14be54a7b95d34ed278658892ce9c56e6b1ab81ed998e220ca8a21898c08efe8c4feb2e2
7
- data.tar.gz: a34c736242f1b4ab7a5f42d1a3173ada74add81c83e1d6da106c91ccef75f457b2bb73e18bca3f81264c1f0a6ab1b3d09c8edd737ecb4d443623858ef4502674
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)
@@ -189,7 +189,7 @@ class PrintNode
189
189
  def evaluate
190
190
  if @value.evaluate.is_a?(ArrayNode)
191
191
  print "Array #{@value.name}: "
192
- @value.evaluate.display_on_one_line
192
+ puts @value.evaluate
193
193
  elsif @value.evaluate.is_a?(Array)
194
194
  print "Array #{@value.name}: "
195
195
  puts @value.evaluate.join(', ')
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.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - mattias, victor