diff --git a/parser/src/main/kotlin/gay/pizza/pork/parser/Parser.kt b/parser/src/main/kotlin/gay/pizza/pork/parser/Parser.kt index c88adde..f838275 100644 --- a/parser/src/main/kotlin/gay/pizza/pork/parser/Parser.kt +++ b/parser/src/main/kotlin/gay/pizza/pork/parser/Parser.kt @@ -60,7 +60,11 @@ class Parser(source: PeekableSource, val attribution: NodeAttribution) { private fun readSymbolCases(): Expression = within { val symbol = readSymbolRaw() if (next(TokenType.LeftParentheses)) { - val arguments = collect(TokenType.RightParentheses, TokenType.Comma) { + val arguments = collect( + TokenType.RightParentheses, + TokenType.Comma, + forceConsumeExceptLast = true + ) { readExpression() } expect(TokenType.RightParentheses) @@ -359,13 +363,18 @@ class Parser(source: PeekableSource, val attribution: NodeAttribution) { private fun collect( peeking: TokenType, consuming: TokenType? = null, + forceConsumeExceptLast: Boolean = false, read: () -> T ): List { val items = mutableListOf() while (!peek(peeking)) { val item = read() if (consuming != null) { - next(consuming) + if (!next(consuming)) { + if (!peek(peeking)) { + expect(consuming) + } + } } items.add(item) }