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.
- Tile
Options - Per-tile template options (polytile.md §2.3): the hole delimiters, the directive sigil, and strictness.
Enums§
- Tile
Body Kind - How a tile body was written, so the printer can reproduce it.
- Tile
Piece - 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.spanis the tile statement’s position, used for diagnostics. - render_
template - Render pieces back to template text under
opts, the inverse ofparse_templateup 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 atile ... : jsonblock 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
tilestatement without the statement.textmay be multi-line; it is taken exactly, as a heredoc body is.