@@ -10,26 +10,26 @@ object Parser {
10
10
return ASTRootNode (nodes)
11
11
}
12
12
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
+ }
22
20
23
21
private fun parseList (l : Lexer ): ASTListNode {
24
22
// assert(l.currentToken().type == Token.TokenType.LispKwd && l.currentToken().strValue == "(")
25
23
l.nextToken()
26
24
val leftParthToken = l.currentToken()
27
25
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 ) {
29
29
subNodes.add(parseNode(l))
30
- if (l.currentToken().type == Token .TokenType .EOI )
31
- throw ParseException (" Unexpected EOI, expected ')'" , l.currentToken().metaData)
32
30
}
31
+ if (l.currentToken().type == Token .TokenType .EOI )
32
+ throw ParseException (" Unexpected EOI, expected ')'" , l.currentToken().metaData)
33
33
34
34
l.nextToken()
35
35
return ASTListNode (leftParthToken.metaData, subNodes)
0 commit comments