Distinguish between quote and quasiquote
This commit is contained in:
parent
322a9992e5
commit
58bb3239ee
@ -494,7 +494,7 @@ class HyASTCompiler(object):
|
|||||||
ret += ret.expr_as_stmt()
|
ret += ret.expr_as_stmt()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def _render_quoted_form(self, form, level=0):
|
def _render_quoted_form(self, form, level):
|
||||||
"""
|
"""
|
||||||
Render a quoted form as a new HyExpression.
|
Render a quoted form as a new HyExpression.
|
||||||
|
|
||||||
@ -517,7 +517,7 @@ class HyASTCompiler(object):
|
|||||||
return set(), form[1], (form[0] == "unquote_splice")
|
return set(), form[1], (form[0] == "unquote_splice")
|
||||||
|
|
||||||
if isinstance(form, HyExpression):
|
if isinstance(form, HyExpression):
|
||||||
if form and form[0] == "quote":
|
if form and form[0] == "quasiquote":
|
||||||
level += 1
|
level += 1
|
||||||
if form and form[0] in ("unquote", "unquote_splice"):
|
if form and form[0] in ("unquote", "unquote_splice"):
|
||||||
level -= 1
|
level -= 1
|
||||||
@ -550,9 +550,15 @@ class HyASTCompiler(object):
|
|||||||
form]).replace(form), False
|
form]).replace(form), False
|
||||||
|
|
||||||
@builds("quote")
|
@builds("quote")
|
||||||
|
@builds("quasiquote")
|
||||||
@checkargs(exact=1)
|
@checkargs(exact=1)
|
||||||
def compile_quote(self, entries):
|
def compile_quote(self, entries):
|
||||||
imports, stmts, splice = self._render_quoted_form(entries[1])
|
if entries[0] == "quote":
|
||||||
|
# Never allow unquoting
|
||||||
|
level = float("inf")
|
||||||
|
else:
|
||||||
|
level = 0
|
||||||
|
imports, stmts, splice = self._render_quoted_form(entries[1], level)
|
||||||
ret = self.compile(stmts)
|
ret = self.compile(stmts)
|
||||||
ret.add_imports("hy", imports)
|
ret.add_imports("hy", imports)
|
||||||
return ret
|
return ret
|
||||||
|
Loading…
x
Reference in New Issue
Block a user