Skip to main content

Module tile

Module tile 

Source
Expand description

Polytile at the host boundary (polytile.md §5.6): build a tile from template text, from structural JSON text, or from a parsed JSON value, then add it to a program with tile::add_tiles.

A host tile reaches a kernel the way every other host intention does, as a transform over the parsed program:

use polydat_core::dsl::{CompileOptions, compile_ast_with_engine, parse_polydat};
use polydat_core::tile::{Span, TileOptions, add_tiles, tile_from_text};

let tile = tile_from_text("greeting", "hi ${who}", &TileOptions::default(), Span::default())?;
let source = "input cycle: u64\nwho := \"world\"\n";
let mut program = parse_polydat(source)?;
add_tiles(&mut program, vec![tile])?;
let kernel = compile_ast_with_engine(
    &program,
    source,
    &CompileOptions::default(),
    None,
    polydat_core::Engine::default(),
)?;

There is no compile_with_tiles, deliberately. Adding tiles is one rewrite among the ones a host may want, and a dedicated entry point would be the only one that could not be combined with another. From add_tiles on, the tile is a tile statement like any the author wrote, and the program’s own typing and engine selection apply to it unchanged.

Re-exports§

pub use crate::dsl::transform::add_tiles;

Structs§

Span
A source location for error reporting.
TileDef
A tile definition: its header, its raw body, and the parsed template.
TileOptions
Per-tile template options (polytile.md §2.3): the hole delimiters, the directive sigil, and strictness.

Enums§

TileBodyKind
How a tile body was written, so the printer can reproduce it.
TilePiece
One element of a parsed template.

Constants§

ENCODINGS
The encodings a tile may declare.

Functions§

parse_template
Parse a tile body into pieces under opts. span is the tile statement’s position, used for diagnostics.
render_template
Render pieces back to template text under opts, the inverse of parse_template up to whitespace inside directives.
template_text_from_value
Turn a structural template into template text under options. The text is what an author would have written in a tile ... : json block for the same document.
tile_from_json_text
A tile from a structural template in JSON text (§3). The encoding is json.
tile_from_json_value
A tile from a structural template a host has already parsed (§3). The encoding is json.
tile_from_text
A tile from template text a host holds: the body of a tile statement without the statement. text may be multi-line; it is taken exactly, as a heredoc body is.