Fix nested comma handling in a backquote

This commit is contained in:
Mike Cifelli 2017-03-12 14:18:37 -04:00
parent e89a6f2dde
commit c2d722d5ab
2 changed files with 21 additions and 0 deletions

View File

@ -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;

View File

@ -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));
}
}