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 +4 -4
- data/lib/nodes/basenodes.rb +20 -2
- data/lib/nodes/stmtnodes.rb +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbfdb16caf742bce82c36b55c0ac51952e472fb3f286c26e1a3f1114579b6968
|
4
|
+
data.tar.gz: 3da5256af5667909386065af82d90d34f470ab4203fde1a36fa02dc95b4ba16d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 859580c36eb816c5a7f726b693784f41b0d59fa436d40ce5b9d6ff44661d15041a248c21d896e40c9fbebb9633f1b701298edd933ac1b77ed8a1ab79a4ac92cd
|
7
|
+
data.tar.gz: e0afd18953789ded0647fba4bece0ae465684957a6d127c3ca17b3d7b1aa1c82679d62c273289800fc510b5dba5c72175c371b5606401f816914ffd826a3ee3c
|
data/lib/nodes/basenodes.rb
CHANGED
@@ -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
|
190
|
-
@value.
|
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)
|
data/lib/nodes/stmtnodes.rb
CHANGED
@@ -188,8 +188,10 @@ class PrintNode
|
|
188
188
|
|
189
189
|
def evaluate
|
190
190
|
if @value.evaluate.is_a?(ArrayNode)
|
191
|
-
@value.
|
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
|