Skip to content

Commit d0cf8ca

Browse files
committed
[ bug ] Bug fix
1 parent 2663dab commit d0cf8ca

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/main/kotlin/org/lice/parse/Parser.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@ object Parser {
1010
return ASTRootNode(nodes)
1111
}
1212

13-
private fun parseNode(l: Lexer): ASTNode {
14-
return if (l.currentToken().type == Token.TokenType.LispKwd && l.currentToken().strValue == "(") {
15-
parseList(l)
16-
} else {
17-
val ret = ASTAtomicNode(l.currentToken().metaData, l.currentToken())
18-
l.nextToken()
19-
ret
20-
}
21-
}
13+
private fun parseNode(l: Lexer) =
14+
if (l.currentToken().type == Token.TokenType.LispKwd && l.currentToken().strValue == "(") parseList(l)
15+
else {
16+
val ret = ASTAtomicNode(l.currentToken().metaData, l.currentToken())
17+
l.nextToken()
18+
ret
19+
}
2220

2321
private fun parseList(l: Lexer): ASTListNode {
2422
// assert(l.currentToken().type == Token.TokenType.LispKwd && l.currentToken().strValue == "(")
2523
l.nextToken()
2624
val leftParthToken = l.currentToken()
2725
val subNodes = ArrayList<ASTNode>()
28-
while (!(l.currentToken().type == Token.TokenType.LispKwd && l.currentToken().strValue == ")")) {
26+
while (!(l.currentToken().type == Token.TokenType.LispKwd
27+
&& l.currentToken().strValue == ")")
28+
&& l.currentToken().type != Token.TokenType.EOI) {
2929
subNodes.add(parseNode(l))
30-
if (l.currentToken().type == Token.TokenType.EOI)
31-
throw ParseException("Unexpected EOI, expected ')'", l.currentToken().metaData)
3230
}
31+
if (l.currentToken().type == Token.TokenType.EOI)
32+
throw ParseException("Unexpected EOI, expected ')'", l.currentToken().metaData)
3333

3434
l.nextToken()
3535
return ASTListNode(leftParthToken.metaData, subNodes)

src/test/kotlin/org/lice/lang/LevelerTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class LevelerTest {
6868
Lice.run("(<= 1 1L 1N 1.0F 1.0D 1M)")
6969
Lice.run("(>= 1 1L 1N 1.0F 1.0D 1M)")
7070
Lice.run("(- 1 1L 1N 1.0F 1.0D 1M)")
71+
Lice.run("(+ 1 1L 1N 1.0F 1.0D 1M)")
7172
Lice.run("(/ 1 1L 1N 1.0F 1.0D 1M)")
7273
Lice.run("(* 1 1L 1N 1.0F 1.0D 1M)")
7374
Lice.run("(% 1 2L 3N 4.0F 5.0D 6M)")

0 commit comments

Comments
 (0)