mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 21:21:33 +00:00
parser: cleanup code for fixing comma bug
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
export let count = 5
|
let count = 5
|
||||||
|
|
||||||
export func main() {
|
export func main() {
|
||||||
var x = 1
|
var x = 1
|
||||||
|
@ -60,11 +60,7 @@ class Parser(source: PeekableSource<Token>, val attribution: NodeAttribution) {
|
|||||||
private fun readSymbolCases(): Expression = within {
|
private fun readSymbolCases(): Expression = within {
|
||||||
val symbol = readSymbolRaw()
|
val symbol = readSymbolRaw()
|
||||||
if (next(TokenType.LeftParentheses)) {
|
if (next(TokenType.LeftParentheses)) {
|
||||||
val arguments = collect(
|
val arguments = collect(TokenType.RightParentheses, TokenType.Comma) {
|
||||||
TokenType.RightParentheses,
|
|
||||||
TokenType.Comma,
|
|
||||||
forceConsumeExceptLast = true
|
|
||||||
) {
|
|
||||||
readExpression()
|
readExpression()
|
||||||
}
|
}
|
||||||
expect(TokenType.RightParentheses)
|
expect(TokenType.RightParentheses)
|
||||||
@ -363,19 +359,16 @@ class Parser(source: PeekableSource<Token>, val attribution: NodeAttribution) {
|
|||||||
private fun <T> collect(
|
private fun <T> collect(
|
||||||
peeking: TokenType,
|
peeking: TokenType,
|
||||||
consuming: TokenType? = null,
|
consuming: TokenType? = null,
|
||||||
forceConsumeExceptLast: Boolean = false,
|
|
||||||
read: () -> T
|
read: () -> T
|
||||||
): List<T> {
|
): List<T> {
|
||||||
val items = mutableListOf<T>()
|
val items = mutableListOf<T>()
|
||||||
while (!peek(peeking)) {
|
while (!peek(peeking)) {
|
||||||
val item = read()
|
val item = read()
|
||||||
if (consuming != null) {
|
if (consuming != null) {
|
||||||
if (!next(consuming)) {
|
|
||||||
if (!peek(peeking)) {
|
if (!peek(peeking)) {
|
||||||
expect(consuming)
|
expect(consuming)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
items.add(item)
|
items.add(item)
|
||||||
}
|
}
|
||||||
return items
|
return items
|
||||||
|
Reference in New Issue
Block a user