adding in a slice operator
This commit is contained in:
parent
b98281312e
commit
a58c813dda
@ -247,6 +247,28 @@ class HyASTCompiler(object):
|
|||||||
slice=ast.Index(value=sli),
|
slice=ast.Index(value=sli),
|
||||||
ctx=ast.Load())
|
ctx=ast.Load())
|
||||||
|
|
||||||
|
@builds("slice")
|
||||||
|
def compile_slice_expression(self, expr):
|
||||||
|
expr.pop(0) # index
|
||||||
|
val = self.compile(expr.pop(0)) # target
|
||||||
|
|
||||||
|
low = None
|
||||||
|
if expr != []:
|
||||||
|
low = self.compile(expr.pop(0))
|
||||||
|
|
||||||
|
high = None
|
||||||
|
if expr != []:
|
||||||
|
high = self.compile(expr.pop(0))
|
||||||
|
|
||||||
|
return ast.Subscript(
|
||||||
|
lineno=expr.start_line,
|
||||||
|
col_offset=expr.start_column,
|
||||||
|
value=val,
|
||||||
|
slice=ast.Slice(lower=low,
|
||||||
|
upper=high,
|
||||||
|
step=None),
|
||||||
|
ctx=ast.Load())
|
||||||
|
|
||||||
@builds("assoc")
|
@builds("assoc")
|
||||||
def compile_assoc_expression(self, expr):
|
def compile_assoc_expression(self, expr):
|
||||||
expr.pop(0) # assoc
|
expr.pop(0) # assoc
|
||||||
|
@ -176,3 +176,10 @@
|
|||||||
"NATIVE: test firsty things"
|
"NATIVE: test firsty things"
|
||||||
(assert (= (first [1 2 3 4 5]) 1))
|
(assert (= (first [1 2 3 4 5]) 1))
|
||||||
(assert (= (car [1 2 3 4 5]) 1)))
|
(assert (= (car [1 2 3 4 5]) 1)))
|
||||||
|
|
||||||
|
|
||||||
|
(defn test-slice []
|
||||||
|
"NATIVE: test slice"
|
||||||
|
(assert (= (slice [1 2 3 4 5] 1) [2 3 4 5]))
|
||||||
|
(assert (= (slice [1 2 3 4 5] 1 3) [2 3]))
|
||||||
|
(assert (= (slice [1 2 3 4 5]) [1 2 3 4 5])))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user