Notation¶
Scoped notation, mixfix enforestation, hygienic expansion by sets of scopes, quotation elaboration, and printing. The notation reference describes the surface, and the semantics states the rules.
notation
¶
Scoped notation, mixfix operators, and typed quotation.
A notation declaration gives mixfix productions over the terms of a
binding signature; open notation activates notations for the rest of a
module; a quotation [| ... |] is read against the active notations'
precedence DAG, expanded hygienically by sets of scopes into the de Bruijn
term it means, and elaborated to the constructor tree (or pattern) of that
term. Terms print back through the active notations, on the host and in the
generated Show instances; a quotation annotated with a quoted-syntax
family of the meta phase quotes QVR itself.
CODE_FAMILIES
module-attribute
¶
The quoted-syntax families a code quotation may be annotated with.
CONTEXT_TURNSTILE
module-attribute
¶
The token that ends a quotation's context, as in [| x, y ⊢ x y |].
NOTATION_CODE
module-attribute
¶
The diagnostic code of every notation and quotation refusal.
ReferenceResolver
module-attribute
¶
Resolves an open notation target (as written, with its line and
column) to the flat names of the notations it activates.
SortKey
¶
A signature and one of its sorts, or None when not yet known.
SyntaxValue
¶
SyntaxValue = Model | tuple[SyntaxValue, ...] | str | int | float | bool | None
A syntax node, a tuple of them, or a leaf of one.
Associativity
¶
How an infix production chains with itself and its level.
Fixity
¶
Where a production's outer operand holes are: none, last, first, or both.
Located
¶
Located = TokenWord | TokenName | TokenLiteral | TokenAntiquote | TokenGroup
Every token kind; each has a span and a location.
NotationProgram
¶
NotationProgram(notations: Mapping[str, NotationDecl], syntaxes: Mapping[str, SyntaxInfo], files: Mapping[str, str])
The notations and signatures of a program, and the tables they form.
| PARAMETER | DESCRIPTION |
|---|---|
notations
|
Every notation declaration, by flat name.
TYPE:
|
syntaxes
|
Every binding signature, by flat name.
TYPE:
|
files
|
The file each notation is declared in.
TYPE:
|
Source code in src/quivers/dsl/notation/elaborate.py
table
¶
table(active: tuple[str, ...], *, file: str, line: int, col: int) -> NotationTable
The table of a set of active notations.
| PARAMETER | DESCRIPTION |
|---|---|
active
|
The flat names of the active notations, in activation order.
TYPE:
|
file
|
The file of the point that needs it.
TYPE:
|
line
|
That point's location.
TYPE:
|
col
|
That point's location.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NotationTable
|
The table, built once per set. |
| RAISES | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
If no notation is active, or the active notations do not form a table. |
Source code in src/quivers/dsl/notation/elaborate.py
sort_of_type
¶
sort_of_type(type_expr: QiecTypeExpr) -> SortKey
The signature sort a type names, if it names one.
| PARAMETER | DESCRIPTION |
|---|---|
type_expr
|
A type.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SortKey
|
|
Source code in src/quivers/dsl/notation/elaborate.py
Quoted
didactic-model
¶
Quoted(*, core: CoreNode, syntax: str = '', sort: str = '', context: tuple[str, ...] = (), reading: Reading | None = None)
Bases: Model
A quotation read and expanded.
| PARAMETER | DESCRIPTION |
|---|---|
core
|
Its meaning.
TYPE:
|
syntax
|
The flat name of its signature, empty for a bare antiquotation.
TYPE:
|
sort
|
Its sort, empty for a bare antiquotation.
TYPE:
|
context
|
The names of its free variables, outermost first.
TYPE:
|
reading
|
How it was read, for tooling.
TYPE:
|
ArgumentAbstraction
didactic-model
¶
ArgumentAbstraction(*, names: tuple[TokenName, ...], body: ParseNode, kind: Literal['argument_abstraction'] = 'argument_abstraction')
Bases: ParseArgument
x y. body: an argument that binds variables.
| PARAMETER | DESCRIPTION |
|---|---|
names
|
The bound names.
TYPE:
|
body
|
The body.
TYPE:
|
ArgumentLiteral
didactic-model
¶
ArgumentLiteral(*, literal: TokenLiteral, kind: Literal['argument_literal'] = 'argument_literal')
ArgumentTerm
didactic-model
¶
ArgumentTerm(*, node: ParseNode, kind: Literal['argument_term'] = 'argument_term')
Bases: ParseArgument
An argument that binds nothing.
| PARAMETER | DESCRIPTION |
|---|---|
node
|
The argument.
TYPE:
|
FillBinder
didactic-model
¶
FillBinder(*, name: TokenName, kind: Literal['fill_binder'] = 'fill_binder')
FillData
didactic-model
¶
FillData(*, literal: TokenLiteral, kind: Literal['fill_data'] = 'fill_data')
Bases: ParseFill
A data hole's literal.
| PARAMETER | DESCRIPTION |
|---|---|
literal
|
The literal.
TYPE:
|
FillOperand
didactic-model
¶
FillOperand(*, node: ParseNode, kind: Literal['fill_operand'] = 'fill_operand')
FillToken
didactic-model
¶
FillToken(*, token: TokenWord, kind: Literal['fill_token'] = 'fill_token')
ParseAntiquote
didactic-model
¶
ParseAntiquote(*, token: TokenAntiquote, kind: Literal['parse_antiquote'] = 'parse_antiquote')
Bases: ParseNode
An antiquotation.
| PARAMETER | DESCRIPTION |
|---|---|
token
|
The antiquotation.
TYPE:
|
ParseArgument
didactic-model
¶
Bases: TaggedUnion
One argument of a constructor application.
ParseConstructor
didactic-model
¶
ParseConstructor(*, op: str, args: tuple[ParseArgument, ...] = (), token: TokenName, kind: Literal['parse_constructor'] = 'parse_constructor')
Bases: ParseNode
A constructor application Op(...) written in a quotation.
| PARAMETER | DESCRIPTION |
|---|---|
op
|
The constructor's flat name.
TYPE:
|
args
|
Its arguments.
TYPE:
|
token
|
The constructor's name as written.
TYPE:
|
ParseName
didactic-model
¶
ParseName(*, token: TokenName, kind: Literal['parse_name'] = 'parse_name')
ParseUse
didactic-model
¶
ParseUse(*, production: str, fills: tuple[ParseFill, ...] = (), line: int = 0, col: int = 0, kind: Literal['parse_use'] = 'parse_use')
Bases: ParseNode
A production applied to its holes' fills.
| PARAMETER | DESCRIPTION |
|---|---|
production
|
The production's qualified name.
TYPE:
|
fills
|
One fill per hole and one
TYPE:
|
line
|
Where the use starts.
TYPE:
|
col
|
Where the use starts.
TYPE:
|
Reading
didactic-model
¶
Reading(*, node: ParseNode, sort: str = '', syntax: str = '')
Bases: Model
A complete reading of a quotation.
| PARAMETER | DESCRIPTION |
|---|---|
node
|
The reading.
TYPE:
|
sort
|
The sort it builds, or empty when only its context decides (a name or an antiquotation).
TYPE:
|
syntax
|
The signature of that sort, or empty.
TYPE:
|
CoreAntiquote
didactic-model
¶
CoreAntiquote(*, antiquote: NotationAntiquote, syntax: str, sort: str, shifts: tuple[CoreShift, ...] = (), depth: int = 0, kind: Literal['core_antiquote'] = 'core_antiquote')
Bases: CoreNode
A spliced host value, weakened past the binders its author cannot see.
| PARAMETER | DESCRIPTION |
|---|---|
antiquote
|
The antiquotation.
TYPE:
|
syntax
|
The signature of the expected sort.
TYPE:
|
sort
|
The expected sort.
TYPE:
|
shifts
|
The weakenings, innermost binder first.
TYPE:
|
depth
|
How many binders of the quotation enclose it.
TYPE:
|
CoreApply
didactic-model
¶
CoreApply(*, op: str, syntax: str, args: tuple[CoreNode, ...] = (), kind: Literal['core_apply'] = 'core_apply')
CoreBinding
didactic-model
¶
CoreBinding(*, names: tuple[str, ...], body: CoreNode, kind: Literal['core_binding'] = 'core_binding')
CoreLeaf
didactic-model
¶
CoreLeaf(*, text: str = '', number: int = 0, is_text: bool = True, kind: Literal['core_leaf'] = 'core_leaf')
Bases: CoreNode
A data literal.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Its value, for a string.
TYPE:
|
number
|
Its value, for an integer.
TYPE:
|
is_text
|
Whether it is a string.
TYPE:
|
CoreNode
didactic-model
¶
Bases: TaggedUnion
A quotation's meaning: a de Bruijn term that may splice host values.
CoreShift
didactic-model
¶
Bases: Model
Weakening a spliced term past one binder its author cannot see.
| PARAMETER | DESCRIPTION |
|---|---|
cutoff
|
Variables below the cutoff keep their index.
TYPE:
|
amount
|
What the others gain.
TYPE:
|
CoreVariable
didactic-model
¶
CoreVariable(*, index: int, syntax: str, sort: str, kind: Literal['core_variable'] = 'core_variable')
Bases: CoreNode
A variable by de Bruijn index.
| PARAMETER | DESCRIPTION |
|---|---|
index
|
The index.
TYPE:
|
syntax
|
The signature's flat name.
TYPE:
|
sort
|
The variable's sort.
TYPE:
|
Syntax
didactic-model
¶
Bases: TaggedUnion
Expanded syntax whose names carry sets of scopes.
SyntaxAbstraction
didactic-model
¶
SyntaxAbstraction(*, names: tuple[SyntaxName, ...], body: Syntax, kind: Literal['syntax_abstraction'] = 'syntax_abstraction')
Bases: Syntax
Names bound over a body: a binding argument.
| PARAMETER | DESCRIPTION |
|---|---|
names
|
The binders, outermost first.
TYPE:
|
body
|
The body.
TYPE:
|
SyntaxAntiquote
didactic-model
¶
SyntaxAntiquote(*, antiquote: NotationAntiquote, scopes: tuple[int, ...], kind: Literal['syntax_antiquote'] = 'syntax_antiquote')
Bases: Syntax
An antiquotation and the scopes of where its author wrote it.
| PARAMETER | DESCRIPTION |
|---|---|
antiquote
|
The antiquotation.
TYPE:
|
scopes
|
Its scopes.
TYPE:
|
SyntaxApply
didactic-model
¶
SyntaxApply(*, op: str, args: tuple[Syntax, ...] = (), line: int = 0, col: int = 0, kind: Literal['syntax_apply'] = 'syntax_apply')
SyntaxLeaf
didactic-model
¶
SyntaxLeaf(*, text: str = '', number: int = 0, is_text: bool = True, line: int = 0, col: int = 0, kind: Literal['syntax_leaf'] = 'syntax_leaf')
Bases: Syntax
A data literal.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
Its value, for a string.
TYPE:
|
number
|
Its value, for an integer.
TYPE:
|
is_text
|
Whether it is a string.
TYPE:
|
line
|
Where it is written.
TYPE:
|
col
|
Where it is written.
TYPE:
|
SyntaxName
didactic-model
¶
SyntaxName(*, text: str, scopes: tuple[int, ...], line: int = 0, col: int = 0, kind: Literal['syntax_name'] = 'syntax_name')
Bases: Syntax
A name and its scopes.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The name.
TYPE:
|
scopes
|
Its scopes, sorted.
TYPE:
|
line
|
Where it is written (for a template name, where the production is used).
TYPE:
|
col
|
Where it is written (for a template name, where the production is used).
TYPE:
|
ModuleNotations
¶
ModuleNotations(checked: CheckedModule, interfaces: dict[ModuleIdentity, ModuleInterface], root: ModuleIdentity)
Resolve notation references in one module of a graph.
| PARAMETER | DESCRIPTION |
|---|---|
checked
|
The module, resolved against its dependencies.
TYPE:
|
interfaces
|
Every module's interface.
TYPE:
|
root
|
The program's root module.
TYPE:
|
Source code in src/quivers/dsl/notation/scoping.py
flat
¶
flat(module: ModuleIdentity, name: str) -> str
The flat-program name of a module's declaration.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The declaring module.
TYPE:
|
name
|
The name in it.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The bare name in the root module, |
Source code in src/quivers/dsl/notation/scoping.py
exported
¶
exported(module: ModuleIdentity) -> tuple[str, ...]
The flat names of the notations a module exports.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
In declaration order. |
Source code in src/quivers/dsl/notation/scoping.py
resolve
¶
The notations a reference names.
| PARAMETER | DESCRIPTION |
|---|---|
target
|
A notation (bare, or qualified by an import) or a module.
TYPE:
|
line
|
Where it is written.
TYPE:
|
col
|
Where it is written.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The flat names of the notations. |
| RAISES | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
If the reference names no notation and no imported module. |
Source code in src/quivers/dsl/notation/scoping.py
relation
¶
relation(notation: NotationDecl, relation: NotationRelation) -> NotationRelation
A relation with its other notations' productions named by flat name.
| PARAMETER | DESCRIPTION |
|---|---|
notation
|
The declaring notation.
TYPE:
|
relation
|
One of its relations.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NotationRelation
|
The relation; a bare production name stays bare (a production of the declaring notation). |
| RAISES | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
If a qualified production's notation does not resolve to one notation. |
Source code in src/quivers/dsl/notation/scoping.py
Level
didactic-model
¶
Bases: Model
One precedence level: productions that relate as one.
| PARAMETER | DESCRIPTION |
|---|---|
members
|
The qualified names of its productions.
TYPE:
|
tighter
|
The levels that bind strictly tighter, transitively.
TYPE:
|
NotationTable
didactic-model
¶
NotationTable(*, notations: tuple[str, ...] = (), productions: tuple[Production, ...] = (), levels: tuple[Level, ...] = (), level_of: tuple[int, ...] = (), syntaxes: tuple[SyntaxInfo, ...] = ())
Bases: Model
The active notations of one point of a module.
| PARAMETER | DESCRIPTION |
|---|---|
notations
|
The flat names of the active notations, in activation order.
TYPE:
|
productions
|
Their productions.
TYPE:
|
levels
|
The precedence levels.
TYPE:
|
level_of
|
Each production's level, by position in
TYPE:
|
syntaxes
|
The signatures the notations are for.
TYPE:
|
tighter_sets
cached
property
¶
Each level's strictly tighter levels.
| RETURNS | DESCRIPTION |
|---|---|
tuple[frozenset[int], ...]
|
By level. |
tokens
cached
property
¶
Every token of the active productions.
| RETURNS | DESCRIPTION |
|---|---|
frozenset[str]
|
The tokens. |
symbol_tokens
cached
property
¶
The symbol tokens, longest first, for maximal munch.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The tokens that are not names. |
reading_symbols
cached
property
¶
The symbol tokens a quotation's symbol runs split into.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The active symbol tokens and the punctuation of constructor
application, |
word_tokens
cached
property
¶
The tokens spelled like names, which quotations read as tokens.
| RETURNS | DESCRIPTION |
|---|---|
frozenset[str]
|
The name-like tokens. |
constructors
cached
property
¶
constructors: dict[str, tuple[SyntaxInfo, str]]
Every constructor of the active signatures with its signature.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, tuple[SyntaxInfo, str]]
|
By flat constructor name: the signature and the constructor's codomain. |
level
¶
level(production: Production) -> int
The precedence level of a production.
| PARAMETER | DESCRIPTION |
|---|---|
production
|
An active production.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
Its level. |
Source code in src/quivers/dsl/notation/table.py
unrelated
¶
Whether two levels are distinct and ordered neither way.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
Two levels.
TYPE:
|
right
|
Two levels.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True when no relation orders them. |
syntax
¶
syntax(name: str) -> SyntaxInfo
One active signature by flat name.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The signature.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SyntaxInfo
|
It. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If no active notation is for it. |
Source code in src/quivers/dsl/notation/table.py
productions_for
¶
productions_for(syntax: str, sort: str) -> tuple[Production, ...]
The productions that build a sort of a signature.
| PARAMETER | DESCRIPTION |
|---|---|
syntax
|
The signature.
TYPE:
|
sort
|
The sort.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Production, ...]
|
In activation order. |
Source code in src/quivers/dsl/notation/table.py
Production
didactic-model
¶
Production(*, notation: str, name: str, syntax: str, items: tuple[ShapeItem, ...], template: TemplateNode, sort: str, assoc: Associativity = 'none', order: int = 0, line: int = 0, col: int = 0, file: str = '')
Bases: Model
A production read against its signature.
| PARAMETER | DESCRIPTION |
|---|---|
notation
|
The flat name of the notation that declares it.
TYPE:
|
name
|
Its name in the notation.
TYPE:
|
syntax
|
The flat name of the signature its template is a term of.
TYPE:
|
items
|
Its shape.
TYPE:
|
template
|
The term it stands for.
TYPE:
|
sort
|
The sort the template builds.
TYPE:
|
assoc
|
Its associativity.
TYPE:
|
order
|
Its position among the active productions, which breaks ties when printing.
TYPE:
|
line
|
Where it is declared.
TYPE:
|
col
|
Where it is declared.
TYPE:
|
file
|
The file it is declared in.
TYPE:
|
qualified
property
¶
The production's name qualified by its notation.
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
label
property
¶
The production for messages: its name, notation, and module.
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
elements
property
¶
elements: tuple[ShapeItem, ...]
The items that take part in reading: every item but printing space.
| RETURNS | DESCRIPTION |
|---|---|
tuple[ShapeItem, ...]
|
Tokens and holes, in order. |
fixity
property
¶
fixity: Fixity
Where the production's outer operand holes are.
A binder or data hole reads one token, so it delimits like a token does.
| RETURNS | DESCRIPTION |
|---|---|
Fixity
|
|
binder_holes
property
¶
The names of the binder holes.
| RETURNS | DESCRIPTION |
|---|---|
frozenset[str]
|
The holes an abstraction of the template binds. |
shape_key
property
¶
What two productions that read the same text share.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The tokens and hole roles of the shape, with the result sort. |
hole
¶
hole(name: str) -> ShapeItem
One hole of the shape.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The hole's name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ShapeItem
|
The hole. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the shape has no hole of that name. |
Source code in src/quivers/dsl/notation/table.py
ShapeItem
didactic-model
¶
ShapeItem(*, role: ShapeRole, text: str, before: str = '', after: str = '', sort: str = '', line: int = 0, col: int = 0)
Bases: Model
One item of a production's shape.
| PARAMETER | DESCRIPTION |
|---|---|
role
|
A token, a run of printing space, an operand hole, a binder hole, or a data hole.
TYPE:
|
text
|
The token without its printing space, the space itself, or the hole's name.
TYPE:
|
before
|
Printing space written before a token.
TYPE:
|
after
|
Printing space written after a token.
TYPE:
|
sort
|
A hole's sort: the operand's object sort, the bound variable's sort, or the data sort.
TYPE:
|
line
|
Where the item is written.
TYPE:
|
col
|
Where the item is written.
TYPE:
|
SyntaxInfo
didactic-model
¶
SyntaxInfo(*, name: str, signature: Signature)
Bases: Model
A binding signature as notation reads it.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The signature's flat name.
TYPE:
|
signature
|
The signature.
TYPE:
|
is_object
¶
Whether a sort is an object sort, whose terms notation writes.
| PARAMETER | DESCRIPTION |
|---|---|
sort
|
The sort.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True for an |
Source code in src/quivers/dsl/notation/table.py
TemplateAbstraction
didactic-model
¶
TemplateAbstraction(*, names: tuple[str, ...], body: TemplateNode, kind: Literal['template_abstraction'] = 'template_abstraction')
Bases: TemplateNode
x y. body: the argument of a binding position.
| PARAMETER | DESCRIPTION |
|---|---|
names
|
The bound names: binder holes, or names the template binds itself.
TYPE:
|
body
|
The body.
TYPE:
|
TemplateApply
didactic-model
¶
TemplateApply(*, op: str, args: tuple[TemplateNode, ...] = (), kind: Literal['template_apply'] = 'template_apply')
Bases: TemplateNode
A constructor applied to arguments.
| PARAMETER | DESCRIPTION |
|---|---|
op
|
The constructor's flat name.
TYPE:
|
args
|
Its arguments; an argument that binds is a
TYPE:
|
TemplateHole
didactic-model
¶
TemplateLeaf
didactic-model
¶
TemplateLeaf(*, text: str = '', number: int = 0, is_text: bool = True, kind: Literal['template_leaf'] = 'template_leaf')
Bases: TemplateNode
A data literal of the template.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The literal's value, for a string.
TYPE:
|
number
|
The literal's value, for an integer.
TYPE:
|
is_text
|
Whether the literal is a string.
TYPE:
|
TemplateNode
didactic-model
¶
Bases: TaggedUnion
A production's template: a term of the signature over its holes.
TemplateVariable
didactic-model
¶
Bases: TemplateNode
A reference to a variable a template abstraction binds.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The variable's name in the template; when it is a binder hole, the variable is the one the user names there.
TYPE:
|
QuotationText
didactic-model
¶
ReadToken
didactic-model
¶
Bases: TaggedUnion
One token of a quotation, as the mixfix reader sees it.
TokenAntiquote
didactic-model
¶
TokenAntiquote(*, antiquote: NotationAntiquote, start: int = 0, end: int = 0, line: int = 0, col: int = 0, kind: Literal['token_antiquote'] = 'token_antiquote')
Bases: ReadToken
An antiquotation.
| PARAMETER | DESCRIPTION |
|---|---|
antiquote
|
The antiquotation as written.
TYPE:
|
start
|
Its byte span.
TYPE:
|
end
|
Its byte span.
TYPE:
|
line
|
Its location.
TYPE:
|
col
|
Its location.
TYPE:
|
TokenGroup
didactic-model
¶
TokenGroup(*, items: tuple[ReadToken, ...] = (), start: int = 0, end: int = 0, line: int = 0, col: int = 0, kind: Literal['token_group'] = 'token_group')
TokenLiteral
didactic-model
¶
TokenLiteral(*, text: str, string: str = '', number: int = 0, is_text: bool = True, start: int = 0, end: int = 0, line: int = 0, col: int = 0, kind: Literal['token_literal'] = 'token_literal')
Bases: ReadToken
A string or integer literal, the value of a data hole.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The literal as written.
TYPE:
|
string
|
Its value, for a string.
TYPE:
|
number
|
Its value, for an integer.
TYPE:
|
is_text
|
Whether it is a string.
TYPE:
|
start
|
Its byte span.
TYPE:
|
end
|
Its byte span.
TYPE:
|
line
|
Its location.
TYPE:
|
col
|
Its location.
TYPE:
|
TokenName
didactic-model
¶
TokenName(*, text: str, start: int = 0, end: int = 0, line: int = 0, col: int = 0, kind: Literal['token_name'] = 'token_name')
Bases: ReadToken
A name: a variable, a constructor, or a binder.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The name.
TYPE:
|
start
|
Its byte span.
TYPE:
|
end
|
Its byte span.
TYPE:
|
line
|
Its location.
TYPE:
|
col
|
Its location.
TYPE:
|
TokenWord
didactic-model
¶
TokenWord(*, text: str, start: int = 0, end: int = 0, line: int = 0, col: int = 0, kind: Literal['token_word'] = 'token_word')
Bases: ReadToken
A token of an active notation.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The token.
TYPE:
|
start
|
Its byte span.
TYPE:
|
end
|
Its byte span.
TYPE:
|
line
|
Its location.
TYPE:
|
col
|
Its location.
TYPE:
|
code_quotation
¶
code_quotation(quotation: QiecQuotation, family: str, *, file: str) -> LetExprNode
The quoted-syntax constructor tree of a code quotation.
| PARAMETER | DESCRIPTION |
|---|---|
quotation
|
The quotation.
TYPE:
|
family
|
TYPE:
|
file
|
The file, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LetExprNode
|
The constructor tree, antiquotations in place. |
| RAISES | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
If the contents do not parse as that category, or use a form the quoted-syntax families do not represent. |
Source code in src/quivers/dsl/notation/code.py
quoted_text
¶
quoted_text(quotation: QiecQuotation, *, file: str) -> tuple[str, list[LetExprNode]]
A code quotation's contents as source text, antiquotations as names.
| PARAMETER | DESCRIPTION |
|---|---|
quotation
|
The quotation.
TYPE:
|
file
|
The file, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, list[LetExprNode]]
|
The contents, dedented (a multi-line quotation's first line, after
|
| RAISES | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
If a multi-line quotation has content on the line of |
Source code in src/quivers/dsl/notation/code.py
core_pattern
¶
core_pattern(core: CoreNode, *, file: str, line: int, col: int) -> QiecPattern
The surface pattern of a meaning.
| PARAMETER | DESCRIPTION |
|---|---|
core
|
The meaning of a pattern quotation.
TYPE:
|
file
|
The file, for diagnostics.
TYPE:
|
line
|
The quotation's location.
TYPE:
|
col
|
The quotation's location.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QiecPattern
|
A constructor pattern; a variable matches the sort's variable
constructor at its index, and |
| RAISES | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
If an antiquotation lies under a binder its author cannot see, so the matched subterm would have to be strengthened. |
Source code in src/quivers/dsl/notation/elaborate.py
core_value
¶
core_value(core: CoreNode, hoist: Hoist, *, line: int, col: int) -> LetExprNode
The surface value of a meaning.
| PARAMETER | DESCRIPTION |
|---|---|
core
|
The meaning.
TYPE:
|
hoist
|
Binds a splice that must be weakened.
TYPE:
|
line
|
The quotation's location, given to the nodes it becomes.
TYPE:
|
col
|
The quotation's location, given to the nodes it becomes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LetExprNode
|
A constructor tree over the signature's families. |
Source code in src/quivers/dsl/notation/elaborate.py
describe_active
¶
The active notations for messages.
| PARAMETER | DESCRIPTION |
|---|---|
active
|
Flat notation names.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Each notation with its module. |
Source code in src/quivers/dsl/notation/elaborate.py
expand_notation
¶
Elaborate every quotation of a module and drop its notation statements.
A quotation whose module scoping already named its active notations
uses them; any other reads the notations the open notation
statements before it activate, in this module.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
A parsed (or flat) module.
TYPE:
|
file_path
|
Its file, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Module
|
The module with every quotation replaced by the value or pattern it
stands for, and without notation declarations or |
| RAISES | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
If an |
Source code in src/quivers/dsl/notation/elaborate.py
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 | |
has_notation_surface
¶
has_notation_surface(module: Module) -> bool
Whether a module declares, opens, or quotes notation.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
A parsed module.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True when some statement or test holds notation surface. |
Source code in src/quivers/dsl/notation/elaborate.py
name_spellings
¶
name_spellings(module: Module) -> tuple[NameSpelling, ...]
The root module's spellings of imported names a flat program records.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
A flat program.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[NameSpelling, ...]
|
Its spellings, or none for a program read from one module. |
Source code in src/quivers/dsl/notation/elaborate.py
notation_program
¶
notation_program(statements: Sequence[Statement], files: Mapping[str, str] | None = None, *, file: str) -> NotationProgram
The notations and signatures a program declares.
| PARAMETER | DESCRIPTION |
|---|---|
statements
|
The program's statements.
TYPE:
|
files
|
The file each notation is declared in;
TYPE:
|
file
|
The program's file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NotationProgram
|
Its notations and signatures. |
Source code in src/quivers/dsl/notation/elaborate.py
parse_quotation
¶
parse_quotation(text: str) -> QiecQuotation
Read the text of a quotation's contents into its token tree.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
What stands between
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QiecQuotation
|
The quotation, unscoped. |
| RAISES | DESCRIPTION |
|---|---|
ParseError
|
If the text is not a token tree. |
Source code in src/quivers/dsl/notation/elaborate.py
quote
¶
quote(program: NotationProgram, active: tuple[str, ...], text: str, *, sort: SortKey = None, file: str = '<quotation>') -> Quoted
Read and expand the contents of a quotation.
| PARAMETER | DESCRIPTION |
|---|---|
program
|
The program's notations and signatures.
TYPE:
|
active
|
The flat names of the active notations.
TYPE:
|
text
|
The quotation's contents.
TYPE:
|
sort
|
The sort it must build, if known.
TYPE:
|
file
|
The file, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Quoted
|
Its meaning and sort. |
Source code in src/quivers/dsl/notation/elaborate.py
read_quoted
¶
read_quoted(quotation: QiecQuotation | QiecQuotationPattern, program: NotationProgram, active: tuple[str, ...], expected: SortKey, *, file: str) -> Quoted
Read and expand one quotation.
| PARAMETER | DESCRIPTION |
|---|---|
quotation
|
The quotation.
TYPE:
|
program
|
The program's notations.
TYPE:
|
active
|
The notations active where it stands.
TYPE:
|
expected
|
The sort an annotation gives it, if any.
TYPE:
|
file
|
The file, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Quoted
|
Its meaning and sort. |
| RAISES | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
If it does not read, reads two ways, does not resolve, or its sort is decided by nothing. |
Source code in src/quivers/dsl/notation/elaborate.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
render_core
¶
render_core(core: CoreNode) -> str
The surface text of a quotation's meaning.
| PARAMETER | DESCRIPTION |
|---|---|
core
|
The meaning.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Its constructor tree, each variable written |
Source code in src/quivers/dsl/notation/elaborate.py
scope_local_notation
¶
Record on each quotation the notations its own module has opened.
A module read alone (no module graph) opens only its own notations;
each quotation records the ones open notation statements before it
activate, as module scoping does for a graph.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
A parsed module.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Module
|
The module, every quotation scoped. |
Source code in src/quivers/dsl/notation/elaborate.py
node_key
¶
node_key(node: ParseNode) -> ReadingKey
A structural key of a reading, for telling readings apart.
| PARAMETER | DESCRIPTION |
|---|---|
node
|
The reading.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ReadingKey
|
Equal for equal readings. |
Source code in src/quivers/dsl/notation/enforest.py
production_of
¶
production_of(use: ParseUse, table: NotationTable) -> Production
The production a use applies.
| PARAMETER | DESCRIPTION |
|---|---|
use
|
The use.
TYPE:
|
table
|
The active notations.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Production
|
Its production. |
Source code in src/quivers/dsl/notation/enforest.py
core_term
¶
The host term of a nameless term that splices nothing.
| PARAMETER | DESCRIPTION |
|---|---|
node
|
The term.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
The structural term, |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the term splices an antiquotation, whose value is not known. |
Source code in src/quivers/dsl/notation/hygiene.py
definition_scope
¶
The scope every name a notation's templates introduce carries.
| PARAMETER | DESCRIPTION |
|---|---|
notation
|
The notation's flat name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
Its definition scope. |
Source code in src/quivers/dsl/notation/hygiene.py
expand_reading
¶
expand_reading(node: ParseNode, table: NotationTable, info: SyntaxInfo, sort: str, context: Sequence[TokenName], *, file: str) -> CoreNode
The nameless term a reading means.
| PARAMETER | DESCRIPTION |
|---|---|
node
|
The reading.
TYPE:
|
table
|
The active notations.
TYPE:
|
info
|
The signature of the quoted sort.
TYPE:
|
sort
|
The quoted sort.
TYPE:
|
context
|
The quotation's context names, outermost first.
TYPE:
|
file
|
The file, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CoreNode
|
The de Bruijn term. |
| RAISES | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
If a name is unbound, a variable has the wrong sort, or a literal or an abstraction stands where a term is expected. |
Source code in src/quivers/dsl/notation/hygiene.py
fresh_scope
¶
variable_sorts
¶
variable_sorts(info: SyntaxInfo) -> frozenset[str]
The sorts some constructor of a signature binds variables of.
| PARAMETER | DESCRIPTION |
|---|---|
info
|
The signature.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
frozenset[str]
|
The sorts that have variables. |
Source code in src/quivers/dsl/notation/hygiene.py
binder_levels
¶
binder_levels(template: TemplateNode, holes: frozenset[str]) -> dict[str, int]
How many binder holes enclose each binder hole of a template.
| PARAMETER | DESCRIPTION |
|---|---|
template
|
A production's template.
TYPE:
|
holes
|
Its binder holes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, int]
|
For each binder hole, the binder holes of abstractions around it. |
Source code in src/quivers/dsl/notation/printing.py
print_term
¶
print_term(term: Term, table: NotationTable, syntax: str, sort: str, context: Sequence[str] = (), *, naming: Literal['fresh', 'level'] = 'fresh') -> str
The text of a term in the active notations.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The de Bruijn term.
TYPE:
|
table
|
The active notations.
TYPE:
|
syntax
|
The flat name of the term's signature.
TYPE:
|
sort
|
The term's sort.
TYPE:
|
context
|
Names of the term's free variables, outermost first. When it is
not empty the text starts with the quotation context
TYPE:
|
naming
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The text, which a quotation reads back to the same term. |
Source code in src/quivers/dsl/notation/printing.py
printable_sorts
¶
printable_sorts(table: NotationTable) -> frozenset[tuple[str, str]]
The signature sorts some active production builds or binds.
| PARAMETER | DESCRIPTION |
|---|---|
table
|
The active notations.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
frozenset[tuple[str, str]]
|
Each signature's flat name with one of its sorts. |
Source code in src/quivers/dsl/notation/printing.py
shown_value
¶
shown_value(module: QiecModule, value: RuntimeConstructor) -> str | None
A value printed by its family's Show instance, when it has one.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked module the value belongs to.
TYPE:
|
value
|
A family value of the reference machine.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
The instance's text, or |
Source code in src/quivers/dsl/notation/rendering.py
scope_module_notation
¶
scope_module_notation(statements: Sequence[Statement], tests: Sequence[TestDecl], resolver: ModuleNotations) -> tuple[tuple[Statement, ...], tuple[TestDecl, ...]]
Scope one module's notation statements and quotations.
| PARAMETER | DESCRIPTION |
|---|---|
statements
|
The module's walked statements, in order.
TYPE:
|
tests
|
Its tests, which see the notations active at the end of the module.
TYPE:
|
resolver
|
Resolves the module's notation references.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[tuple[Statement, ...], tuple[TestDecl, ...]]
|
The statements, each |
Source code in src/quivers/dsl/notation/scoping.py
scope_statement
¶
A statement with the active notations recorded on its quotations.
| PARAMETER | DESCRIPTION |
|---|---|
statement
|
A statement of a module or of a module body.
TYPE:
|
active
|
The flat names of the notations active where it stands.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Statement
|
The statement, each quotation (value or pattern) naming |
Source code in src/quivers/dsl/notation/scoping.py
scope_test
¶
A test with the active notations recorded on its quotations.
| PARAMETER | DESCRIPTION |
|---|---|
test
|
A
TYPE:
|
active
|
The flat names of the notations active at the end of its module.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TestDecl
|
The declaration, each quotation naming |
Source code in src/quivers/dsl/notation/scoping.py
printer_statements
¶
printer_statements(table: NotationTable, *, line: int, col: int) -> tuple[Statement, ...]
The generated Show instances of the sorts a table covers.
| PARAMETER | DESCRIPTION |
|---|---|
table
|
The program's active notations at the end of its root module.
TYPE:
|
line
|
Where the
TYPE:
|
col
|
Where the
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Statement, ...]
|
The computations, |
Source code in src/quivers/dsl/notation/show.py
build_table
¶
build_table(notations: Sequence[str], declarations: Mapping[str, NotationDecl], syntaxes: Mapping[str, SyntaxInfo], files: Mapping[str, str], *, file: str, line: int = 0, col: int = 0) -> NotationTable
Read the active notations into one table.
| PARAMETER | DESCRIPTION |
|---|---|
notations
|
The flat names of the active notations, in activation order.
TYPE:
|
declarations
|
Every notation declaration of the program, by flat name. A
relation's references are qualified production names
(
TYPE:
|
syntaxes
|
Every signature, by flat name.
TYPE:
|
files
|
The file each notation is declared in, by flat name.
TYPE:
|
file
|
The file of the point the table serves, for activation refusals.
TYPE:
|
line
|
The location of that point.
TYPE:
|
col
|
The location of that point.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NotationTable
|
The productions, levels, and signatures. |
| RAISES | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
If a notation's signature is unknown, a production does not read, two active productions have one shape, a relation names an unknown production, the relations form a cycle, or one level mixes associativities. |
Source code in src/quivers/dsl/notation/table.py
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 | |
describe_notation
¶
A notation named with its module, for messages.
| PARAMETER | DESCRIPTION |
|---|---|
flat
|
The notation's flat-program name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/notation/table.py
fail
¶
fail(message: str, *, file: str, line: int = 0, col: int = 0) -> QiecDiagnosticError
A located notation diagnostic.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
What was refused.
TYPE:
|
file
|
The file.
TYPE:
|
line
|
The 1-based line.
TYPE:
|
col
|
The 0-based column.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
The diagnostic, with code |
Source code in src/quivers/dsl/notation/table.py
is_symbol
¶
Whether a token is a run of symbol characters.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The token.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True when no character is a space, an ASCII letter or digit, an
underscore, a bracket, a quote, |
Source code in src/quivers/dsl/notation/table.py
is_word
¶
Whether a token is spelled like a name.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The token.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True for |
Source code in src/quivers/dsl/notation/table.py
piece_edges
¶
piece_edges(item: ShapeItem) -> tuple[bool, bool]
Whether a printed shape item starts and ends like a name.
Two printed pieces are separated by a space exactly when the first ends like a name and the second starts like one, so a name, a literal, or an operand never runs into its neighbour; a symbol token and declared printing space need none.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
The item.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[bool, bool]
|
Whether its printing starts like a name, and whether it ends like one. |
Source code in src/quivers/dsl/notation/table.py
read_production
¶
read_production(notation: str, production: NotationProduction, syntax: SyntaxInfo, *, file: str, order: int = 0) -> Production
Read one production against its signature.
| PARAMETER | DESCRIPTION |
|---|---|
notation
|
The flat name of its notation.
TYPE:
|
production
|
The production as written.
TYPE:
|
syntax
|
The signature of its notation.
TYPE:
|
file
|
The file it is written in.
TYPE:
|
order
|
Its declaration order among the active productions.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Production
|
The production, each hole with its role and sort. |
| RAISES | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
If the shape has no token and is not juxtaposition, two operand holes are adjacent elsewhere, a token cannot be read, a hole is unused or appears twice in the shape, or the template is not a term of the signature. |
Source code in src/quivers/dsl/notation/table.py
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 | |
syntax_infos
¶
syntax_infos(signatures: Iterable[tuple[str, Signature]]) -> dict[str, SyntaxInfo]
Signatures keyed by flat name, as notation reads them.
| PARAMETER | DESCRIPTION |
|---|---|
signatures
|
Each signature's flat name and value.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, SyntaxInfo]
|
By flat name. |
Source code in src/quivers/dsl/notation/table.py
read_quotation
¶
read_quotation(items: tuple[NotationItem, ...], table: NotationTable, *, file: str) -> QuotationText
A quotation's context and tokens.
A quotation may begin with a context, the names of the free variables
the quoted term may mention, separated by commas and ended by ⊢.
| PARAMETER | DESCRIPTION |
|---|---|
items
|
The quotation's token tree.
TYPE:
|
table
|
The active notations.
TYPE:
|
file
|
The file, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QuotationText
|
The context names and the term's tokens. |
| RAISES | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
If the context is not names separated by commas, or a token does not read. |
Source code in src/quivers/dsl/notation/tokens.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 | |
read_tokens
¶
read_tokens(items: tuple[NotationItem, ...], table: NotationTable, *, file: str) -> tuple[ReadToken, ...]
The reader's tokens of a token tree.
| PARAMETER | DESCRIPTION |
|---|---|
items
|
The token tree.
TYPE:
|
table
|
The active notations.
TYPE:
|
file
|
The file, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[ReadToken, ...]
|
The tokens; parenthesized groups stay groups. |
| RAISES | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
If a symbol run is not made of active tokens, or a square or curly bracket is not an active token. |
Source code in src/quivers/dsl/notation/tokens.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
enforest
¶
Enforestation: reading a quotation's tokens against the active precedence DAG.
The reader follows Danielsson and Norell's grammar for mixfix operators
over a precedence graph. A level's expressions are its operators applied
to operands of strictly tighter levels, except that a prefix or
right-associative operator's last operand may again be of its own level
(a right chain) and a postfix or left-associative operator's first
operand may be (a left chain). The holes between an operator's tokens
take any expression. Closed productions, names, antiquotations,
constructor applications Op(a, x. b), and parenthesized groups are
atoms, usable anywhere.
The reader is a memoized top-down parser that keeps every reading (up to two per span, which is all ambiguity detection needs), so it reports an ambiguous quotation instead of choosing. When no reading exists, it reads again treating every pair of unrelated levels as nestable; a reading found then shows which two productions lack a precedence relation, and the refusal names both and the notations and modules that declare them.
enforest
¶
enforest(tokens: Sequence[ReadToken], table: NotationTable, sort: SortKey, *, file: str, line: int, col: int) -> Reading
Read a quotation's tokens into exactly one reading.
| PARAMETER | DESCRIPTION |
|---|---|
tokens
|
The quotation's tokens.
TYPE:
|
table
|
The active notations.
TYPE:
|
sort
|
The sort the quotation must build, or
TYPE:
|
file
|
The file, for diagnostics.
TYPE:
|
line
|
The quotation's location.
TYPE:
|
col
|
The quotation's location.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Reading
|
The reading and its sort. |
| RAISES | DESCRIPTION |
|---|---|
QiecDiagnosticError
|
If the quotation is empty, has no reading, has a reading only when two unrelated productions nest (naming both, their notations, and their modules), or has two readings (naming the productions where they differ). |
Source code in src/quivers/dsl/notation/enforest.py
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 | |
notation
¶
Language-server support for notation: hover on quotations, definition of operators.
Hovering a quotation shows the term it elaborates to (its constructor tree, with de Bruijn variables), its sort, and its text printed back through the active notations. Go-to-definition on a token of a quotation reaches the production of the notation that read it, in whichever module declares it.
NotationTarget
didactic-model
¶
Bases: Model
Where a production is declared.
| PARAMETER | DESCRIPTION |
|---|---|
file
|
Its file, or empty for the document itself.
TYPE:
|
line
|
Its 0-based line in that file.
TYPE:
|
col
|
Its 0-based column.
TYPE:
|
length
|
The length of the production's name.
TYPE:
|
quotation_at
¶
quotation_at(module: Module, source: str, line: int, col: int) -> tuple[Quotation, int] | None
The quotation of a document's own module at a position.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The program (the document's own statements come first).
TYPE:
|
source
|
The document's text.
TYPE:
|
line
|
The 0-based line.
TYPE:
|
col
|
The 0-based character column.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Quotation, int] | None
|
The innermost quotation covering the position and the position's
byte offset, or |
Source code in src/quivers/lsp/notation.py
notation_hover
¶
notation_hover(module: Module, source: str, line: int, col: int, *, file: str) -> str | None
The hover text of a quotation: the term it elaborates to.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The document's program.
TYPE:
|
source
|
The document's text.
TYPE:
|
line
|
The 0-based line.
TYPE:
|
col
|
The 0-based character column.
TYPE:
|
file
|
The document, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
Markdown naming the sort, the elaborated constructor tree, and the
printed form; the refusal when the quotation does not elaborate;
|
Source code in src/quivers/lsp/notation.py
notation_definition
¶
notation_definition(module: Module, source: str, line: int, col: int, *, file: str, source_map: SourceMap | None = None) -> NotationTarget | None
The production that read the token of a quotation at a position.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The document's program.
TYPE:
|
source
|
The document's text.
TYPE:
|
line
|
The 0-based line.
TYPE:
|
col
|
The 0-based character column.
TYPE:
|
file
|
The document.
TYPE:
|
source_map
|
Maps a line of the flat program to its file, when the program is a module graph.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NotationTarget | None
|
The production's name in its declaration, or |
Source code in src/quivers/lsp/notation.py
Module scoping enters through
scope_module_notation for a whole module, and
through scope_statement and
scope_test for one statement or test of a module or
functor body, given the notations active where it stands.