Skip to content

Commit 114db0c

Browse files
committed
bugfix star macro
1 parent 9357e6a commit 114db0c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/main/java/io/polypen/parse/Macro.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static ListExpr applyStarMacro(ListExpr listExpr) {
2020
Expr previous = null;
2121
for (int i = 0; i < exprs.size(); i++) {
2222
Expr expr = exprs.get(i);
23-
if (isStrongBind(previous) && (!isPlus(expr) || !region.isEmpty())) {
23+
if (isStrongBind(previous) && (isStrongBind(expr) || !region.isEmpty())) {
2424
region.add(previous);
2525
} else {
2626
if (!region.isEmpty()) {
@@ -46,7 +46,7 @@ public static boolean isStrongBind(Expr expr) {
4646
if (expr == null) {
4747
return false;
4848
}
49-
return expr instanceof MultExpr || expr instanceof VarExp || expr instanceof NumberExpr;
49+
return expr instanceof MultExpr || expr instanceof VarExp || expr instanceof NumberExpr || expr instanceof ListExpr;
5050
}
5151

5252
public static boolean isPlus(Expr expr) {

src/test/java/io/polypen/parse/ParserTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,15 @@ void starMacro2() {
3737
NumberExpr.of(1), PLUS, ListExpr.of(NumberExpr.of(2), MULT, NumberExpr.of(3)), PLUS, NumberExpr.of(4)),
3838
expanded);
3939
}
40+
41+
@Test
42+
void starMacro3() {
43+
ListExpr result = Parser.parse("(1 + 2) * 3");
44+
ListExpr expanded = applyStarMacro(result);
45+
assertEquals(ListExpr.of(
46+
ListExpr.of(
47+
ListExpr.of(NumberExpr.of(1), PLUS, NumberExpr.of(2)),
48+
MULT, NumberExpr.of(3))),
49+
expanded);
50+
}
4051
}

0 commit comments

Comments
 (0)