class

Scanner

@Js
class Scanner : Obj

Scanner is a utility class for parsing lines

constructors makeLine

makeSourceLines

make

methods next

Advance the scanner to the next character

nextCh

Check if the specified char is next and advance the position

peekPrevCodePoint

Peek at the previous codepoint

match

Consume characters while the given function returns true and return the number of characters consumed

nextStr

Check if we have the specified content on the line and advance the position

hasNext

Are there more characters to consume

source

For cases where the caller appends the result to a StrBuf, we could offer another method to avoid some unnecessary copying

peekCodePoint

Peek at the next code point

peek

Peek at the next character without consuming it

findMatch

Consume characters until the given function returns true, or the end-of-line is reached

setPos

Set the current position for the scanner

matchMultiple

Consume as many ch in a row as possible and return the number consumed

pos

Get the current position (current line, index into that line)

find

Scan until we find the given ch

whitespace

Consume whitespace and return the number of whitespace characters consumed

Whitespace is defined as space, \t, \n, \u000B, \f, and \r

find Int find(Int ch)

Scan until we find the given ch. Return the number of characters skipped, or -1 if we hit the end of the line.

findMatch Int findMatch(|Int->Bool| f)

Consume characters until the given function returns true, or the end-of-line is reached. Return the number of characters skipped, or -1 if we reach the end.

hasNext Bool hasNext()

Are there more characters to consume

make new make(SourceLine[] lines, Int lineIndex, Int index)

makeLine new makeLine(SourceLine line)

makeSourceLines new makeSourceLines(SourceLines sourceLines)

match Int match(|Int->Bool| f)

Consume characters while the given function returns true and return the number of characters consumed.

matchMultiple Int matchMultiple(Int ch)

Consume as many ch in a row as possible and return the number consumed.

next Void next()

Advance the scanner to the next character

nextCh Bool nextCh(Int ch)

Check if the specified char is next and advance the position.

ch: the char to check (including newline chars)

Return true if matched and position was advanced; false otherwise

nextStr Bool nextStr(Str content)

Check if we have the specified content on the line and advance the position. Note that if you want to match newline characters, use nextCh.

content: the text content to match on a single line (excluding newline)

Return true if matched and position was advanced; false otherwise

peek Int peek()

Peek at the next character without consuming it

peekCodePoint Int peekCodePoint()

Peek at the next code point

peekPrevCodePoint Int peekPrevCodePoint()

Peek at the previous codepoint

pos Position pos()

Get the current position (current line, index into that line)

setPos Void setPos(Position pos)

Set the current position for the scanner

source SourceLines source(Position begin, Position end)

For cases where the caller appends the result to a StrBuf, we could offer another method to avoid some unnecessary copying.

whitespace Int whitespace()

Consume whitespace and return the number of whitespace characters consumed

Whitespace is defined as space, \t, \n, \u000B, \f, and \r

Haxall 4.0.5 ∙ 24-Feb-2026 14:33 EST