From c2d722d5abd121da48969e61d72e59f8101ea95a Mon Sep 17 00:00:00 2001 From: Mike Cifelli Date: Sun, 12 Mar 2017 14:18:37 -0400 Subject: [PATCH] Fix nested comma handling in a backquote --- src/function/builtin/BackquoteEvaluator.java | 7 +++++++ test/function/builtin/EVALTester.java | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/function/builtin/BackquoteEvaluator.java b/src/function/builtin/BackquoteEvaluator.java index c882423..e62738c 100644 --- a/src/function/builtin/BackquoteEvaluator.java +++ b/src/function/builtin/BackquoteEvaluator.java @@ -57,6 +57,8 @@ class BackquoteEvaluator { throw new AtSignNotInCommaException(); else if (expression.isComma()) resolveCommaExpression(expression); + else if (expression.isList()) + resolveListExpression(expression); else addResolvedExpression(expression); } @@ -122,6 +124,11 @@ class BackquoteEvaluator { leader = (Cons) leader.getRest(); } + private void resolveListExpression(SExpression expression) { + BackquoteEvaluator evaluator = new BackquoteEvaluator(new BackquoteExpression(expression)); + addResolvedExpression(evaluator.evaluate()); + } + private static class CommaEvaluationResult { private SExpression result; diff --git a/test/function/builtin/EVALTester.java b/test/function/builtin/EVALTester.java index 2b51bd4..ec6b9ff 100644 --- a/test/function/builtin/EVALTester.java +++ b/test/function/builtin/EVALTester.java @@ -148,4 +148,18 @@ public class EVALTester { assertIsErrorWithMessage(new UnmatchedAtSignException()); } + @Test + public void evalQuoteInNestedList() { + String input = "(let ((g 27)) `((,g)))"; + + assertSExpressionsMatch(parseString("((27))"), evaluateString(input)); + } + + @Test + public void evalAtSignInNestedList() { + String input = "(let ((g '(1 2 3))) `((,@g)))"; + + assertSExpressionsMatch(parseString("((1 2 3))"), evaluateString(input)); + } + }