Lexicon expansion¶
Category sets, polymorphic entries, synthesized meanings, templates, lexical rules, and refinements, expanded into ordinary deductions. The lexicon reference describes the surface, and the semantics states the rules.
lexical
¶
Lexicon expansion: category sets, polymorphic entries, lexical rules, refinements.
A deduction may declare regular sets of categories (categories), the
semantic type of each category (semantics), templates for families of
entries, polymorphic entries whose categories quantify over category sets
(∀ X in Conj. ...), lexical rules, atoms with features, and a base it
refines. expand_lexical rewrites every such deduction into an ordinary
one before any engine reads it, so the reference machine, the compiled
runtime, and every transpile target see only atoms, rules, and monomorphic
entries; meanings synthesized by meta computations are checked by the
deduction's typing judgment, and a refinement is checked to restrict its
base and given its forgetful map. A deduction with a lazily instantiated
entry or a lexical rule in chart mode also gets an agenda plan
(quivers.dsl.ast_nodes.plans), which the agenda engine runs in its place
and reads back as the deduction before its items leave the engine.
quivers.dsl.lexical.terms: categories and meanings as first-order terms.quivers.dsl.lexical.categories: category sets.quivers.dsl.lexical.universe: the categories a grammar attests.quivers.dsl.lexical.semantics: semantic types and the typing check.quivers.dsl.lexical.synthesis: meanings synthesized by meta computations.quivers.dsl.lexical.entries: templates and polymorphic entries.quivers.dsl.lexical.lexical_rules: lexical rules.quivers.dsl.lexical.lazy: lazy instantiation by rule specialization.quivers.dsl.lexical.features: atoms with features.quivers.dsl.lexical.refinement: refinements and their forgetful maps.quivers.dsl.lexical.expand: the expansion of a module.
ENTRY_OPTIONS
module-attribute
¶
The options a lexicon entry or a template may carry.
OPERATION_OPTIONS
module-attribute
¶
Rule options naming a computation over the rule's matched variables, which a specialized rule reads from its source rather than carrying.
LEVEL
module-attribute
¶
The prefix of the atoms counting the chart rule applications behind a lexical item.
WRAPPER
module-attribute
¶
The atom wrapping a lexical item's category when lexical rules run in the chart.
SPAN_HEAD
module-attribute
¶
The head of the items a lexicon yields: span(i, j, category[, meaning]).
CategorySets
¶
CategorySets(declarations: Iterable[CategorySetDecl], is_atom: Callable[[str], bool], owner: str)
The category sets of one deduction.
| PARAMETER | DESCRIPTION |
|---|---|
declarations
|
The
TYPE:
|
is_atom
|
Whether a name is one of the deduction's atoms.
TYPE:
|
owner
|
The deduction, for diagnostics.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If two sets share a name, a set is named like an atom, a member names something that is neither an atom nor a set, or a set is a member of itself without a constructor in between (so membership would not be decided by recursion on terms). |
Source code in src/quivers/dsl/lexical/categories.py
finite
cached
property
¶
The sets no set reaches itself from: the finite ones.
| RETURNS | DESCRIPTION |
|---|---|
frozenset[str]
|
Their names. |
__contains__
¶
Whether a set of that name is declared.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Whether it names a set. |
Source code in src/quivers/dsl/lexical/categories.py
require
¶
Refuse a name that is no declared set.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name.
TYPE:
|
line
|
Where it is used.
TYPE:
|
col
|
Where it is used.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If no category set has that name. |
Source code in src/quivers/dsl/lexical/categories.py
contains
¶
contains(name: str, term: Term) -> bool
Whether a ground term belongs to a set.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The set.
TYPE:
|
term
|
The term.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Membership. |
Source code in src/quivers/dsl/lexical/categories.py
enumerate
¶
enumerate(name: str) -> tuple[Term, ...]
Every member of a finite set, in declaration order.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The set.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Term, ...]
|
Its members, each once. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the set is infinite. |
Source code in src/quivers/dsl/lexical/categories.py
describe
¶
Spell a set's declaration.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The set.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/lexical/categories.py
Instance
didactic-model
¶
Instance(*, word: str, category: Term, meaning: LetExprNode, learnable: bool = False, weights: tuple[str, ...] = (), apart: bool = False, source: int = 0, lazy: bool = False, line: int = 0, col: int = 0)
Bases: Model
One monomorphic lexicon entry.
| PARAMETER | DESCRIPTION |
|---|---|
word
|
The word.
TYPE:
|
category
|
The ground category.
TYPE:
|
meaning
|
The meaning.
TYPE:
|
learnable
|
Whether the instance has a learned weight of its own.
TYPE:
|
weights
|
The weight families it reads.
TYPE:
|
apart
|
Whether its entry weighs each instance apart (
TYPE:
|
source
|
The index of the written entry it comes from.
TYPE:
|
lazy
|
Whether its entry is instantiated lazily.
TYPE:
|
line
|
The written entry's line.
TYPE:
|
col
|
The written entry's column.
TYPE:
|
entry
¶
entry() -> LexiconEntry
The instance as a plain lexicon entry.
| RETURNS | DESCRIPTION |
|---|---|
LexiconEntry
|
The entry, with no option but |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the category cannot be written as a category. |
Source code in src/quivers/dsl/lexical/entries.py
Schema
didactic-model
¶
Schema(*, words: tuple[str, ...], binders: tuple[CategoryBinder, ...], category: Term, meaning: LetExprNode, options: tuple[OptionEntry, ...] = (), index: int = 0, line: int = 0, col: int = 0)
Bases: Model
A written entry read as a schema: binders, category, meaning, options.
| PARAMETER | DESCRIPTION |
|---|---|
words
|
Its words.
TYPE:
|
binders
|
Its category variables and their sets.
TYPE:
|
category
|
Its category, over the variables.
TYPE:
|
meaning
|
Its meaning.
TYPE:
|
options
|
Its options, template options first.
TYPE:
|
index
|
Its position in the lexicon.
TYPE:
|
line
|
Its line.
TYPE:
|
col
|
Its column.
TYPE:
|
LexicalError
¶
Bases: ValueError
A deduction's lexicon, category sets, or refinement cannot be expanded.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
What is wrong, naming the declaration and the property it lacks.
TYPE:
|
line
|
The 1-based source line, or 0 when unknown.
TYPE:
|
col
|
The 0-based source column, or 0 when unknown.
TYPE:
|
Source code in src/quivers/dsl/lexical/errors.py
code
class-attribute
instance-attribute
¶
The diagnostic code every lexicon refusal carries.
LexicalExpansion
didactic-model
¶
LexicalExpansion(*, module: Module = field(opaque=True, extras=OPAQUE_BY_VALUE), refinements: Mapping[str, Refinement] = field(opaque=True, default_factory=dict, extras=OPAQUE_BY_VALUE), plans: Mapping[str, AgendaPlan] = field(opaque=True, default_factory=dict, extras=OPAQUE_BY_VALUE))
Bases: ValueModel
A module with plain deductions, the refinements it declares, and agenda plans.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module.
TYPE:
|
refinements
|
The forgetful map of each refined deduction, by name.
TYPE:
|
plans
|
The deduction the agenda engine runs in place of each deduction with a lazily instantiated entry or a lexical rule in chart mode, by name.
TYPE:
|
Features
didactic-model
¶
Features(*, sets: Mapping[str, tuple[str, ...]] = field(opaque=True, extras=OPAQUE_BY_VALUE), values: Mapping[str, tuple[tuple[str, ...], ...]] = field(opaque=True, extras=OPAQUE_BY_VALUE))
Bases: ValueModel
The featured atoms of one deduction.
| PARAMETER | DESCRIPTION |
|---|---|
sets
|
Each featured atom's feature sets, in order.
TYPE:
|
values
|
Each featured atom's admissible values at each feature.
TYPE:
|
atoms
property
¶
The featured atoms.
| RETURNS | DESCRIPTION |
|---|---|
frozenset[str]
|
Their names. |
instances
¶
Every atom the featured atoms stand for, with the atom it refines.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, str]
|
|
Source code in src/quivers/dsl/lexical/features.py
ground
¶
Replace every featured atom of a ground term by its atom.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
A category or item.
TYPE:
|
where
|
Its owner, for diagnostics.
TYPE:
|
line
|
Where it is written.
TYPE:
|
col
|
Where it is written.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
The term over plain atoms. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If a featured atom is written bare, with the wrong number of features, or with a value outside its feature's set. |
Source code in src/quivers/dsl/lexical/features.py
variables
¶
variables(term: Term) -> dict[str, frozenset[str]]
The feature variables of a term and the values each may take.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
A rule's premise or conclusion.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, frozenset[str]]
|
Each variable filling a feature, with the values of every feature it fills. |
Source code in src/quivers/dsl/lexical/features.py
Specialization
didactic-model
¶
Specialization(*, placeholders: tuple[Instance, ...] = (), rules: tuple[SequentRule, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), instances: Mapping[str, Mapping[int, Term]] = field(default_factory=dict, opaque=True, extras=OPAQUE_BY_VALUE), names: tuple[str, ...] = (), consumed: Mapping[str, tuple[tuple[str, str, Term], ...]] = field(default_factory=dict, opaque=True, extras=OPAQUE_BY_VALUE))
Bases: ValueModel
What lazy instantiation adds to a deduction.
| PARAMETER | DESCRIPTION |
|---|---|
placeholders
|
One entry per word and meaning of each lazy entry, its category the placeholder atom and its meaning the instances' meaning.
TYPE:
|
rules
|
The specialized rules.
TYPE:
|
instances
|
Each specialized rule's instance category at each position that takes a placeholder, for reading a derivation back as one over the instances.
TYPE:
|
names
|
The placeholder atom of each lazy instance, in the order given.
TYPE:
|
consumed
|
Each specialized rule's consumed instances, in premise order: the placeholder, the word, and the instance category.
TYPE:
|
ReadRule
¶
ReadRule(rule: LexicalRuleDecl, is_atom: Callable[[str], bool], owner: str)
A lexical rule read as terms.
| PARAMETER | DESCRIPTION |
|---|---|
rule
|
The rule.
TYPE:
|
is_atom
|
Whether a name is an atom.
TYPE:
|
owner
|
The deduction, for diagnostics.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If an option is unknown or malformed, an item is not a span, the premise's positions are not variables, or the conclusion's span is not the premise's. |
Source code in src/quivers/dsl/lexical/lexical_rules.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
family
property
¶
The weight family the rule contributes, when it learns one.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
|
apply
¶
The entry the rule derives from one entry, if its premise matches.
| PARAMETER | DESCRIPTION |
|---|---|
instance
|
The entry.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Instance | None
|
The derived entry, reading the entry's weights and the rule's. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the conclusion's category is not ground. |
Source code in src/quivers/dsl/lexical/lexical_rules.py
Derivation
didactic-model
¶
Derivation(*, item: Hashable = field(opaque=True, extras=OPAQUE_BY_IDENTITY), rule: str = '', premises: tuple[Derivation, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE))
Bases: ValueModel
A derivation read off a chart: an item, its rule, its premises.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
The item derived, in the chart's representation. It may be any hashable host value and is compared by identity.
TYPE:
|
rule
|
The rule applied, or empty for a lexical axiom.
TYPE:
|
premises
|
The derivations of its premises, in order.
TYPE:
|
Refinement
didactic-model
¶
Refinement(*, name: str, base: str, atom_images: Mapping[str, str] = field(opaque=True, extras=OPAQUE_BY_VALUE), rule_images: Mapping[str, str] = field(opaque=True, extras=OPAQUE_BY_VALUE))
Bases: ValueModel
The forgetful map of one refinement.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The refined deduction.
TYPE:
|
base
|
The deduction it refines.
TYPE:
|
atom_images
|
Each atom of the refinement that is not one of the base's, with the base atom it forgets to.
TYPE:
|
rule_images
|
Each rule of the refinement with the base rule it maps to.
TYPE:
|
forget
¶
The forgetful image of a category, item, or rule pattern.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
A term of the refinement.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
The base term. |
Source code in src/quivers/dsl/lexical/refinement.py
forget_item
¶
The forgetful image of a chart item, as the agenda engine holds it.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
A refined item: a tuple whose atoms are
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Hashable
|
The base item. |
Source code in src/quivers/dsl/lexical/refinement.py
forget_derivation
¶
forget_derivation(derivation: Derivation) -> Derivation
The forgetful image of a derivation.
| PARAMETER | DESCRIPTION |
|---|---|
derivation
|
A derivation in the refined deduction's chart.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Derivation
|
Its image: every item forgotten, every rule its base rule. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the derivation applies a rule the refinement does not have. |
Source code in src/quivers/dsl/lexical/refinement.py
SemanticTypes
¶
SemanticTypes(declaration: SemanticsDecl, is_atom: Callable[[str], bool], judgments: Mapping[str, JudgmentSystem], owner: str)
The semantic types of one deduction's categories.
| PARAMETER | DESCRIPTION |
|---|---|
declaration
|
The
TYPE:
|
is_atom
|
Whether a name is one of the deduction's atoms.
TYPE:
|
judgments
|
The module's judgments.
TYPE:
|
owner
|
The deduction, for diagnostics.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the judgment is undeclared or is not |
Source code in src/quivers/dsl/lexical/semantics.py
type_of
¶
The semantic type of a ground category.
| PARAMETER | DESCRIPTION |
|---|---|
category
|
The category.
TYPE:
|
line
|
Where it is used.
TYPE:
|
col
|
Where it is used.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
Its type, a ground term of the judgment's syntax. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If no clause matches the category or one of its parts. |
Source code in src/quivers/dsl/lexical/semantics.py
check
¶
check(meaning: LetExprNode, category: Term, *, owner: str) -> None
Refuse a meaning without a typing at its category's type.
| PARAMETER | DESCRIPTION |
|---|---|
meaning
|
The meaning.
TYPE:
|
category
|
Its category.
TYPE:
|
owner
|
The entry, for diagnostics.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the meaning is not a term of the judgment's syntax, or has no derivation of the judgment at the category's type; the message names the type and the constraint that failed. |
Source code in src/quivers/dsl/lexical/semantics.py
SynthesisCall
didactic-model
¶
SynthesisCall(*, generator: str, argument: Term, owner: str, line: int = 0, col: int = 0)
Bases: Model
One meaning to synthesize.
| PARAMETER | DESCRIPTION |
|---|---|
generator
|
The meta computation.
TYPE:
|
argument
|
The semantic type it receives, a ground term.
TYPE:
|
owner
|
The entry the meaning is for, for diagnostics.
TYPE:
|
line
|
The call's line.
TYPE:
|
col
|
The call's column.
TYPE:
|
Node
didactic-model
¶
Node(*, head: str, args: tuple[Term, ...] = (), form: Literal['atom', 'apply', 'slash', 'features', 'integer', 'string'] = 'atom', kind: Literal['node'] = 'node')
Bases: Term
An atom, an application, a slash, or an atom at feature values.
| PARAMETER | DESCRIPTION |
|---|---|
head
|
The atom, the applied symbol, the slash (
TYPE:
|
args
|
The arguments; empty for an atom.
TYPE:
|
form
|
How the source spells it:
TYPE:
|
Variable
didactic-model
¶
CategoryRule
didactic-model
¶
binder_sets
¶
binder_sets(binders: Mapping[str, str], sets: CategorySets, line: int, col: int) -> None
Refuse binders over undeclared sets.
| PARAMETER | DESCRIPTION |
|---|---|
binders
|
Each category variable's set.
TYPE:
|
sets
|
The deduction's sets.
TYPE:
|
line
|
Where the binders are written.
TYPE:
|
col
|
Where the binders are written.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If a set is undeclared. |
Source code in src/quivers/dsl/lexical/categories.py
empty_sets
¶
empty_sets(owner: str) -> CategorySets
No category sets.
| PARAMETER | DESCRIPTION |
|---|---|
owner
|
The deduction, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CategorySets
|
The empty collection. |
Source code in src/quivers/dsl/lexical/categories.py
family_of_entry
¶
The weight family every instance of a written entry reads.
| PARAMETER | DESCRIPTION |
|---|---|
index
|
The entry's position in the lexicon.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/lexical/entries.py
family_of_instance
¶
family_of_instance(index: int, assignment: Sequence[Term]) -> str
The weight family an instance of a per_instance entry reads.
The entry's family is indexed by the instantiation, as a rule schema's
#[shared = F(n)] is by its parameters, so each assignment of
categories to the entry's variables has a weight of its own, read by
the instance however the entry is instantiated.
| PARAMETER | DESCRIPTION |
|---|---|
index
|
The entry's position in the lexicon.
TYPE:
|
assignment
|
The categories its variables take, in binder order.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/lexical/entries.py
instances
¶
instances(schema: Schema, sets: CategorySets, attested: Callable[[int], frozenset[Term]], synthesize: Callable[[str, Term, str, int, int], LetExprNode], *, depth_bound: int | None, owner: str) -> tuple[Instance, ...]
The instances of one schema.
| PARAMETER | DESCRIPTION |
|---|---|
schema
|
The entry.
TYPE:
|
sets
|
The deduction's category sets.
TYPE:
|
attested
|
The categories the grammar attests up to a depth bound.
TYPE:
|
synthesize
|
Synthesizes a meaning:
TYPE:
|
depth_bound
|
The deduction's
TYPE:
|
owner
|
The deduction, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Instance, ...]
|
One instance per word and assignment, in order. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If a variable ranges over an undeclared set, over an infinite set with no bound, the category mentions a name that is neither an atom nor a variable, or the meaning uses a variable in a way no category spells. |
Source code in src/quivers/dsl/lexical/entries.py
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 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |
schemas
¶
schemas(declaration: DeductionDecl, is_atom: Callable[[str], bool], templates: Mapping[str, LexicalTemplate], owner: str) -> tuple[Schema, ...]
Read each written entry as a schema, applying templates.
| PARAMETER | DESCRIPTION |
|---|---|
declaration
|
The deduction.
TYPE:
|
is_atom
|
Whether a name is one of its atoms.
TYPE:
|
templates
|
Its templates, by name.
TYPE:
|
owner
|
The deduction, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Schema, ...]
|
One schema per written entry, in order. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If an entry has an unknown option, or a latent ( |
Source code in src/quivers/dsl/lexical/entries.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 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 | |
synthesis_calls
¶
synthesis_calls(meaning: LetExprNode, variables: frozenset[str]) -> bool
Whether a meaning calls a meta computation on a category variable.
| PARAMETER | DESCRIPTION |
|---|---|
meaning
|
The meaning.
TYPE:
|
variables
|
The category variables.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Whether some |
Source code in src/quivers/dsl/lexical/entries.py
expand_lexical
¶
expand_lexical(module: Module, *, module_name: str, file_path: str) -> LexicalExpansion
Expand every deduction of a module into a plain one.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module, its deductions composed.
TYPE:
|
module_name
|
The module's name, for the meta phase.
TYPE:
|
file_path
|
The path recorded on diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LexicalExpansion
|
The module, each deduction that used lexical surface replaced by its expansion and followed by what its refinement generates, the refinements' forgetful maps, and the agenda plans. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If any deduction's expansion is refused; the message names the deduction, the part refused, and the property it lacks. |
Source code in src/quivers/dsl/lexical/expand.py
uses_lexical_surface
¶
uses_lexical_surface(declaration: DeductionDecl) -> bool
Whether a deduction uses anything expansion rewrites.
| PARAMETER | DESCRIPTION |
|---|---|
declaration
|
The deduction.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Whether it declares category sets, semantics, templates, lexical rules, featured atoms, or a base, or has a polymorphic entry or an entry naming a weight family. |
Source code in src/quivers/dsl/lexical/expand.py
featured_name
¶
The atom a featured atom is at some feature values.
| PARAMETER | DESCRIPTION |
|---|---|
atom
|
The featured atom.
TYPE:
|
values
|
Its feature values, in order.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/lexical/features.py
instantiate_rules
¶
instantiate_rules(rules: Sequence[SequentRule], features: Features, is_atom: Callable[[str], bool], owner: str) -> tuple[tuple[SequentRule, ...], dict[str, str]]
Each rule at every assignment of its feature variables.
| PARAMETER | DESCRIPTION |
|---|---|
rules
|
The rules.
TYPE:
|
features
|
The featured atoms.
TYPE:
|
is_atom
|
Whether a name is an atom.
TYPE:
|
owner
|
The deduction, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[tuple[SequentRule, ...], dict[str, str]]
|
The rules over plain atoms, and each rule's source rule by name. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If a featured atom is written bare or with values outside its sets, or a feature variable can take no value. |
Source code in src/quivers/dsl/lexical/features.py
read_features
¶
read_features(declared: Sequence[AtomFeatures], sets: CategorySets, owner: str) -> Features
Read a deduction's featured atoms.
| PARAMETER | DESCRIPTION |
|---|---|
declared
|
The featured atoms of its atoms lines.
TYPE:
|
sets
|
Its category sets.
TYPE:
|
owner
|
The deduction, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Features
|
The featured atoms. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If a feature's set is undeclared, infinite, or has a member that is not an atom, or an atom is declared with features twice. |
Source code in src/quivers/dsl/lexical/features.py
placeholder
¶
The atom standing for a lazily instantiated entry at one meaning.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The entry's position in the lexicon.
TYPE:
|
meaning_class
|
The position of the meaning (and the weights) among the entry's.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/lexical/lazy.py
specialize
¶
specialize(lazy: Sequence[Instance], rules: Sequence[SequentRule], is_atom: Callable[[str], bool], owner: str, *, wrap: Callable[[Term], Term] | None = None, suffix: str = 'lazy', per_word: bool = False) -> Specialization
The placeholder entries and specialized rules of lazy entries.
| PARAMETER | DESCRIPTION |
|---|---|
lazy
|
The instances of every lazily instantiated entry.
TYPE:
|
rules
|
The rules to specialize.
TYPE:
|
is_atom
|
Whether a name is an atom.
TYPE:
|
owner
|
The deduction, for diagnostics.
TYPE:
|
wrap
|
Wraps a lexical item's category when the rules take wrapped items
(lexical rules in the chart), or |
suffix
|
What a specialized rule's name adds to its source's.
TYPE:
|
per_word
|
Whether each word of an entry has a placeholder of its own, so a rule that consumes one knows the word: a grammar normalized per left-hand side reads the consumed instance's production, which is the word's.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Specialization
|
The placeholders, the specialized rules, and their instances. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If a premise that is a bare variable would be specialized while the variable also occurs inside a term of the rule. |
Source code in src/quivers/dsl/lexical/lazy.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 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 | |
chart_atoms
¶
chart_atoms(rules: Sequence[ReadRule]) -> tuple[str, ...]
The atoms the chart's lexical rules add to a deduction's plan.
| PARAMETER | DESCRIPTION |
|---|---|
rules
|
The lexical rules in
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The wrapper and one level atom per depth, or none without rules. |
Source code in src/quivers/dsl/lexical/lexical_rules.py
chart_depth
¶
chart_depth(rules: Sequence[ReadRule]) -> int
The number of chart rule applications a lexical item may have behind it.
| PARAMETER | DESCRIPTION |
|---|---|
rules
|
The lexical rules in
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
Their largest |
Source code in src/quivers/dsl/lexical/lexical_rules.py
chart_lexicon
¶
chart_lexicon(found: Sequence[Instance], rules: Sequence[ReadRule]) -> tuple[tuple[Instance, str], ...]
The entries lexical rules in chart mode derive from a lexicon.
The chart rules close the lexicon as compiled rules do: each round
applies every rule to the entries the previous round derived, up to the
rules' largest bound.
| PARAMETER | DESCRIPTION |
|---|---|
found
|
The lexicon's entries, their weights shared (
TYPE:
|
rules
|
The lexical rules in
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[tuple[Instance, str], ...]
|
Each derived entry, reading its source's weights and the rule's, and the rule deriving it, chain by chain. |
Source code in src/quivers/dsl/lexical/lexical_rules.py
chart_rules
¶
chart_rules(rules: Sequence[ReadRule]) -> tuple[SequentRule, ...]
The chart rules lexical rules in chart mode become.
| PARAMETER | DESCRIPTION |
|---|---|
rules
|
The lexical rules in
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[SequentRule, ...]
|
|
Source code in src/quivers/dsl/lexical/lexical_rules.py
compile_lexical_rules
¶
Close a lexicon under its compiled lexical rules.
Every entry first reads its own weight as the family of its written entry, so an entry a rule derives reads the same weight.
| PARAMETER | DESCRIPTION |
|---|---|
found
|
The lexicon's entries.
TYPE:
|
rules
|
The lexical rules in
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Instance, ...]
|
The entries, then the derived ones, chain by chain up to the
largest |
Source code in src/quivers/dsl/lexical/lexical_rules.py
family_of_rule
¶
The weight family of a learnable lexical rule.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The lexical rule.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/lexical/lexical_rules.py
level
¶
The atom marking a lexical item a number of chart rule applications derived.
| PARAMETER | DESCRIPTION |
|---|---|
depth
|
The number of applications.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/lexical/lexical_rules.py
level_rule
¶
The plan's copy of a chart lexical rule taking items at one level.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The lexical rule.
TYPE:
|
depth
|
The level of the items the copy takes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/lexical/lexical_rules.py
share_weights
¶
Give every entry with a learned weight of its own its written entry's family.
An entry a lexical rule derives reads its source entry's weight, so the source's own weight becomes the family of its written entry, which both read.
| PARAMETER | DESCRIPTION |
|---|---|
found
|
The lexicon's entries.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Instance, ...]
|
The entries, each learnable one reading its written entry's family instead of a weight of its own. |
wrap
¶
A lexical entry whose item lexical rules in the chart apply to.
| PARAMETER | DESCRIPTION |
|---|---|
instance
|
The entry.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Instance
|
The entry with its category wrapped at level zero,
|
Source code in src/quivers/dsl/lexical/lexical_rules.py
wrapped
¶
A lexical item's category as the chart's lexical rules read it.
| PARAMETER | DESCRIPTION |
|---|---|
category
|
The category.
TYPE:
|
depth
|
The number of chart rule applications that derived the item.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
|
Source code in src/quivers/dsl/lexical/lexical_rules.py
check_restriction
¶
check_restriction(refinement: Refinement, rules: Sequence[SequentRule], entries: Sequence[LexiconEntry], base: DeductionDecl, is_atom: Callable[[str], bool], is_base_atom: Callable[[str], bool], sources: Mapping[str, str]) -> dict[str, str]
Check that a refinement only restricts its base; map its rules.
| PARAMETER | DESCRIPTION |
|---|---|
refinement
|
The refinement's forgetful map on atoms.
TYPE:
|
rules
|
The refinement's expanded rules.
TYPE:
|
entries
|
Its expanded lexicon.
TYPE:
|
base
|
The expanded base.
TYPE:
|
is_atom
|
Whether a name is an atom of the refinement.
TYPE:
|
is_base_atom
|
Whether a name is an atom of the base.
TYPE:
|
sources
|
Each expanded rule's written rule, for preferring a base rule of the same name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, str]
|
Each refined rule's base rule. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If a rule's image is an instance of no base rule, naming the rule and its image, or an entry's image is no base entry. |
Source code in src/quivers/dsl/lexical/refinement.py
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 431 432 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 | |
inherit
¶
inherit(refined: DeductionDecl, base: DeductionDecl, featured: frozenset[str], is_base_atom: Callable[[str], bool]) -> DeductionDecl
A refinement with the parts of its base it does not restate.
| PARAMETER | DESCRIPTION |
|---|---|
refined
|
The refinement as written.
TYPE:
|
base
|
The base as written.
TYPE:
|
featured
|
The atoms the refinement gives features.
TYPE:
|
is_base_atom
|
Whether a name is an atom of the base.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DeductionDecl
|
The refinement with the base's atoms, binders, rules, entries, templates, lexical rules, category sets, and semantics it does not restate, keeping the refinement's own first. A base part that reads a featured atom bare is not inherited, since the refinement gives that atom no bare reading: a rule, lexical rule, or category set that names one, a template or entry whose category names one, and anything that ranges over or names a category set or template that is not inherited for that reason. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the base has a part the refinement cannot read: a lexicon file. |
Source code in src/quivers/dsl/lexical/refinement.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 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 304 305 306 307 308 309 310 311 312 313 314 315 | |
transport_guard
¶
transport_guard(declaration: QiecComputationDecl, name: str, base: str, refined: str, preimages: Mapping[str, tuple[str, ...]]) -> QiecComputationDecl
A guard over a base's items transported to a refinement's items.
A guard may not call another computation, so it cannot read its matched items through the forgetful map. It is transported the way Dagand and McBride transport a function defined by case analysis: each branch on a base constructor becomes a branch on every refined constructor that forgets to it, so the transported guard on a refined item decides what the base guard decides on its image.
| PARAMETER | DESCRIPTION |
|---|---|
declaration
|
The base guard.
TYPE:
|
name
|
The transported guard's name.
TYPE:
|
base
|
The base deduction.
TYPE:
|
refined
|
The refinement.
TYPE:
|
preimages
|
Each base symbol with the refined symbols that forget to it.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QiecComputationDecl
|
The transported guard. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the guard builds a base item, which has no single refinement. |
Source code in src/quivers/dsl/lexical/refinement.py
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 | |
transport_weight
¶
transport_weight(declaration: QiecComputationDecl, name: str, base: str, refined: str) -> str
A computed rule weight over a base's items, read on a refinement's.
The weight is a computation, which may call others, so it transports by precomposition: the transported weight forgets each item it is given and calls the base weight.
| PARAMETER | DESCRIPTION |
|---|---|
declaration
|
The base weight.
TYPE:
|
name
|
The transported weight's name.
TYPE:
|
base
|
The base deduction.
TYPE:
|
refined
|
The refinement.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The transported weight's source. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the weight takes static parameters, which a rule weight does not. |
Source code in src/quivers/dsl/lexical/refinement.py
judgment_systems
¶
judgment_systems(statements: Sequence[object]) -> dict[str, JudgmentSystem]
Build the judgment systems a module declares.
| PARAMETER | DESCRIPTION |
|---|---|
statements
|
The module's statements.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, JudgmentSystem]
|
Each judgment's system, by name. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If a syntax or a judgment does not compile. |
Source code in src/quivers/dsl/lexical/semantics.py
to_syntax
¶
A ground term as a term of a syntax.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The term, over the syntax's constructors.
TYPE:
|
signature
|
The syntax.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
The term. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the term has a variable or a head the syntax does not declare. |
Source code in src/quivers/dsl/lexical/semantics.py
synthesize
¶
synthesize(module: Module, calls: Sequence[SynthesisCall], *, module_name: str, file_path: str) -> tuple[LetExprNode, ...]
Run each synthesis call in the module's meta phase.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module, whose meta declarations the calls may use.
TYPE:
|
calls
|
The calls, in order.
TYPE:
|
module_name
|
The module's name.
TYPE:
|
file_path
|
The path recorded on diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[LetExprNode, ...]
|
Each call's meaning, in order. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If a generator is not a meta computation from one |
Source code in src/quivers/dsl/lexical/synthesis.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
apply
¶
atom
¶
atom(name: str) -> Node
The atom of a name.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The atom.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Node
|
The atom as a term. |
depth
¶
depth(term: Term) -> int
The constructor depth of a term: an atom or a variable is 0.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The term.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The depth. |
Source code in src/quivers/dsl/lexical/terms.py
from_meaning
¶
from_meaning(node: LetExprNode, *, owner: str, variables: frozenset[str] = frozenset()) -> Term
Read a lexical meaning as a term.
A name is a variable when it is one of variables (a template's
parameter, a category variable); every other name is a constant: an
atom, or a name a binder binds.
| PARAMETER | DESCRIPTION |
|---|---|
node
|
The meaning.
TYPE:
|
owner
|
What the meaning belongs to, for diagnostics.
TYPE:
|
variables
|
The names that are variables.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
The term. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the meaning holds something other than constructor applications, names, integers, and strings. |
Source code in src/quivers/dsl/lexical/terms.py
from_object
¶
from_object(expr: ObjectExpr, is_atom: Callable[[str], bool], *, owner: str) -> Term
Read an object expression as a term.
| PARAMETER | DESCRIPTION |
|---|---|
expr
|
A category or an item.
TYPE:
|
is_atom
|
Whether a bare name is an atom rather than a variable.
TYPE:
|
owner
|
What the expression belongs to, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
The term. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the expression is not a category: a product, a coproduct, a space, or a schema spine. |
Source code in src/quivers/dsl/lexical/terms.py
match
¶
match(pattern: Term, term: Term, bindings: Mapping[str, Term] | None = None) -> dict[str, Term] | None
Match a pattern against a term, binding the pattern's variables.
The term's own variables are constants to the match.
| PARAMETER | DESCRIPTION |
|---|---|
pattern
|
The pattern.
TYPE:
|
term
|
The term.
TYPE:
|
bindings
|
Bindings that must hold.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Term] | None
|
The bindings, or None when the term is no instance. |
Source code in src/quivers/dsl/lexical/terms.py
rename
¶
Rename every variable apart by a suffix.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The term.
TYPE:
|
suffix
|
Appended to each variable's name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
The renamed term. |
Source code in src/quivers/dsl/lexical/terms.py
render
¶
render(term: Term) -> str
Spell a term as source writes it.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The term.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The spelling. |
Source code in src/quivers/dsl/lexical/terms.py
substitute
¶
Replace variables by terms.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The term.
TYPE:
|
mapping
|
The replacement of each variable; others stay.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
The term after replacement. |
Source code in src/quivers/dsl/lexical/terms.py
to_meaning
¶
to_meaning(term: Term, line: int = 0, col: int = 0) -> LetExprNode
Write a term as a lexical meaning.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The term.
TYPE:
|
line
|
The line the expression carries.
TYPE:
|
col
|
The column the expression carries.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LetExprNode
|
The meaning. |
Source code in src/quivers/dsl/lexical/terms.py
to_object
¶
to_object(term: Term, line: int = 0, col: int = 0) -> ObjectExpr
Write a term as an object expression.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The term.
TYPE:
|
line
|
The line the expression carries.
TYPE:
|
col
|
The column the expression carries.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ObjectExpr
|
The expression. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the term is a string, which no category spells. |
Source code in src/quivers/dsl/lexical/terms.py
unify
¶
A most general unifier of two terms, with the occurs check.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
One term.
TYPE:
|
right
|
The other; its variables are distinct from the first's when the caller renamed them apart.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Term] | None
|
The unifier, fully applied, or None when the terms do not unify. |
Source code in src/quivers/dsl/lexical/terms.py
variables_of
¶
variables_of(term: Term) -> tuple[str, ...]
The variables of a term, in order of first occurrence.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The term.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The variables. |
Source code in src/quivers/dsl/lexical/terms.py
attested_categories
¶
attested_categories(seeds: Iterable[Term], rules: Sequence[CategoryRule], bound: int) -> frozenset[Term]
The categories a grammar attests up to a depth bound.
| PARAMETER | DESCRIPTION |
|---|---|
seeds
|
The categories of the monomorphic lexical entries.
TYPE:
|
rules
|
The deduction's rules on categories.
TYPE:
|
bound
|
The largest constructor depth of a derived category.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
frozenset[Term]
|
Every derived category and every part of one. |
Source code in src/quivers/dsl/lexical/universe.py
category_of
¶
The category of a span item, or None for another item.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
An item pattern.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term | None
|
Its category slot. |
Source code in src/quivers/dsl/lexical/universe.py
category_rule
¶
category_rule(name: str, premises: Sequence[Term], conclusion: Term) -> CategoryRule | None
Read a rule on categories, when every item of it is a span.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The rule.
TYPE:
|
premises
|
Its premise items.
TYPE:
|
conclusion
|
Its conclusion item.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CategoryRule | None
|
The rule on categories, or None when an item is not a span. |
Source code in src/quivers/dsl/lexical/universe.py
expand
¶
Expand a module's deductions into plain ones.
expand_lexical runs before the structure layer, the meta phase, and the
compiler, after deduction composition, so every engine and transpile
target reads deductions with no category sets, semantics, templates,
polymorphic entries, lexical rules, featured atoms, or refinements. A
deduction that uses none of them is left exactly as written. For one that
does, expansion:
- inherits, for a refinement, every part of its base it does not restate;
- reads its templates and entries as schemas, and instantiates each entry at every assignment of its category variables, synthesizing meanings by meta computations;
- checks every meaning against its category's semantic type, when the deduction declares semantics;
- closes the lexicon under its compiled lexical rules;
- instantiates its rules over feature variables, and writes every featured atom as the atom it stands for;
- adds the entries its lexical rules in chart mode derive, each naming its rule;
- for a refinement, checks that it only restricts its base and generates its forgetful map and the transport of the base's derived instances;
- for a deduction with a lazily instantiated entry or a lexical rule in
chart mode, builds the agenda plan the agenda engine runs in its place
(
quivers.dsl.ast_nodes.plans): the placeholders and the rules specialized to them, and the wrapped lexical items with the lift and the chart rules. The plan's atoms and rules never leave the engine, so the deduction every other reader sees has every instance as an entry.
NORMALIZE_OPTION
module-attribute
¶
The option whose lhs reading groups productions by left-hand side.
LexicalExpansion
didactic-model
¶
LexicalExpansion(*, module: Module = field(opaque=True, extras=OPAQUE_BY_VALUE), refinements: Mapping[str, Refinement] = field(opaque=True, default_factory=dict, extras=OPAQUE_BY_VALUE), plans: Mapping[str, AgendaPlan] = field(opaque=True, default_factory=dict, extras=OPAQUE_BY_VALUE))
Bases: ValueModel
A module with plain deductions, the refinements it declares, and agenda plans.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module.
TYPE:
|
refinements
|
The forgetful map of each refined deduction, by name.
TYPE:
|
plans
|
The deduction the agenda engine runs in place of each deduction with a lazily instantiated entry or a lexical rule in chart mode, by name.
TYPE:
|
uses_lexical_surface
¶
uses_lexical_surface(declaration: DeductionDecl) -> bool
Whether a deduction uses anything expansion rewrites.
| PARAMETER | DESCRIPTION |
|---|---|
declaration
|
The deduction.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Whether it declares category sets, semantics, templates, lexical rules, featured atoms, or a base, or has a polymorphic entry or an entry naming a weight family. |
Source code in src/quivers/dsl/lexical/expand.py
expand_lexical
¶
expand_lexical(module: Module, *, module_name: str, file_path: str) -> LexicalExpansion
Expand every deduction of a module into a plain one.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module, its deductions composed.
TYPE:
|
module_name
|
The module's name, for the meta phase.
TYPE:
|
file_path
|
The path recorded on diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LexicalExpansion
|
The module, each deduction that used lexical surface replaced by its expansion and followed by what its refinement generates, the refinements' forgetful maps, and the agenda plans. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If any deduction's expansion is refused; the message names the deduction, the part refused, and the property it lacks. |
Source code in src/quivers/dsl/lexical/expand.py
refinement
¶
Refinements: deductions that add features to the atoms of a base.
refines Base makes a deduction an ornament of Base's item family
[@dagand2014transporting]: it declares features on some of the base's
atoms (atoms NP[num : Num]), so each refined category is a base
category with feature values, and the refined deduction's rules and
lexicon are those of the base written over refined categories. The
erasure of the ornament, the forgetful map, sends NP__sg (NP[sg]) to NP
and every other symbol to itself.
A refinement inherits every part of the base it does not restate: rules, entries, templates, lexical rules, category sets, and semantics. A base rule or entry that mentions an atom the refinement gives features is inherited only when restated, since its features are not determined; a rule is restated by declaring one of the same name. The compiler checks the restriction: the forgetful image of every rule of the refined deduction is an instance of a rule of the base, and the image of every lexical entry is an entry of the base, so the image of every refined derivation is a base derivation and the refined grammar's language is a subset of the base's.
The forgetful map is generated on items, as the derived instance
R.Item.forget (class Forget of the meta library), and on host
derivations, as Refinement.forget_derivation. Functions over the base's
items transport along it: every class the base derives for its item family
is derived for the refinement's, a signature morphism (Quote,
Include) by Dagand and McBride's transport, which keeps the base's
algebra and recurs over the refined family, and a module test states that
the transported reification agrees with the base's after forgetting.
Derivation
didactic-model
¶
Derivation(*, item: Hashable = field(opaque=True, extras=OPAQUE_BY_IDENTITY), rule: str = '', premises: tuple[Derivation, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE))
Bases: ValueModel
A derivation read off a chart: an item, its rule, its premises.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
The item derived, in the chart's representation. It may be any hashable host value and is compared by identity.
TYPE:
|
rule
|
The rule applied, or empty for a lexical axiom.
TYPE:
|
premises
|
The derivations of its premises, in order.
TYPE:
|
Refinement
didactic-model
¶
Refinement(*, name: str, base: str, atom_images: Mapping[str, str] = field(opaque=True, extras=OPAQUE_BY_VALUE), rule_images: Mapping[str, str] = field(opaque=True, extras=OPAQUE_BY_VALUE))
Bases: ValueModel
The forgetful map of one refinement.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The refined deduction.
TYPE:
|
base
|
The deduction it refines.
TYPE:
|
atom_images
|
Each atom of the refinement that is not one of the base's, with the base atom it forgets to.
TYPE:
|
rule_images
|
Each rule of the refinement with the base rule it maps to.
TYPE:
|
forget
¶
The forgetful image of a category, item, or rule pattern.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
A term of the refinement.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
The base term. |
Source code in src/quivers/dsl/lexical/refinement.py
forget_item
¶
The forgetful image of a chart item, as the agenda engine holds it.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
A refined item: a tuple whose atoms are
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Hashable
|
The base item. |
Source code in src/quivers/dsl/lexical/refinement.py
forget_derivation
¶
forget_derivation(derivation: Derivation) -> Derivation
The forgetful image of a derivation.
| PARAMETER | DESCRIPTION |
|---|---|
derivation
|
A derivation in the refined deduction's chart.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Derivation
|
Its image: every item forgotten, every rule its base rule. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the derivation applies a rule the refinement does not have. |
Source code in src/quivers/dsl/lexical/refinement.py
inherit
¶
inherit(refined: DeductionDecl, base: DeductionDecl, featured: frozenset[str], is_base_atom: Callable[[str], bool]) -> DeductionDecl
A refinement with the parts of its base it does not restate.
| PARAMETER | DESCRIPTION |
|---|---|
refined
|
The refinement as written.
TYPE:
|
base
|
The base as written.
TYPE:
|
featured
|
The atoms the refinement gives features.
TYPE:
|
is_base_atom
|
Whether a name is an atom of the base.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DeductionDecl
|
The refinement with the base's atoms, binders, rules, entries, templates, lexical rules, category sets, and semantics it does not restate, keeping the refinement's own first. A base part that reads a featured atom bare is not inherited, since the refinement gives that atom no bare reading: a rule, lexical rule, or category set that names one, a template or entry whose category names one, and anything that ranges over or names a category set or template that is not inherited for that reason. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the base has a part the refinement cannot read: a lexicon file. |
Source code in src/quivers/dsl/lexical/refinement.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 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 304 305 306 307 308 309 310 311 312 313 314 315 | |
check_restriction
¶
check_restriction(refinement: Refinement, rules: Sequence[SequentRule], entries: Sequence[LexiconEntry], base: DeductionDecl, is_atom: Callable[[str], bool], is_base_atom: Callable[[str], bool], sources: Mapping[str, str]) -> dict[str, str]
Check that a refinement only restricts its base; map its rules.
| PARAMETER | DESCRIPTION |
|---|---|
refinement
|
The refinement's forgetful map on atoms.
TYPE:
|
rules
|
The refinement's expanded rules.
TYPE:
|
entries
|
Its expanded lexicon.
TYPE:
|
base
|
The expanded base.
TYPE:
|
is_atom
|
Whether a name is an atom of the refinement.
TYPE:
|
is_base_atom
|
Whether a name is an atom of the base.
TYPE:
|
sources
|
Each expanded rule's written rule, for preferring a base rule of the same name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, str]
|
Each refined rule's base rule. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If a rule's image is an instance of no base rule, naming the rule and its image, or an entry's image is no base entry. |
Source code in src/quivers/dsl/lexical/refinement.py
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 431 432 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 | |
transport_guard
¶
transport_guard(declaration: QiecComputationDecl, name: str, base: str, refined: str, preimages: Mapping[str, tuple[str, ...]]) -> QiecComputationDecl
A guard over a base's items transported to a refinement's items.
A guard may not call another computation, so it cannot read its matched items through the forgetful map. It is transported the way Dagand and McBride transport a function defined by case analysis: each branch on a base constructor becomes a branch on every refined constructor that forgets to it, so the transported guard on a refined item decides what the base guard decides on its image.
| PARAMETER | DESCRIPTION |
|---|---|
declaration
|
The base guard.
TYPE:
|
name
|
The transported guard's name.
TYPE:
|
base
|
The base deduction.
TYPE:
|
refined
|
The refinement.
TYPE:
|
preimages
|
Each base symbol with the refined symbols that forget to it.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
QiecComputationDecl
|
The transported guard. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the guard builds a base item, which has no single refinement. |
Source code in src/quivers/dsl/lexical/refinement.py
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 | |
transport_weight
¶
transport_weight(declaration: QiecComputationDecl, name: str, base: str, refined: str) -> str
A computed rule weight over a base's items, read on a refinement's.
The weight is a computation, which may call others, so it transports by precomposition: the transported weight forgets each item it is given and calls the base weight.
| PARAMETER | DESCRIPTION |
|---|---|
declaration
|
The base weight.
TYPE:
|
name
|
The transported weight's name.
TYPE:
|
base
|
The base deduction.
TYPE:
|
refined
|
The refinement.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The transported weight's source. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the weight takes static parameters, which a rule weight does not. |
Source code in src/quivers/dsl/lexical/refinement.py
categories
¶
Declared category sets: regular sets of terms over a deduction's atoms.
categories Conj = S, N, Bwd(Conj, Arg) declares the least set of terms
holding S, N, and every Bwd(c, a) with c in Conj and
a in Arg. A member names a set (itself or another) wherever it
takes any element of that set, so a declaration is a regular tree grammar
whose nonterminals are the sets. Membership of a term is
decided by recursion on the term; a set is finite when no set reaches
itself through a member, and a finite set is enumerated.
CategorySets
¶
CategorySets(declarations: Iterable[CategorySetDecl], is_atom: Callable[[str], bool], owner: str)
The category sets of one deduction.
| PARAMETER | DESCRIPTION |
|---|---|
declarations
|
The
TYPE:
|
is_atom
|
Whether a name is one of the deduction's atoms.
TYPE:
|
owner
|
The deduction, for diagnostics.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If two sets share a name, a set is named like an atom, a member names something that is neither an atom nor a set, or a set is a member of itself without a constructor in between (so membership would not be decided by recursion on terms). |
Source code in src/quivers/dsl/lexical/categories.py
finite
cached
property
¶
The sets no set reaches itself from: the finite ones.
| RETURNS | DESCRIPTION |
|---|---|
frozenset[str]
|
Their names. |
__contains__
¶
Whether a set of that name is declared.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Whether it names a set. |
Source code in src/quivers/dsl/lexical/categories.py
require
¶
Refuse a name that is no declared set.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name.
TYPE:
|
line
|
Where it is used.
TYPE:
|
col
|
Where it is used.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If no category set has that name. |
Source code in src/quivers/dsl/lexical/categories.py
contains
¶
contains(name: str, term: Term) -> bool
Whether a ground term belongs to a set.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The set.
TYPE:
|
term
|
The term.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Membership. |
Source code in src/quivers/dsl/lexical/categories.py
enumerate
¶
enumerate(name: str) -> tuple[Term, ...]
Every member of a finite set, in declaration order.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The set.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Term, ...]
|
Its members, each once. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the set is infinite. |
Source code in src/quivers/dsl/lexical/categories.py
describe
¶
Spell a set's declaration.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The set.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/lexical/categories.py
empty_sets
¶
empty_sets(owner: str) -> CategorySets
No category sets.
| PARAMETER | DESCRIPTION |
|---|---|
owner
|
The deduction, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CategorySets
|
The empty collection. |
Source code in src/quivers/dsl/lexical/categories.py
binder_sets
¶
binder_sets(binders: Mapping[str, str], sets: CategorySets, line: int, col: int) -> None
Refuse binders over undeclared sets.
| PARAMETER | DESCRIPTION |
|---|---|
binders
|
Each category variable's set.
TYPE:
|
sets
|
The deduction's sets.
TYPE:
|
line
|
Where the binders are written.
TYPE:
|
col
|
Where the binders are written.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If a set is undeclared. |
Source code in src/quivers/dsl/lexical/categories.py
universe
¶
The categories a deduction attests: the range of an infinite category set.
A category variable over a finite set takes each member of the set. Over an infinite set it takes the members the grammar attests: the categories the deduction's rules derive from the categories of its monomorphic lexical entries, together with every part of one, up to a constructor depth bound. The derivation is read on categories alone, with positions and meanings ignored, so the attested categories include every category a chart over any sentence can hold within the bound.
SPAN_HEAD
module-attribute
¶
The head of the items a lexicon yields: span(i, j, category[, meaning]).
CategoryRule
didactic-model
¶
category_of
¶
The category of a span item, or None for another item.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
An item pattern.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term | None
|
Its category slot. |
Source code in src/quivers/dsl/lexical/universe.py
category_rule
¶
category_rule(name: str, premises: Sequence[Term], conclusion: Term) -> CategoryRule | None
Read a rule on categories, when every item of it is a span.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The rule.
TYPE:
|
premises
|
Its premise items.
TYPE:
|
conclusion
|
Its conclusion item.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CategoryRule | None
|
The rule on categories, or None when an item is not a span. |
Source code in src/quivers/dsl/lexical/universe.py
subterms
¶
attested_categories
¶
attested_categories(seeds: Iterable[Term], rules: Sequence[CategoryRule], bound: int) -> frozenset[Term]
The categories a grammar attests up to a depth bound.
| PARAMETER | DESCRIPTION |
|---|---|
seeds
|
The categories of the monomorphic lexical entries.
TYPE:
|
rules
|
The deduction's rules on categories.
TYPE:
|
bound
|
The largest constructor depth of a derived category.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
frozenset[Term]
|
Every derived category and every part of one. |
Source code in src/quivers/dsl/lexical/universe.py
entries
¶
Lexicon entries after templates, polymorphism, and synthesis.
An Instance is one monomorphic lexical entry: a word, a ground category,
a meaning, and the weights it reads. instances turns a deduction's
written lexicon into instances. A template entry takes its template's
category and its template's meaning at the entry's meaning. A polymorphic
entry becomes one instance per assignment of category-set members to its
variables: a variable over a finite set takes every member, and a variable
over an infinite set takes the members the grammar attests up to the bound
(the entry's bound, else the deduction's depth). Every instance of
one entry reads one weight family, so the instances share their weight,
unless the entry is per_instance: then each instance reads the entry's
family at its instantiation (family_of_instance), a weight of its own.
A meaning may name a category variable, which stands for its category as
a term, and may call a meta computation on one, coord[X], which
synthesizes the meaning from the variable's semantic type.
ENTRY_OPTIONS
module-attribute
¶
The options a lexicon entry or a template may carry.
INSTANTIATIONS
module-attribute
¶
How a polymorphic entry is instantiated.
Instance
didactic-model
¶
Instance(*, word: str, category: Term, meaning: LetExprNode, learnable: bool = False, weights: tuple[str, ...] = (), apart: bool = False, source: int = 0, lazy: bool = False, line: int = 0, col: int = 0)
Bases: Model
One monomorphic lexicon entry.
| PARAMETER | DESCRIPTION |
|---|---|
word
|
The word.
TYPE:
|
category
|
The ground category.
TYPE:
|
meaning
|
The meaning.
TYPE:
|
learnable
|
Whether the instance has a learned weight of its own.
TYPE:
|
weights
|
The weight families it reads.
TYPE:
|
apart
|
Whether its entry weighs each instance apart (
TYPE:
|
source
|
The index of the written entry it comes from.
TYPE:
|
lazy
|
Whether its entry is instantiated lazily.
TYPE:
|
line
|
The written entry's line.
TYPE:
|
col
|
The written entry's column.
TYPE:
|
entry
¶
entry() -> LexiconEntry
The instance as a plain lexicon entry.
| RETURNS | DESCRIPTION |
|---|---|
LexiconEntry
|
The entry, with no option but |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the category cannot be written as a category. |
Source code in src/quivers/dsl/lexical/entries.py
Schema
didactic-model
¶
Schema(*, words: tuple[str, ...], binders: tuple[CategoryBinder, ...], category: Term, meaning: LetExprNode, options: tuple[OptionEntry, ...] = (), index: int = 0, line: int = 0, col: int = 0)
Bases: Model
A written entry read as a schema: binders, category, meaning, options.
| PARAMETER | DESCRIPTION |
|---|---|
words
|
Its words.
TYPE:
|
binders
|
Its category variables and their sets.
TYPE:
|
category
|
Its category, over the variables.
TYPE:
|
meaning
|
Its meaning.
TYPE:
|
options
|
Its options, template options first.
TYPE:
|
index
|
Its position in the lexicon.
TYPE:
|
line
|
Its line.
TYPE:
|
col
|
Its column.
TYPE:
|
family_of_entry
¶
The weight family every instance of a written entry reads.
| PARAMETER | DESCRIPTION |
|---|---|
index
|
The entry's position in the lexicon.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/lexical/entries.py
family_of_instance
¶
family_of_instance(index: int, assignment: Sequence[Term]) -> str
The weight family an instance of a per_instance entry reads.
The entry's family is indexed by the instantiation, as a rule schema's
#[shared = F(n)] is by its parameters, so each assignment of
categories to the entry's variables has a weight of its own, read by
the instance however the entry is instantiated.
| PARAMETER | DESCRIPTION |
|---|---|
index
|
The entry's position in the lexicon.
TYPE:
|
assignment
|
The categories its variables take, in binder order.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/lexical/entries.py
schemas
¶
schemas(declaration: DeductionDecl, is_atom: Callable[[str], bool], templates: Mapping[str, LexicalTemplate], owner: str) -> tuple[Schema, ...]
Read each written entry as a schema, applying templates.
| PARAMETER | DESCRIPTION |
|---|---|
declaration
|
The deduction.
TYPE:
|
is_atom
|
Whether a name is one of its atoms.
TYPE:
|
templates
|
Its templates, by name.
TYPE:
|
owner
|
The deduction, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Schema, ...]
|
One schema per written entry, in order. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If an entry has an unknown option, or a latent ( |
Source code in src/quivers/dsl/lexical/entries.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 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 | |
instances
¶
instances(schema: Schema, sets: CategorySets, attested: Callable[[int], frozenset[Term]], synthesize: Callable[[str, Term, str, int, int], LetExprNode], *, depth_bound: int | None, owner: str) -> tuple[Instance, ...]
The instances of one schema.
| PARAMETER | DESCRIPTION |
|---|---|
schema
|
The entry.
TYPE:
|
sets
|
The deduction's category sets.
TYPE:
|
attested
|
The categories the grammar attests up to a depth bound.
TYPE:
|
synthesize
|
Synthesizes a meaning:
TYPE:
|
depth_bound
|
The deduction's
TYPE:
|
owner
|
The deduction, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Instance, ...]
|
One instance per word and assignment, in order. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If a variable ranges over an undeclared set, over an infinite set with no bound, the category mentions a name that is neither an atom nor a variable, or the meaning uses a variable in a way no category spells. |
Source code in src/quivers/dsl/lexical/entries.py
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 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |
synthesis_calls
¶
synthesis_calls(meaning: LetExprNode, variables: frozenset[str]) -> bool
Whether a meaning calls a meta computation on a category variable.
| PARAMETER | DESCRIPTION |
|---|---|
meaning
|
The meaning.
TYPE:
|
variables
|
The category variables.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Whether some |
Source code in src/quivers/dsl/lexical/entries.py
lexical_rules
¶
Lexical rules: unary rules whose premise is a lexical item.
lexical rule r : span(I, J, NP, x) |- span(I, J, C, M) derives a
lexical item from a lexical item over the same span. A rule in compile
mode (the default) closes the lexicon when the deduction is expanded: each
entry the premise matches yields a new entry, and entries derived this way
are closed again, up to the rule's bound (one application by default).
A rule in chart mode is a weighted unary rule over lexical items
instead, applied to the lexicon's items and to the items the chart rules
derive from them, up to the largest bound of the chart rules, and to
nothing an ordinary rule derives; so the deduction is the one compile mode
gives with the same bound. The deduction every reader sees has the entries
it derives, each naming the rule (chart_lexicon); the agenda engine
applies it in the chart (quivers.dsl.ast_nodes.plans), where a lexical
item is wrapped as __lexical_item(C, __lexical_level_<d>), d the
number of chart rule applications that derived it, the generated rule
__lexical_lift unwraps it at any level, and the lexical rule has one
copy per level below the bound, taking a wrapped item at its level to one
at the next. Either way a learnable lexical rule has one learned weight,
the family __lexical_rule_<r>: an entry it derives multiplies it into
its source entry's weight, and every copy of the chart rule reads it.
RULE_OPTIONS
module-attribute
¶
The options a lexical rule takes.
WRAPPER
module-attribute
¶
The atom wrapping a lexical item's category when lexical rules run in the chart.
LEVEL
module-attribute
¶
The prefix of the atoms counting the chart rule applications behind a lexical item.
ReadRule
¶
ReadRule(rule: LexicalRuleDecl, is_atom: Callable[[str], bool], owner: str)
A lexical rule read as terms.
| PARAMETER | DESCRIPTION |
|---|---|
rule
|
The rule.
TYPE:
|
is_atom
|
Whether a name is an atom.
TYPE:
|
owner
|
The deduction, for diagnostics.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If an option is unknown or malformed, an item is not a span, the premise's positions are not variables, or the conclusion's span is not the premise's. |
Source code in src/quivers/dsl/lexical/lexical_rules.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
family
property
¶
The weight family the rule contributes, when it learns one.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
|
apply
¶
The entry the rule derives from one entry, if its premise matches.
| PARAMETER | DESCRIPTION |
|---|---|
instance
|
The entry.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Instance | None
|
The derived entry, reading the entry's weights and the rule's. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the conclusion's category is not ground. |
Source code in src/quivers/dsl/lexical/lexical_rules.py
level
¶
The atom marking a lexical item a number of chart rule applications derived.
| PARAMETER | DESCRIPTION |
|---|---|
depth
|
The number of applications.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/lexical/lexical_rules.py
wrapped
¶
A lexical item's category as the chart's lexical rules read it.
| PARAMETER | DESCRIPTION |
|---|---|
category
|
The category.
TYPE:
|
depth
|
The number of chart rule applications that derived the item.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
|
Source code in src/quivers/dsl/lexical/lexical_rules.py
chart_depth
¶
chart_depth(rules: Sequence[ReadRule]) -> int
The number of chart rule applications a lexical item may have behind it.
| PARAMETER | DESCRIPTION |
|---|---|
rules
|
The lexical rules in
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
Their largest |
Source code in src/quivers/dsl/lexical/lexical_rules.py
chart_atoms
¶
chart_atoms(rules: Sequence[ReadRule]) -> tuple[str, ...]
The atoms the chart's lexical rules add to a deduction's plan.
| PARAMETER | DESCRIPTION |
|---|---|
rules
|
The lexical rules in
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The wrapper and one level atom per depth, or none without rules. |
Source code in src/quivers/dsl/lexical/lexical_rules.py
family_of_rule
¶
The weight family of a learnable lexical rule.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The lexical rule.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/lexical/lexical_rules.py
compile_lexical_rules
¶
Close a lexicon under its compiled lexical rules.
Every entry first reads its own weight as the family of its written entry, so an entry a rule derives reads the same weight.
| PARAMETER | DESCRIPTION |
|---|---|
found
|
The lexicon's entries.
TYPE:
|
rules
|
The lexical rules in
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Instance, ...]
|
The entries, then the derived ones, chain by chain up to the
largest |
Source code in src/quivers/dsl/lexical/lexical_rules.py
share_weights
¶
Give every entry with a learned weight of its own its written entry's family.
An entry a lexical rule derives reads its source entry's weight, so the source's own weight becomes the family of its written entry, which both read.
| PARAMETER | DESCRIPTION |
|---|---|
found
|
The lexicon's entries.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Instance, ...]
|
The entries, each learnable one reading its written entry's family instead of a weight of its own. |
chart_lexicon
¶
chart_lexicon(found: Sequence[Instance], rules: Sequence[ReadRule]) -> tuple[tuple[Instance, str], ...]
The entries lexical rules in chart mode derive from a lexicon.
The chart rules close the lexicon as compiled rules do: each round
applies every rule to the entries the previous round derived, up to the
rules' largest bound.
| PARAMETER | DESCRIPTION |
|---|---|
found
|
The lexicon's entries, their weights shared (
TYPE:
|
rules
|
The lexical rules in
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[tuple[Instance, str], ...]
|
Each derived entry, reading its source's weights and the rule's, and the rule deriving it, chain by chain. |
Source code in src/quivers/dsl/lexical/lexical_rules.py
level_rule
¶
The plan's copy of a chart lexical rule taking items at one level.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The lexical rule.
TYPE:
|
depth
|
The level of the items the copy takes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/lexical/lexical_rules.py
chart_rules
¶
chart_rules(rules: Sequence[ReadRule]) -> tuple[SequentRule, ...]
The chart rules lexical rules in chart mode become.
| PARAMETER | DESCRIPTION |
|---|---|
rules
|
The lexical rules in
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[SequentRule, ...]
|
|
Source code in src/quivers/dsl/lexical/lexical_rules.py
wrap
¶
A lexical entry whose item lexical rules in the chart apply to.
| PARAMETER | DESCRIPTION |
|---|---|
instance
|
The entry.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Instance
|
The entry with its category wrapped at level zero,
|
Source code in src/quivers/dsl/lexical/lexical_rules.py
lazy
¶
Lazy instantiation: a polymorphic entry instantiated where a rule uses it.
Lazy instantiation is how the agenda engine runs a deduction, not a change
to the deduction: the deduction every other reader sees (the checked
elaboration, its item family, deriving, proofs, and every transpile target)
has each instance of the entry as an entry of its lexicon. The agenda
engine runs an agenda plan (quivers.dsl.ast_nodes.plans) instead, in which
a lazily instantiated entry contributes, for each meaning its instances
have, one item per token whose category __lazy_<k>_<m> stands for the
entry with its category variables unbound and whose meaning is the
instances' meaning. No instance of the entry is an axiom of that chart.
Instead each rule premise whose category unifies with an instance's
category is specialized: the specialized rule takes the placeholder item in
that position, keeps the premise's meaning pattern, and instantiates its
other premises and its conclusion by the unifier, so the variable is
instantiated by the items the rule meets in the chart, and an instance
enters the chart only as part of what a rule derives from it. The meaning
is never written into a rule, so it may hold binders. A specialized rule
reads its source rule's learned weight on the source's own bindings, so
lazy and bounded instantiation give every derived item the same weight. An
entry that weighs each instance apart (per_instance) has a placeholder
that weighs nothing, and a rule specialized to it also reads the consumed
instance's own weight (SpecializedWeight.entries), the one weight the
instance's axiom carries under bounded instantiation.
Every item and application the run hands out is read back through the
plan's reveal, which maps a placeholder to the instances it stands for and
a specialized application to its source rule's.
A specialized rule carries neither its source's guard nor its computed
weight (OPERATION_OPTIONS), whose signatures are the source rule's
telescope: the agenda engine runs the source rule's, read through the
plan's record of the rule's source, on the specialized rule's bindings and
the variables the specialization fixed.
A premise whose category is a variable nothing else constrains, or a
premise that is a bare variable, unifies with every instance, so it is
specialized to each, which is bounded instantiation for that rule alone.
Such a premise would also match the placeholder item itself, which stands
for every instance at once and is none of them; the agenda engine gives no
premise of a rule an item the plan generates unless the premise was
specialized to take it (quivers.dsl.compiler.deductions). A bare
premise binds a whole item, which a specialized rule has to spell; where a
term of the rule also holds the variable, the spelled item would hold its
chart positions as terms, so that rule is refused.
OPERATION_OPTIONS
module-attribute
¶
Rule options naming a computation over the rule's matched variables, which a specialized rule reads from its source rather than carrying.
Specialization
didactic-model
¶
Specialization(*, placeholders: tuple[Instance, ...] = (), rules: tuple[SequentRule, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE), instances: Mapping[str, Mapping[int, Term]] = field(default_factory=dict, opaque=True, extras=OPAQUE_BY_VALUE), names: tuple[str, ...] = (), consumed: Mapping[str, tuple[tuple[str, str, Term], ...]] = field(default_factory=dict, opaque=True, extras=OPAQUE_BY_VALUE))
Bases: ValueModel
What lazy instantiation adds to a deduction.
| PARAMETER | DESCRIPTION |
|---|---|
placeholders
|
One entry per word and meaning of each lazy entry, its category the placeholder atom and its meaning the instances' meaning.
TYPE:
|
rules
|
The specialized rules.
TYPE:
|
instances
|
Each specialized rule's instance category at each position that takes a placeholder, for reading a derivation back as one over the instances.
TYPE:
|
names
|
The placeholder atom of each lazy instance, in the order given.
TYPE:
|
consumed
|
Each specialized rule's consumed instances, in premise order: the placeholder, the word, and the instance category.
TYPE:
|
placeholder
¶
The atom standing for a lazily instantiated entry at one meaning.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The entry's position in the lexicon.
TYPE:
|
meaning_class
|
The position of the meaning (and the weights) among the entry's.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/lexical/lazy.py
specialize
¶
specialize(lazy: Sequence[Instance], rules: Sequence[SequentRule], is_atom: Callable[[str], bool], owner: str, *, wrap: Callable[[Term], Term] | None = None, suffix: str = 'lazy', per_word: bool = False) -> Specialization
The placeholder entries and specialized rules of lazy entries.
| PARAMETER | DESCRIPTION |
|---|---|
lazy
|
The instances of every lazily instantiated entry.
TYPE:
|
rules
|
The rules to specialize.
TYPE:
|
is_atom
|
Whether a name is an atom.
TYPE:
|
owner
|
The deduction, for diagnostics.
TYPE:
|
wrap
|
Wraps a lexical item's category when the rules take wrapped items
(lexical rules in the chart), or |
suffix
|
What a specialized rule's name adds to its source's.
TYPE:
|
per_word
|
Whether each word of an entry has a placeholder of its own, so a rule that consumes one knows the word: a grammar normalized per left-hand side reads the consumed instance's production, which is the word's.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Specialization
|
The placeholders, the specialized rules, and their instances. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If a premise that is a bare variable would be specialized while the variable also occurs inside a term of the rule. |
Source code in src/quivers/dsl/lexical/lazy.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 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 | |
features
¶
Atoms with features: atoms NP[num : Num] and categories NP[sg].
A featured atom is a family of atoms, one per assignment of members of its
feature sets, which must be finite sets of atoms: NP[sg] is the atom
NP__sg, and the item family of the deduction has one constructor per
such atom. A rule over feature variables (NP[n]) is one rule per
assignment of the variables, named r__<value>...; each variable takes
the members of every feature set it fills. Every occurrence of a featured
atom carries its features, so a featured atom written bare is refused.
Features
didactic-model
¶
Features(*, sets: Mapping[str, tuple[str, ...]] = field(opaque=True, extras=OPAQUE_BY_VALUE), values: Mapping[str, tuple[tuple[str, ...], ...]] = field(opaque=True, extras=OPAQUE_BY_VALUE))
Bases: ValueModel
The featured atoms of one deduction.
| PARAMETER | DESCRIPTION |
|---|---|
sets
|
Each featured atom's feature sets, in order.
TYPE:
|
values
|
Each featured atom's admissible values at each feature.
TYPE:
|
atoms
property
¶
The featured atoms.
| RETURNS | DESCRIPTION |
|---|---|
frozenset[str]
|
Their names. |
instances
¶
Every atom the featured atoms stand for, with the atom it refines.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, str]
|
|
Source code in src/quivers/dsl/lexical/features.py
ground
¶
Replace every featured atom of a ground term by its atom.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
A category or item.
TYPE:
|
where
|
Its owner, for diagnostics.
TYPE:
|
line
|
Where it is written.
TYPE:
|
col
|
Where it is written.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
The term over plain atoms. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If a featured atom is written bare, with the wrong number of features, or with a value outside its feature's set. |
Source code in src/quivers/dsl/lexical/features.py
variables
¶
variables(term: Term) -> dict[str, frozenset[str]]
The feature variables of a term and the values each may take.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
A rule's premise or conclusion.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, frozenset[str]]
|
Each variable filling a feature, with the values of every feature it fills. |
Source code in src/quivers/dsl/lexical/features.py
featured_name
¶
The atom a featured atom is at some feature values.
| PARAMETER | DESCRIPTION |
|---|---|
atom
|
The featured atom.
TYPE:
|
values
|
Its feature values, in order.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/dsl/lexical/features.py
read_features
¶
read_features(declared: Sequence[AtomFeatures], sets: CategorySets, owner: str) -> Features
Read a deduction's featured atoms.
| PARAMETER | DESCRIPTION |
|---|---|
declared
|
The featured atoms of its atoms lines.
TYPE:
|
sets
|
Its category sets.
TYPE:
|
owner
|
The deduction, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Features
|
The featured atoms. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If a feature's set is undeclared, infinite, or has a member that is not an atom, or an atom is declared with features twice. |
Source code in src/quivers/dsl/lexical/features.py
instantiate_rules
¶
instantiate_rules(rules: Sequence[SequentRule], features: Features, is_atom: Callable[[str], bool], owner: str) -> tuple[tuple[SequentRule, ...], dict[str, str]]
Each rule at every assignment of its feature variables.
| PARAMETER | DESCRIPTION |
|---|---|
rules
|
The rules.
TYPE:
|
features
|
The featured atoms.
TYPE:
|
is_atom
|
Whether a name is an atom.
TYPE:
|
owner
|
The deduction, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[tuple[SequentRule, ...], dict[str, str]]
|
The rules over plain atoms, and each rule's source rule by name. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If a featured atom is written bare or with values outside its sets, or a feature variable can take no value. |
Source code in src/quivers/dsl/lexical/features.py
semantics
¶
Semantic types of categories, and the typing check of lexical meanings.
semantics Ty and its clauses S => T, Fwd(A, B) => Arr(B, A)
give each category a semantic type by structural recursion: the first
clause whose category pattern matches gives the type, with each pattern
variable standing for the type of the category it matched. The types are
terms of the syntax the judgment Ty(ctx, term, type) types; every
meaning a deduction's lexicon assigns, written or synthesized, must have a
derivation of Ty in the empty context at the semantic type of its
category.
SemanticTypes
¶
SemanticTypes(declaration: SemanticsDecl, is_atom: Callable[[str], bool], judgments: Mapping[str, JudgmentSystem], owner: str)
The semantic types of one deduction's categories.
| PARAMETER | DESCRIPTION |
|---|---|
declaration
|
The
TYPE:
|
is_atom
|
Whether a name is one of the deduction's atoms.
TYPE:
|
judgments
|
The module's judgments.
TYPE:
|
owner
|
The deduction, for diagnostics.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the judgment is undeclared or is not |
Source code in src/quivers/dsl/lexical/semantics.py
type_of
¶
The semantic type of a ground category.
| PARAMETER | DESCRIPTION |
|---|---|
category
|
The category.
TYPE:
|
line
|
Where it is used.
TYPE:
|
col
|
Where it is used.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
Its type, a ground term of the judgment's syntax. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If no clause matches the category or one of its parts. |
Source code in src/quivers/dsl/lexical/semantics.py
check
¶
check(meaning: LetExprNode, category: Term, *, owner: str) -> None
Refuse a meaning without a typing at its category's type.
| PARAMETER | DESCRIPTION |
|---|---|
meaning
|
The meaning.
TYPE:
|
category
|
Its category.
TYPE:
|
owner
|
The entry, for diagnostics.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the meaning is not a term of the judgment's syntax, or has no derivation of the judgment at the category's type; the message names the type and the constraint that failed. |
Source code in src/quivers/dsl/lexical/semantics.py
judgment_systems
¶
judgment_systems(statements: Sequence[object]) -> dict[str, JudgmentSystem]
Build the judgment systems a module declares.
| PARAMETER | DESCRIPTION |
|---|---|
statements
|
The module's statements.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, JudgmentSystem]
|
Each judgment's system, by name. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If a syntax or a judgment does not compile. |
Source code in src/quivers/dsl/lexical/semantics.py
to_syntax
¶
A ground term as a term of a syntax.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The term, over the syntax's constructors.
TYPE:
|
signature
|
The syntax.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
The term. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the term has a variable or a head the syntax does not declare. |
Source code in src/quivers/dsl/lexical/semantics.py
synthesis
¶
Type-directed synthesis of lexical meanings by meta computations.
A polymorphic entry's meaning may call a meta computation on one of its
category variables, coord[X]. At each instance the computation runs in
the module's meta phase on the semantic type of the category X takes,
quoted as a SynValue (a nullary type constructor E as
ValueVar("E"), an applied one Arr(E, T) as
ValueCall("Arr", ...)), and returns the meaning, quoted the same way.
Generalized conjunction is the standard case: it recurs on the type
[@partee1983generalized]. The synthesized meaning is checked by the
deduction's typing judgment like a written one.
SYNTAX_VALUE
module-attribute
¶
The meta-phase family a synthesizer takes and returns.
SynthesisCall
didactic-model
¶
SynthesisCall(*, generator: str, argument: Term, owner: str, line: int = 0, col: int = 0)
Bases: Model
One meaning to synthesize.
| PARAMETER | DESCRIPTION |
|---|---|
generator
|
The meta computation.
TYPE:
|
argument
|
The semantic type it receives, a ground term.
TYPE:
|
owner
|
The entry the meaning is for, for diagnostics.
TYPE:
|
line
|
The call's line.
TYPE:
|
col
|
The call's column.
TYPE:
|
synthesize
¶
synthesize(module: Module, calls: Sequence[SynthesisCall], *, module_name: str, file_path: str) -> tuple[LetExprNode, ...]
Run each synthesis call in the module's meta phase.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module, whose meta declarations the calls may use.
TYPE:
|
calls
|
The calls, in order.
TYPE:
|
module_name
|
The module's name.
TYPE:
|
file_path
|
The path recorded on diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[LetExprNode, ...]
|
Each call's meaning, in order. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If a generator is not a meta computation from one |
Source code in src/quivers/dsl/lexical/synthesis.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
terms
¶
Categories, items, and meanings as first-order terms.
A deduction writes its categories and items as object expressions
(Fwd(S, NP), S \ NP, span(I, J, X, F)) and its lexical
meanings as let expressions (Lam(x, App(dog, x))). Expansion reasons
about both as first-order terms over the deduction's atoms: a name that is
not an atom is a variable. This module converts between the source forms
and Term, and implements the operations expansion needs on terms:
substitution, matching, unification, depth, and renaming.
Variable
didactic-model
¶
Node
didactic-model
¶
Node(*, head: str, args: tuple[Term, ...] = (), form: Literal['atom', 'apply', 'slash', 'features', 'integer', 'string'] = 'atom', kind: Literal['node'] = 'node')
Bases: Term
An atom, an application, a slash, or an atom at feature values.
| PARAMETER | DESCRIPTION |
|---|---|
head
|
The atom, the applied symbol, the slash (
TYPE:
|
args
|
The arguments; empty for an atom.
TYPE:
|
form
|
How the source spells it:
TYPE:
|
atom
¶
atom(name: str) -> Node
The atom of a name.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The atom.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Node
|
The atom as a term. |
apply
¶
from_object
¶
from_object(expr: ObjectExpr, is_atom: Callable[[str], bool], *, owner: str) -> Term
Read an object expression as a term.
| PARAMETER | DESCRIPTION |
|---|---|
expr
|
A category or an item.
TYPE:
|
is_atom
|
Whether a bare name is an atom rather than a variable.
TYPE:
|
owner
|
What the expression belongs to, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
The term. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the expression is not a category: a product, a coproduct, a space, or a schema spine. |
Source code in src/quivers/dsl/lexical/terms.py
to_object
¶
to_object(term: Term, line: int = 0, col: int = 0) -> ObjectExpr
Write a term as an object expression.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The term.
TYPE:
|
line
|
The line the expression carries.
TYPE:
|
col
|
The column the expression carries.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ObjectExpr
|
The expression. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the term is a string, which no category spells. |
Source code in src/quivers/dsl/lexical/terms.py
from_meaning
¶
from_meaning(node: LetExprNode, *, owner: str, variables: frozenset[str] = frozenset()) -> Term
Read a lexical meaning as a term.
A name is a variable when it is one of variables (a template's
parameter, a category variable); every other name is a constant: an
atom, or a name a binder binds.
| PARAMETER | DESCRIPTION |
|---|---|
node
|
The meaning.
TYPE:
|
owner
|
What the meaning belongs to, for diagnostics.
TYPE:
|
variables
|
The names that are variables.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
The term. |
| RAISES | DESCRIPTION |
|---|---|
LexicalError
|
If the meaning holds something other than constructor applications, names, integers, and strings. |
Source code in src/quivers/dsl/lexical/terms.py
to_meaning
¶
to_meaning(term: Term, line: int = 0, col: int = 0) -> LetExprNode
Write a term as a lexical meaning.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The term.
TYPE:
|
line
|
The line the expression carries.
TYPE:
|
col
|
The column the expression carries.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LetExprNode
|
The meaning. |
Source code in src/quivers/dsl/lexical/terms.py
substitute
¶
Replace variables by terms.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The term.
TYPE:
|
mapping
|
The replacement of each variable; others stay.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
The term after replacement. |
Source code in src/quivers/dsl/lexical/terms.py
variables_of
¶
variables_of(term: Term) -> tuple[str, ...]
The variables of a term, in order of first occurrence.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The term.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The variables. |
Source code in src/quivers/dsl/lexical/terms.py
depth
¶
depth(term: Term) -> int
The constructor depth of a term: an atom or a variable is 0.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The term.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The depth. |
Source code in src/quivers/dsl/lexical/terms.py
match
¶
match(pattern: Term, term: Term, bindings: Mapping[str, Term] | None = None) -> dict[str, Term] | None
Match a pattern against a term, binding the pattern's variables.
The term's own variables are constants to the match.
| PARAMETER | DESCRIPTION |
|---|---|
pattern
|
The pattern.
TYPE:
|
term
|
The term.
TYPE:
|
bindings
|
Bindings that must hold.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Term] | None
|
The bindings, or None when the term is no instance. |
Source code in src/quivers/dsl/lexical/terms.py
unify
¶
A most general unifier of two terms, with the occurs check.
| PARAMETER | DESCRIPTION |
|---|---|
left
|
One term.
TYPE:
|
right
|
The other; its variables are distinct from the first's when the caller renamed them apart.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Term] | None
|
The unifier, fully applied, or None when the terms do not unify. |
Source code in src/quivers/dsl/lexical/terms.py
rename
¶
Rename every variable apart by a suffix.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The term.
TYPE:
|
suffix
|
Appended to each variable's name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Term
|
The renamed term. |
Source code in src/quivers/dsl/lexical/terms.py
render
¶
render(term: Term) -> str
Spell a term as source writes it.
| PARAMETER | DESCRIPTION |
|---|---|
term
|
The term.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The spelling. |