fst.common

Low level common data and functions that are not part of or aware of the FST class.

class NodeError(builtins.Exception):

General FST node error.

class astfield(typing.NamedTuple):

Name and optional index indicating a field location in an AST (or FST) node.

astfield(name: str, idx: int | None = None)

Create new instance of astfield(name, idx)

name: str

The actual field name, a la "body", "value", "orelse", etc...

idx: int | None

The index if the field is a list, else None.

def get( self, parent: ast.AST) -> ast.AST | ellipsis | int | float | complex | str | bytes | bool | None:

Get child node at this field in the given parent.

def get_default( self, parent: ast.AST, default: ast.AST | ellipsis | int | float | complex | str | bytes | bool | None = False) -> ast.AST | ellipsis | int | float | complex | str | bytes | bool | None:

Get child node at this field in the given parent. Return default if not found instead of raising AttributError or IndexError, False works well because not normally found in locations where AST nodes can reside in AST trees.

def set(self, parent: ast.AST, child: ast.AST) -> None:

Set child node at this field in the given parent.

class fstloc(typing.NamedTuple):

Full location span.

fstloc(ln: int, col: int, end_ln: int, end_col: int)

Create new instance of fstloc(ln, col, end_ln, end_col)

ln: int

Start line number.

col: int

Start column.

end_ln: int

End line number (inclusive).

end_col: int

End column (exclusive).

bln

Alias for ln.

bcol

Alias for col.

bend_ln

Alias for end_ln.

bend_col

Alias for end_col.

loc

To be able to use as FST.loc.

bloc

Alias for loc.

class fstlocn(typing.NamedTuple):

Version of fstloc with a namespace, used for pars().n.