StringStream

class StringStream(val string: String, tabSize: Int, val indentUnit: Int, overrideIndent: Int? = null)

Encapsulates a single line of input. Given to stream syntax code, which uses it to tokenize the content.

Constructors

Link copied to clipboard
constructor(string: String, tabSize: Int, indentUnit: Int, overrideIndent: Int? = null)

Properties

Link copied to clipboard

The current indent unit size.

Link copied to clipboard
var pos: Int

The current position on the line.

Link copied to clipboard
var start: Int

The start position of the current token.

Link copied to clipboard

The line content.

Functions

Link copied to clipboard
fun backUp(n: Int)

Move back n characters.

Link copied to clipboard
fun column(): Int

Get the column position at start.

Link copied to clipboard

Get the current token string.

Link copied to clipboard
fun eat(predicate: (String) -> Boolean): String?

Consume and return the next character if predicate returns true.

fun eat(ch: String): String?

Consume and return the next character if it equals ch.

fun eat(pattern: Regex): String?

Consume and return the next character if it matches pattern.

Link copied to clipboard

Consume whitespace ahead of pos. Return true if any was found.

Link copied to clipboard
fun eatWhile(predicate: (String) -> Boolean): Boolean

Continue matching characters for which the predicate returns true. Return true if any characters were consumed.

Continue matching characters that match the given string. Return true if any characters were consumed.

fun eatWhile(pattern: Regex): Boolean

Continue matching characters that match the given regex. Return true if any characters were consumed.

Link copied to clipboard
fun eol(): Boolean

True if we are at the end of the line.

Link copied to clipboard

Get the indentation column of the current line.

Link copied to clipboard
fun match(pattern: Regex, consume: Boolean = true): MatchResult?

Match the input against the given regex (which should start with ^). If consume is true (default), advance past the matched text. Returns the match result if it matches at the current position, or null.

fun match(pattern: String, consume: Boolean = true, caseInsensitive: Boolean = false): Boolean

Match the input against the given string. If consume is true (default), advance past the matched text. When caseInsensitive is true, the match is case-insensitive.

Link copied to clipboard
fun next(): String?

Read the next character and advance pos, or return null at end.

Link copied to clipboard
fun peek(): String?

Get the next character without advancing, or null at end of line.

Link copied to clipboard

Move to directly before the given character, if found on the current line. Returns true if found.

Link copied to clipboard
fun skipToEnd()

Move to the end of the line.

Link copied to clipboard
fun sol(): Boolean

True if we are at the start of the line.