Fix nested comma handling in a backquote
This commit is contained in:
parent
e89a6f2dde
commit
c2d722d5ab
|
@ -57,6 +57,8 @@ class BackquoteEvaluator {
|
||||||
throw new AtSignNotInCommaException();
|
throw new AtSignNotInCommaException();
|
||||||
else if (expression.isComma())
|
else if (expression.isComma())
|
||||||
resolveCommaExpression(expression);
|
resolveCommaExpression(expression);
|
||||||
|
else if (expression.isList())
|
||||||
|
resolveListExpression(expression);
|
||||||
else
|
else
|
||||||
addResolvedExpression(expression);
|
addResolvedExpression(expression);
|
||||||
}
|
}
|
||||||
|
@ -122,6 +124,11 @@ class BackquoteEvaluator {
|
||||||
leader = (Cons) leader.getRest();
|
leader = (Cons) leader.getRest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void resolveListExpression(SExpression expression) {
|
||||||
|
BackquoteEvaluator evaluator = new BackquoteEvaluator(new BackquoteExpression(expression));
|
||||||
|
addResolvedExpression(evaluator.evaluate());
|
||||||
|
}
|
||||||
|
|
||||||
private static class CommaEvaluationResult {
|
private static class CommaEvaluationResult {
|
||||||
|
|
||||||
private SExpression result;
|
private SExpression result;
|
||||||
|
|
|
@ -148,4 +148,18 @@ public class EVALTester {
|
||||||
assertIsErrorWithMessage(new UnmatchedAtSignException());
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue