-
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.
tokenizer: remove TokenStream, use sequences instead
- Loading branch information
Showing
7 changed files
with
58 additions
and
52 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
4 changes: 2 additions & 2 deletions
4
tokenizer/src/main/kotlin/gay/pizza/pork/tokenizer/Highlighter.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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package gay.pizza.pork.tokenizer | ||
|
||
class Highlighter(val scheme: HighlightScheme) { | ||
fun highlight(stream: TokenStream): List<Highlight> = | ||
stream.tokens.map { scheme.highlight(it) } | ||
fun highlight(source: TokenSource): Sequence<Highlight> = | ||
source.sequence().map { scheme.highlight(it) } | ||
} |
32 changes: 32 additions & 0 deletions
32
tokenizer/src/main/kotlin/gay/pizza/pork/tokenizer/ListTokenSource.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,32 @@ | ||
package gay.pizza.pork.tokenizer | ||
|
||
class ListTokenSource(val tokens: List<Token>) : TokenSource { | ||
private var index = 0 | ||
|
||
override val currentIndex: Int | ||
get() = index | ||
|
||
override fun next(): Token { | ||
if (index == tokens.size) { | ||
return tokens.last() | ||
} | ||
val char = tokens[index] | ||
index++ | ||
return char | ||
} | ||
|
||
override fun peek(): Token { | ||
if (index == tokens.size) { | ||
return tokens.last() | ||
} | ||
return tokens[index] | ||
} | ||
|
||
override fun peekTypeAhead(ahead: Int): TokenType { | ||
val calculated = index + ahead | ||
if (calculated >= tokens.size) { | ||
return tokens.last().type | ||
} | ||
return tokens[calculated].type | ||
} | ||
} |
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
5 changes: 0 additions & 5 deletions
5
tokenizer/src/main/kotlin/gay/pizza/pork/tokenizer/TokenStream.kt
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
tokenizer/src/main/kotlin/gay/pizza/pork/tokenizer/TokenStreamSource.kt
This file was deleted.
Oops, something went wrong.
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