Constructor
new TokenStack(array)
Parameters:
Name | Type | Description |
---|---|---|
array |
Array.<String> | list of tokens |
- Source:
Methods
(protected) consume(patternopt, options) → {String}
Consumes all consecutive tokens matching pattern. Throws if number of matched tokens not within range min-max.
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
pattern |
module:@citation-js/core.util.TokenStack~pattern |
<optional> |
/^[\s\S]$/ | pattern |
||||||||||||||||||||||||||||||
options |
Object |
Properties
|
- Source:
Throws:
-
-
Not enough tokens
- Type
- SyntaxError
-
-
-
Too many tokens
- Type
- SyntaxError
-
Returns:
consumed tokens
- Type
- String
(protected) consumeN(length) → {String}
Consume n tokens. Throws if not enough tokens left
Parameters:
Name | Type | Description |
---|---|---|
length |
Number | number of tokens |
- Source:
Throws:
-
Not enough tokens left
- Type
- SyntaxError
Returns:
consumed tokens
- Type
- String
(protected) consumeSequence(sequence) → {String}
Consume a pattern spanning multiple tokens ('sequence').
Parameters:
Name | Type | Description |
---|---|---|
sequence |
module:@citation-js/core.util.TokenStack~sequence | sequence |
- Source:
Throws:
-
Expected sequence, got tokens
- Type
- SyntaxError
Returns:
consumed tokens
- Type
- String
(protected) consumeToken(patternopt, options) → {String}
Consume a single token if possible, and throw if not.
Parameters:
Name | Type | Attributes | Default | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
pattern |
module:@citation-js/core.util.TokenStack~pattern |
<optional> |
/^[\s\S]$/ | pattern |
|||||||||||||||
options |
Object |
Properties
|
- Source:
Throws:
-
Unexpected token at index: Expected pattern, got token
- Type
- SyntaxError
Returns:
token
- Type
- String
(protected) consumeWhitespace(patternopt, options) → {String}
Consume a single token if possible, and throw if not.
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
pattern |
module:@citation-js/core.util.TokenStack~pattern |
<optional> |
/^\s$/ | whitespace pattern |
||||||||||
options |
Object |
Properties
|
- Source:
Throws:
-
Unexpected token at index: Expected whitespace, got token
- Type
- SyntaxError
Returns:
matched whitespace
- Type
- String
(protected) matches(pattern) → {Boolean}
Match current token against pattern.
Parameters:
Name | Type | Description |
---|---|---|
pattern |
module:@citation-js/core.util.TokenStack~pattern | pattern |
- Source:
Returns:
match
- Type
- Boolean
(protected) matchesSequence(pattern) → {Boolean}
Match current token against pattern.
Parameters:
Name | Type | Description |
---|---|---|
pattern |
module:@citation-js/core.util.TokenStack~sequence | pattern |
- Source:
Returns:
match
- Type
- Boolean
(protected) tokensLeft() → {Number}
Get a number representing the number of tokens that are left.
- Source:
Returns:
tokens left
- Type
- Number
(protected, static) getMatchCallback(pattern) → {module:@citation-js/core.util.TokenStack~match}
Get a single callback to match a token against one or several patterns.
Parameters:
Name | Type | Description |
---|---|---|
pattern |
module:@citation-js/core.util.TokenStack~pattern | pattern |
- Source:
Returns:
Match callback
(protected, static) getPatternText(pattern) → {String}
Get string representation of pattern.
Parameters:
Name | Type | Description |
---|---|---|
pattern |
String | RegExp | pattern |
- Source:
Returns:
string representation
- Type
- String
Type Definitions
match(token, index, stack) → {Boolean}
Parameters:
Name | Type | Description |
---|---|---|
token |
String | token |
index |
Number | token index |
stack |
Array.<String> | token stack |
- Source:
Returns:
match or not
- Type
- Boolean
pattern
TokenStack pattern
Type:
- String | RegExp | module:@citation-js/core.util.TokenStack~match | Array.<module:@citation-js/core.util.TokenStack~pattern>
- Source:
sequence
TokenStack pattern sequence
Type:
- String | Array.<module:@citation-js/core.util.TokenStack~pattern>
- Source:
tokenFilter(token) → {Boolean}
Parameters:
Name | Type | Description |
---|---|---|
token |
String | token |
- Source:
Returns:
keep or not
- Type
- Boolean
tokenMap(token) → {String}
Parameters:
Name | Type | Description |
---|---|---|
token |
String | token |
- Source:
Returns:
new token
- Type
- String