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