mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-02 12:50:55 +00:00
parser: cleanup code for fixing comma bug
This commit is contained in:
parent
dbe4e7d5a5
commit
d8c0ef43c1
@ -1,4 +1,4 @@
|
||||
export let count = 5
|
||||
let count = 5
|
||||
|
||||
export func main() {
|
||||
var x = 1
|
||||
|
@ -60,11 +60,7 @@ class Parser(source: PeekableSource<Token>, 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<Token>, val attribution: NodeAttribution) {
|
||||
private fun <T> collect(
|
||||
peeking: TokenType,
|
||||
consuming: TokenType? = null,
|
||||
forceConsumeExceptLast: Boolean = false,
|
||||
read: () -> T
|
||||
): List<T> {
|
||||
val items = mutableListOf<T>()
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user