Skip to main content

Crate compmd

Crate compmd 

Source
Expand description

The CompMD processor: parses, validates and expands documents written in CompMD (Component Markdown), as the CompMD specification describes, at the version SPEC_VERSION names.

It implements stages 1 to 4b, everything up to rendering, as the states of a Processor: parsing gives a document’s tree, resolving loads its imports and binds every component name, validating checks it against the signatures, loading gives the inputs their values and loads the data, and expanding makes the expanded tree a renderer draws, for one render context; every stage adds its diagnostics. Expressions follow the CompMD CEL profile, with the md. functions (spec §8.2).

The processor does no I/O: the caller hands it files, packs, remote and host data, and the time zones, through the traits of host, so it runs anywhere, a browser among them.

use compmd::{ParseOptions, Processor};

let parsed = Processor::new("a.comp.md", ":: chart[Weekly installs] {src=installs.csv}\n")
    .parse(&ParseOptions::default());
let json = serde_json::to_value(parsed.tree()).unwrap();
assert_eq!(json["children"][0]["type"], "componentLeaf");

Re-exports§

pub use processor::Processor;
pub use compmd_pack as pack;

Modules§

analysis
Component analysis (spec §7.1, §13.1): each host-language component checked against its signature fence, W104 where they disagree. The processor reads no JavaScript: the host gives what a component takes, read from its code (ComponentProps), and only what the code states is checked: a prop’s name always, its type where the code gives one.
cel
The CompMD CEL profile (spec §8.2): a parser, a type-checker that runs before evaluation, and an evaluator with a work budget. Every error is an F024, with the column it is at.
components
The components a document can name (spec §6.3), for a tool that lists them: grouped by the file that defines them, each with its kind, its signature and where the document uses it.
context
The render context (spec §8.5): what a render depends on besides the document, its imports and its data.
diagnostic
Diagnostics (spec §10) in the machine form of spec §10.5.
evaluations
What the last render evaluated in the processed document (spec §8.1, §8.2): each interpolation and each expression param written in it, with the value it gave and how many times it was evaluated, for an editor that shows a value beside what gave it.
expand
Stage 4b, evaluating (spec §8, §9, §11, §12.3): the expanded tree. Every compmd definition, if, each, value and interpolation is replaced by what it produces; box, the input components and host-language components stay as nodes, their params evaluated. Then the layout checks (W114, W119) run on the result.
expanded
The expanded tree (spec §12.3), what stage 4b makes of a document: content only, with every compmd definition, if, each, value and interpolation replaced by what it produces. Components stay as nodes only where the processor renders them itself: box, the input components, and host-language components, with their params evaluated.
frontmatter
What a document’s frontmatter gives a render (spec §2.1, §6, §8.6, §8.7), for a tool that shows it: the author’s own fields (md.doc), the settings under md, each data import with what was loaded for it, and the inputs with their values; and the frontmatter as written, for a tool that rewrites it (Written).
functions
The functions an expression can call (spec §8.2), each with its signatures, what it gives and examples: the md. functions, the functions and methods the profile takes from CEL, and its macros. One catalog, for an editor’s completion and hover, a reference page and a language server; the processor’s own hints read it too.
hints
Positional hints: what is at a place in a processed document’s text, and what it takes. An editor shows a hint beside the text and offers its completions; a language server makes its hovers and completions of the same hint.
host
What a host provides. The processor does no I/O: it reads the document’s files, the packs, remote and host: data and the time zones through these traits, each on its own, so a stage takes only the ones it uses and a host can reuse an implementation, such as a pack store or a time zone database, in another host. () implements each as “none”, and maps implement the data traits for what a host holds in memory: HashMap<String, String> for files, HashMap<String, Vec<LoadedRelease>> for packs, HashMap<String, Fetched> for remote data by URL and HashMap<String, Json> for host data by source.
md
The md. functions of spec §8.2: dates in the render’s time zone, formatting by the document’s language, and the list functions. Signatures gives their types to the checker; Md, made for one render, evaluates them.
path_references
Every place a document reads a metadata path, md.doc.due_date (spec §8.1), and the edits that rename its key: for a host that lets a writer rename a field its documents read, and for an editor’s references and rename. The reads are found in the document’s expressions as the processor parses them ([crate::written_expressions]), so text that only looks like one, in a code block, in prose or inside a CEL string, isn’t one.
plain
A document as plain text and plain HTML (spec §14): what a plain CommonMark and GFM renderer shows of it, for an editor that shows how a document degrades, and its text as a reader reads it, for a search index or a preview.
policy
The host’s configuration of packs (spec §6.4, §15): which packs a document may import, how far each one’s code is trusted, the packs the host denies or left out, and the runtimes and libraries it provides component code (spec §7.6).
processor
The processor (spec §11), its stages as states: a Processor goes from New through Parsed, Resolved, Validated and Loaded to Expanded. Each stage takes the processor and gives it back in its next state, so the stages can only run in order; each state gives what its stage made, and every state the diagnostics so far. Each stage takes what it uses: the parse options; the host’s files and packs, and the ambient packs; the origins remote data may come from; the render context, and the host’s remote and host: data; the expansion options.
render
What a code block a code renderer renders shows: its render param (spec §7.7).
rendered_blocks
The code blocks code renderers render (spec §7.7), for an editor: each one’s language and where its text is, so an editor hands the requests inside it to the writer’s language server for that language (content languages in editors, decision 3).
tokens
Syntax tokens: where each span of CompMD’s own syntax is in a processed document, and what it is, by the names every grammar and the language server share (compmd-grammars’ syntax/tokens.json). A language server gives them as semantic tokens, which know more than a grammar can: whether a name stands for a component the document can use.
tree
The document tree (spec §12): mdast nodes for CommonMark and GFM, and CompMD’s own nodes.
unresolved_references
The references no definition resolves, for an editor (the language server, Q10): [text][label], [label][] and [label] whose label no link reference definition of the document defines. CommonMark makes such a reference text, so the tree has no node for it; the fork of markdown-rs says where each one is as it parses.
values
What a param’s value may be (spec §5.1, §7.3, §9.4), as one definition per kind of value: its tokens, the forms it takes besides them, and an example of those forms. Checking a value, the F009 message that says what a param takes, the suggestion of a misspelt token, and the params.json a renderer checks itself against all read it, so a token or a form is written down once.

Structs§

Ambient
The packs every document imports, at the lowest priority (spec §6.3), and whether to report their names.
ParseOptions
What a parse needs besides the text.
TextEdit
An edit of a document’s text: the code points start..end of the text the processor last saw became text.

Enums§

AllowedOrigins
The names packs and their files are known by: PackName, ReleaseId, FilePath, Place, Integrity. Where a processor may fetch a document’s remote data from; any other origin is F028.
Language
A host language a binding covers: the first word of a definition fence, or a component file’s extension.

Constants§

SPEC_VERSION
The version of the CompMD specification this processor implements (spec §1): a draft, 1.0-draft.N, until the spec’s version 1 is released. The spec is versioned on its own, apart from this crate.