class documentation
class TokenizerState: (source)
Known subclasses: tivars.tokenizer.state.IllegalState, tivars.tokenizer.state.Line, tivars.tokenizer.state.MaxMode, tivars.tokenizer.state.MinMode, tivars.tokenizer.state.SmartMode
Constructor: TokenizerState(mode, accept, length)
Base class for tokenizer states
Each state represents some encoding context which affects tokenization.
| Method | __init__ |
No summary |
| Method | munch |
Munch the input string and determine the resulting token, tokenizer timelines, and remainder of the string |
| Method | next |
Determines the next tokenizer timelines given a token |
| Class Variable | max |
The maximum number of tokens to emit before leaving this state |
| Instance Variable | accept |
Undocumented |
| Instance Variable | length |
Undocumented |
| Instance Variable | mode |
Undocumented |
def munch(self, string:
str, trie: TITokenTrie) -> tuple[ TIToken, str, list[ list[ TokenizerState]]]:
(source)
¶
Munch the input string and determine the resulting token, tokenizer timelines, and remainder of the string
| Parameters | |
string:str | The text string to tokenize |
trie:TITokenTrie | The TokenTrie object to use for tokenization |
| Returns | |
tuple[ | A tuple of the output Token, the remainder of string, and a list of timelines |
overridden in
tivars.tokenizer.state.Line, tivars.tokenizer.state.Name, tivars.tokenizer.state.SmartModeDetermines the next tokenizer timelines given a token
Each timeline that will branch from this one is returned as a list of states to add to a copy of the stack.
- If a list of states in a timeline is...
- empty, then the timeline is exiting the current state.
- length one, then the timeline's current state is being replaced by a new state.
- length two, then the timeline is entering a new state, able to exit back to this one.
| Parameters | |
token:TIToken | The current token |
remainder:str | The remaining string content to tokenize |
| Returns | |
list[ | A list of timelines (each a list of states) |
overridden in
tivars.tokenizer.state.ListName, tivars.tokenizer.state.ListName, tivars.tokenizer.state.ProgramName, tivars.tokenizer.state.ProgramNameThe maximum number of tokens to emit before leaving this state