finesse.script.containers module
Token and production containers for use in the tokenizer and parser.
- class finesse.script.containers.Addressable[source]
Bases:
objectMixin defining interface to retrieve strings containing script lines.
- script(bounds=None)[source]
Get the script in the interval [start, stop) defined by bounds.
Lines between start and stop with no tokens are yielded as empty lines. Gaps between the columns spanned by tokens on the same line are yielded as spaces.
Parameters
- bounds
KatBounds, optional Bounds within which to retrieve script. Defaults to the whole script.
Returns
strThe script.
- bounds
- script_lines(bounds)[source]
The script within bounds by line.
Parameters
- bounds
KatBounds The bounds to retrieve script between.
Returns
listLines within bounds. Where bounds starts or stops mid-way through a line, only the part of the line that falls within bounds is contained in the corresponding line.
- bounds
- property start[source]
Start coordinate.
- Getter:
The start
KatCoordinate.
- property stop[source]
Stop coordinate.
- Getter:
The stop
KatCoordinate.
- class finesse.script.containers.ArgumentContainer(arguments: List[TokenContainer])[source]
Bases:
TokenContainerMixin for containers that contain arguments.
- arguments: List[TokenContainer]
- class finesse.script.containers.BaseCustomToken(lineno: int, start_index: int, stop_index: int, type: str, raw_value: Any)[source]
Bases:
KatTokenA custom token.
- class finesse.script.containers.ExtraTokenContainer(extra: List[KatToken])[source]
Bases:
TokenContainerMixin for containers that contain extra tokens.
- class finesse.script.containers.KatArray(extra: List[KatToken], arguments: List[TokenContainer])[source]
Bases:
ArgumentContainer,ExtraTokenContainer,TokenContainerRepresents a kat script array.
- class finesse.script.containers.KatBooleanToken(lineno: int, start_index: int, stop_index: int, type: str, raw_value: Any)[source]
Bases:
BaseCustomTokenA boolean token.
- class finesse.script.containers.KatBounds(start: KatCoordinate, stop: KatCoordinate)[source]
Bases:
objectKat script start and stop bounds.
This represents a block of text in a kat script file.
- isempty()[source]
Whether the contents contained within the bounds is empty.
Returns
boolTrue if empty, False otherwise.
- lcontract(newstart)[source]
Contract start boundary.
Parameters
- newstart
KatCoordinate The new start coordinate.
Returns
KatBoundsThe contracted bounds.
Raises
- ValueError
If newstart is not >= current start coordinate.
- newstart
- lexpand(newstart)[source]
Expand start boundary.
Parameters
- newstart
KatCoordinate The new start coordinate.
Returns
KatBoundsThe expanded bounds.
Raises
- ValueError
If newstart is not <= current start coordinate.
- newstart
- rcontract(newstop)[source]
Contract stop boundary.
Parameters
- newstop
KatCoordinate The new stop coordinate.
Returns
KatBoundsThe contracted bounds.
Raises
- ValueError
If newstop is not <= current stop coordinate.
- newstop
- rexpand(newstop)[source]
Expand stop boundary.
Parameters
- newstop
KatCoordinate The new stop coordinate.
Returns
KatBoundsThe expanded bounds.
Raises
- ValueError
If newstop is not >= current stop coordinate.
- newstop
- start: KatCoordinate
- stop: KatCoordinate
- class finesse.script.containers.KatCoordinate(lineno: int, index: int)[source]
Bases:
objectKat script file coordinate supporting comparison operations.
- class finesse.script.containers.KatElement(directive: KatToken, extra: List[KatToken], arguments: List[TokenContainer], name: KatToken)[source]
Bases:
ArgumentContainer,ExtraTokenContainer,KatScriptItemRepresents a parsed element statement and any corresponding arguments.
- missing_argument_meta_token()[source]
A meta token at one position after that of the last argument token.
This is used to create error markers pointing to the location of missing parameters.
- class finesse.script.containers.KatExpression(extra: List[KatToken], arguments: List[TokenContainer], operator: KatToken)[source]
Bases:
ArgumentContainer,ExtraTokenContainer,TokenContainerRepresents a kat script expression.
- class finesse.script.containers.KatFile(text: str)[source]
Bases:
AddressableContainer with kat script lines (no concrete tokens).
- class finesse.script.containers.KatFixMeToken(lineno: int, start_index: int, stop_index: int, type: str, raw_value: Any)[source]
Bases:
BaseCustomTokenA “fixme” token used by the unparser to represent an invalid value.
- class finesse.script.containers.KatFunction(directive: KatToken, extra: List[KatToken], arguments: List[TokenContainer])[source]
Bases:
ArgumentContainer,ExtraTokenContainer,KatScriptItemRepresents a parsed kat function statement and any corresponding arguments.
- missing_argument_meta_token()[source]
A meta token at one position after that of the last argument token.
This is used to create error markers pointing to the location of missing parameters.
- class finesse.script.containers.KatGroupedExpression(extra: List[KatToken], arguments: List[TokenContainer])[source]
Bases:
ArgumentContainer,ExtraTokenContainer,TokenContainerRepresents a kat script expression group, i.e. (<expression>).
- class finesse.script.containers.KatKwarg(key: KatToken, equals: KatToken, value: KatToken | KatFunction | KatExpression | KatGroupedExpression | KatArray)[source]
Bases:
TokenContainerRepresents a kat argument containing a key, value and ‘=’.
- value: KatToken | KatFunction | KatExpression | KatGroupedExpression | KatArray
- class finesse.script.containers.KatMetaToken(lineno: int, start_index: int, stop_index: int, type: str)[source]
Bases:
TokenMixinA token that may not map to a real token.
Meta tokens are employed by
KatTokenizerwhen converting whitespace and newline tokens used as delimiters into DELIMITER. The use of a single meta token for DELIMITER in this case simplifies the parser rules.By definition, the value of a meta token does not matter so the class doesn’t support having one. Similarly, to help prevent bugs, an exception is raised if the token is attempted to be displayed.
- class finesse.script.containers.KatNoneToken(lineno: int, start_index: int, stop_index: int, type: str, raw_value: Any)[source]
Bases:
BaseCustomTokenA null token.
- class finesse.script.containers.KatNumberToken(lineno: int, start_index: int, stop_index: int, type: str, raw_value: Any)[source]
Bases:
BaseCustomTokenA number token.
- SI_NUMBER_PATTERN = re.compile('.*[pnumkMGT]$')
- class finesse.script.containers.KatNumericalArray(extra: List[KatToken], arguments: List[TokenContainer])[source]
Bases:
KatArrayRepresents a kat script numerical array.
- class finesse.script.containers.KatScript(extra: List[KatToken], arguments: List[TokenContainer])[source]
Bases:
ArgumentContainer,ExtraTokenContainer,TokenContainerRepresents a kat script.
- class finesse.script.containers.KatScriptItem(directive: KatToken)[source]
Bases:
TokenContainerRepresents a top level kat script item.
- abstractmethod missing_argument_meta_token()[source]
A meta token at one position after that of the last argument token.
This is used to create error markers pointing to the location of missing parameters.
- class finesse.script.containers.KatStringToken(lineno: int, start_index: int, stop_index: int, type: str, raw_value: Any)[source]
Bases:
BaseCustomTokenA string token.
- class finesse.script.containers.KatToken(lineno: int, start_index: int, stop_index: int, type: str, raw_value: Any)[source]
Bases:
TokenMixinA real token with the corresponding text’s location, type and value.
- to_meta()[source]
Convert token to a meta token.
Returns
KatMetaTokenThe current token, as a meta token.
- class finesse.script.containers.KatWhitespaceToken(lineno: int, start_index: int, stop_index: int, type: str, raw_value: Any)[source]
Bases:
BaseCustomTokenA whitespace token.
- class finesse.script.containers.TokenContainer[source]
Bases:
AddressableContainer with concrete token instances.
- property first_token[source]
First container token by coordinate.
- Getter:
first
KatTokenwithin this container.
- property last_token[source]
Last container token by coordinate.
- Getter:
last
KatTokenwithin this container.
- class finesse.script.containers.TokenMixin(lineno: int, start_index: int, stop_index: int, type: str)[source]
Bases:
TokenContainerA class that provides functionality shared by
KatMetaTokenandKatToken.Injected this way to prevent
KatTokeninheriting fromKatMetaToken, which would be confusing since they are both tokens, but one represent real tokens while the other does not.