-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gradle: 8.4 and parser: lazy tokenization
- Loading branch information
Showing
8 changed files
with
59 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,5 @@ plugins { | |
} | ||
|
||
tasks.withType<Wrapper> { | ||
gradleVersion = "8.3" | ||
gradleVersion = "8.4" | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
parser/src/main/kotlin/gay/pizza/pork/parser/LazyTokenSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package gay.pizza.pork.parser | ||
|
||
class LazyTokenSource(val tokenizer: Tokenizer) : TokenSource { | ||
private val queue = mutableListOf<Token>() | ||
private var index = 0 | ||
override val currentIndex: Int | ||
get() = index | ||
|
||
override fun next(): Token { | ||
index++ | ||
if (queue.isNotEmpty()) { | ||
return queue.removeFirst() | ||
} | ||
return tokenizer.next() | ||
} | ||
|
||
override fun peek(): Token { | ||
if (queue.isNotEmpty()) { | ||
return queue.first() | ||
} | ||
val token = tokenizer.next() | ||
queue.add(token) | ||
return token | ||
} | ||
|
||
override fun peekTypeAhead(ahead: Int): TokenType { | ||
wantAtLeast(ahead + 1) | ||
return queue[ahead].type | ||
} | ||
|
||
private fun wantAtLeast(ahead: Int) { | ||
if (queue.size < ahead) { | ||
for (i in 1..ahead) { | ||
queue.add(tokenizer.next()) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters