- Index
- »
- fan.markdown
- »
- Scanner
Scanner
@Js
class Scanner : Obj
Scanner is a utility class for parsing lines
Advance the scanner to the next character
Check if the specified char is next and advance the position
Peek at the previous codepoint
Consume characters while the given function returns true and return the number of characters consumed
Check if we have the specified content on the line and advance the position
Are there more characters to consume
For cases where the caller appends the result to a StrBuf, we could offer another method to avoid some unnecessary copying
Peek at the next code point
Peek at the next character without consuming it
Consume characters until the given function returns true, or the end-of-line is reached
Set the current position for the scanner
Consume as many ch in a row as possible and return the number consumed
Get the current position (current line, index into that line)
Scan until we find the given ch
Consume whitespace and return the number of whitespace characters consumed
Whitespace is defined as space, \t, \n, \u000B, \f, and \r
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.
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.
Bool hasNext()
Are there more characters to consume
new make(SourceLine[] lines, Int lineIndex, Int index)
new makeLine(SourceLine line)
new makeSourceLines(SourceLines sourceLines)
Int match(|Int->Bool| f)
Consume characters while the given function returns true and return the number of characters consumed.
Int matchMultiple(Int ch)
Consume as many ch in a row as possible and return the number consumed.
Void next()
Advance the scanner to the next character
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
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
Int peek()
Peek at the next character without consuming it
Int peekCodePoint()
Peek at the next code point
Int peekPrevCodePoint()
Peek at the previous codepoint
Position pos()
Get the current position (current line, index into that line)
Void setPos(Position pos)
Set the current position for the scanner
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.
Int whitespace()
Consume whitespace and return the number of whitespace characters consumed
Whitespace is defined as space, \t, \n, \u000B, \f, and \r