From d8c0ef43c1664f1323111ee31a03d5ab63f487f3 Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Mon, 11 Sep 2023 05:20:08 -0400 Subject: [PATCH] parser: cleanup code for fixing comma bug --- examples/count.pork | 2 +- .../src/main/kotlin/gay/pizza/pork/parser/Parser.kt | 13 +++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/examples/count.pork b/examples/count.pork index e9d72a2..7736387 100644 --- a/examples/count.pork +++ b/examples/count.pork @@ -1,4 +1,4 @@ -export let count = 5 +let count = 5 export func main() { var x = 1 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 f838275..287578f 100644 --- a/parser/src/main/kotlin/gay/pizza/pork/parser/Parser.kt +++ b/parser/src/main/kotlin/gay/pizza/pork/parser/Parser.kt @@ -60,11 +60,7 @@ 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, - forceConsumeExceptLast = true - ) { + val arguments = collect(TokenType.RightParentheses, TokenType.Comma) { readExpression() } expect(TokenType.RightParentheses) @@ -363,17 +359,14 @@ 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) { - if (!next(consuming)) { - if (!peek(peeking)) { - expect(consuming) - } + if (!peek(peeking)) { + expect(consuming) } } items.add(item)