Enter a search term above to see results...
On This Page
StringScanner
The StringScanner
class is a utility used internally by the TemplateCompiler to scan and parse template strings. It provides methods for moving through a string, matching patterns, and extracting relevant information during the template compilation process.
This library should not generally be used unless you plan on writing a custom string templating language.
Constructor
Syntax
Parameters
Name | Type | Description |
---|---|---|
input | string | The input string to be scanned |
Usage
Properties
input
The original input string.
pos
The current position in the input string.
Methods
matches
Checks if the rest of the input matches a given regular expression.
Syntax
Parameters
Name | Type | Description |
---|---|---|
regex | RegExp | The regular expression to test |
Returns
boolean
- true
if the rest of the input matches the regex, false
otherwise.
Usage
rest
Returns the rest of the input string from the current position.
Syntax
Returns
string
- The remaining unscanned portion of the input.
Usage
isEOF
Checks if the scanner has reached the end of the input.
Syntax
Returns
boolean
- true
if the scanner is at or past the end of the input, false
otherwise.
Usage
peek
Returns the character at the current position without advancing.
Syntax
Returns
string
- The character at the current position.
Usage
consume
Consumes and returns a portion of the input that matches a given pattern.
Syntax
Parameters
Name | Type | Description |
---|---|---|
pattern | string|RegExp | The pattern to match and consume |
Returns
string|null
- The matched string if found, otherwise null
.
Usage
consumeUntil
Consumes and returns the portion of the input up to a given pattern.
Syntax
Parameters
Name | Type | Description |
---|---|---|
pattern | string|RegExp | The pattern to stop consuming |
Returns
string
- The consumed string up to the pattern.
Usage
getContext
Returns context information about the current position in the input.
Syntax
Returns
Object
- An object containing context information.
Usage
fatal
Throws an error with the given message and current position information.
Syntax
Parameters
Name | Type | Description |
---|---|---|
msg | string | The error message |