Skip to main content

SourceParser

Trait SourceParser 

Source
pub trait SourceParser: Send + Sync {
    // Required methods
    fn parse_html(
        &self,
        src: &str,
        fragments: &FragmentTable,
    ) -> Result<LayoutIR, String>;
    fn parse_css(&self, src: &str) -> Result<Stylesheet, String>;
    fn resolve_includes(
        &self,
        src: &str,
        self_path: &Path,
        out: &mut Vec<PathBuf>,
    ) -> Result<String, String>;
    fn resolve_css_imports(
        &self,
        src: &str,
        self_path: &Path,
        out: &mut Vec<PathBuf>,
    ) -> Result<String, String>;
    fn parse_html_with_loader(
        &self,
        src: &str,
        self_path: &Path,
        fragments: &FragmentTable,
    ) -> Result<LayoutIR, String>;
    fn collect_fragments(
        &self,
        src: &str,
        self_path: &Path,
    ) -> Result<FragmentTable, String>;
    fn block_fragments(
        &self,
        src: &str,
        uri: &str,
        blocks: Vec<MarkupBlock>,
    ) -> Result<FragmentTable, String>;
    fn script_refs(
        &self,
        src: &str,
        self_path: &Path,
    ) -> Result<ScriptRefs, String>;
    fn link_fragments(
        &self,
        table: FragmentTable,
    ) -> Result<FragmentTable, String>;
}
Expand description

The markup/CSS front-end, injected by whoever drives the runtime from source. Implemented in lumenc (LumencParser) over its roxmltree markup parser, the hand-rolled CSS parser, the <include> / @import resolver, and the real-filesystem FsLoader.

Errors are surfaced as String (rendered from the front-end’s own error types) so the trait carries no dependency on the parser’s error model.

Required Methods§

Source

fn parse_html( &self, src: &str, fragments: &FragmentTable, ) -> Result<LayoutIR, String>

Parse markup text (with <include> directives already spliced away) into a LayoutIR, instantiating any of fragments it names.

Source

fn parse_css(&self, src: &str) -> Result<Stylesheet, String>

Parse CSS text into a Stylesheet.

Source

fn resolve_includes( &self, src: &str, self_path: &Path, out: &mut Vec<PathBuf>, ) -> Result<String, String>

Resolve <include src="..."> directives in src against self_path’s directory (real filesystem). Every resolved file path is appended to out so the hot-reload watcher can poll it.

Source

fn resolve_css_imports( &self, src: &str, self_path: &Path, out: &mut Vec<PathBuf>, ) -> Result<String, String>

Resolve @import "..." directives in src against self_path. Every imported file path is appended to out.

Source

fn parse_html_with_loader( &self, src: &str, self_path: &Path, fragments: &FragmentTable, ) -> Result<LayoutIR, String>

Parse markup, resolving <include> directives against self_path’s directory via the real-filesystem loader (the file-based-pages assembly path).

Source

fn collect_fragments( &self, src: &str, self_path: &Path, ) -> Result<FragmentTable, String>

Read the fragments src declares, without building its tree. An app collects these from every one of its .lmn files so a fragment declared in one is usable from all of them.

Source

fn block_fragments( &self, src: &str, uri: &str, blocks: Vec<MarkupBlock>, ) -> Result<FragmentTable, String>

Build the fragments the markup blocks of one script declare. The blocks are what the script’s language read out of src (candela’s lmn!); this front-end turns each block’s markup into a fragment. uri is where the script came from, and lands on each fragment’s origin, at the line src holds the block on. An app collects these alongside what its markup declares, so a shipped artifact carries every fragment and parses no markup itself.

Source

fn script_refs(&self, src: &str, self_path: &Path) -> Result<ScriptRefs, String>

Read the <script> elements src names, without building its tree. Markup names a script component by writing the function as a tag, so the scripts are read before the tree and their blocks are in the table the parse instantiates against.

Expand the use sites the fragment bodies hold against each other, so every body is the whole subtree it stands for. An artifact carries the linked table, which is what lets a shipped app instantiate with no parser.

Implementors§