Tangling¶
tangle
¶
Tangling a literate .qvr.md module into QVR source.
A literate module is a Markdown document whose fenced qvr blocks, in
document order, are its code: the document tangles to one module, as a
literate program tangles to the program it describes. Its prose is metadata:
the tangled source keeps every code line on the line it has in the document
and replaces every other line by an empty one, so a diagnostic names the
document's own line and an edit to the prose changes no declaration and no
content hash.
The blocks that tangle are the module's code blocks: unmarked ones and those
marked cumulative or qiec-cumulative. A block marked false,
standalone, or qiec is a separate fragment, an example fence is
a test, and a --8<-- include shows a corpus file; none of these is code
of the module.
LITERATE_SUFFIX
module-attribute
¶
The file suffix of a literate module.
is_literate_path
¶
Whether a path names a literate module.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
A file path.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True when the file name ends in |
Source code in src/quivers/dsl/literate/tangle.py
module_stem
¶
The module name of a .qvr or .qvr.md file.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
The file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The file name without |
Source code in src/quivers/dsl/literate/tangle.py
code_blocks
¶
code_blocks(text: str) -> tuple[FencedBlock, ...]
The blocks a literate document tangles.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The document.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[FencedBlock, ...]
|
Its code blocks, in document order. |
Source code in src/quivers/dsl/literate/tangle.py
tangle
¶
The QVR source a literate document tangles to.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The document.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
One line per document line: a code block's line with the fence's indentation removed, and an empty line for every other line, so the source's line numbers are the document's. |
Source code in src/quivers/dsl/literate/tangle.py
read_module_text
¶
The QVR source of a module file, tangling a literate one.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
A
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The file's text, or the source a |
| RAISES | DESCRIPTION |
|---|---|
OSError
|
If the file cannot be read. |