CharacterStream

Handles reading UTF-32 characters from JavaScript string, with lookahead ability

Constructor

new CharacterStream(pattern)

Create a new streamer object

Parameters:
NameTypeDescription
patternstring

the pattern string to iterate over

Members

buffer

Buffered characters from the stream

col_utf16

Current column number in UTF-16 encoding

col_utf32

Current column number, in UTF-32 encoding

line

Current line number, where lines are given by '\n' character

pattern

Pattern we're iterating over for this stream

stream

Character stream generator

Methods

buffer(nopt) → {boolean}

Ensure at least n>0 characters are buffered if possible

Parameters:
NameTypeAttributesDefaultDescription
nnumber<optional>
1

number of characters to buffer

Returns:

true if we could fulfill buffer request

Type: 
boolean

discard(nopt) → {boolean}

Discard n>0 characters; throws if there are not n characters

Parameters:
NameTypeAttributesDefaultDescription
nnumber<optional>
1

number of characters to discard

Returns:

true if we could fulfill discard request

Type: 
boolean

error(expected, discardopt)

Throw a syntax error at this point in the stream

Parameters:
NameTypeAttributesDefaultDescription
expectedstring

message indicating what was expected; prefix/suffix is generated

discardnumber<optional>
0

how many buffered characters were okay; the next character (possibly buffered) after those discarded is the one that triggered the error

peek(nopt) → (nullable) {string}

Fetch n>0 characters as a string

Parameters:
NameTypeAttributesDefaultDescription
nnumber<optional>
1

number of characters to peek

Returns:

the peeked string; null if we can't get n characters

Type: 
string

pop(nopt) → (nullable) {string}

Fetch n>0 characters and discard them

Parameters:
NameTypeAttributesDefaultDescription
nnumber<optional>
1

number of characters to pop

Returns:

the popped string; null if we can't get n characters

Type: 
string