Skip to main content

polydat_core/dsl/
mod.rs

1// Copyright 2024-2026 Jonathan Shook
2// SPDX-License-Identifier: Apache-2.0
3
4//! Polydat DSL: lexer, parser, and AST for `.polydat` kernel definition files.
5
6// The language itself lives in `polydat_grammar`: the lexer, the
7// parser, the AST, the pretty-printer, the free-name collector,
8// pragmas, the diagnostic types, and the tile template
9// parsers. Each is reachable here at the path it always had.
10pub use polydat_grammar::{
11    ast, error, lexer, parser, pprint, pragmas, refs, tile, tile_structural,
12};
13
14pub mod compile;
15pub mod const_constraints;
16pub mod cursor_sugar;
17pub mod events;
18pub mod factories;
19/// External-facing factory module. Made `pub` (was `pub(crate)`) so
20/// crates that host polydat nodes outside the polydat crate
21/// (host runtimes) can reach `ConstArg`, `compile_ctx`,
22/// and `build_node` from their `register_nodes!` invocations.
23pub mod factory;
24pub mod registry;
25pub mod tile_lower;
26pub mod transform;
27pub mod traversal;
28pub(crate) mod validate;
29
30pub mod stub;
31
32/// Re-exported for external crates that register Polydat nodes via `register_nodes!`.
33pub use factory::ConstArg;
34mod binding;
35mod modules;
36
37pub use compile::{
38    CompileOptions, compile_ast_with_engine, compile_ast_with_options, compile_polydat,
39    compile_polydat_checked, compile_polydat_kernel, compile_polydat_kernel_with_options,
40    compile_polydat_kernel_with_tiles, compile_polydat_with, compile_polydat_with_engine,
41    compile_polydat_with_options, eval_const_expr,
42};
43// The deprecated forms stay reachable at their old paths; a caller sees
44// the deprecation at its own use.
45#[allow(deprecated)]
46pub use compile::{
47    compile_polydat_strict, compile_polydat_with_libs, compile_polydat_with_libs_and_limit,
48    compile_polydat_with_outputs, compile_polydat_with_path,
49};
50
51/// Collect identifier references from an `Expr` tree into `out`.
52///
53/// Walks every `Ident`, function call argument, binary/unary
54/// operand, array element, and field-access source. String-
55/// literal placeholders (`{name}` form) contribute their
56/// identifier-shaped placeholder bodies.
57///
58/// Cross-crate consumers (e.g. the host's SRD-13f
59/// synthesizer) use this to discover transitive wire refs from
60/// a binding's RHS without depending on the private `validate`
61/// module.
62pub fn collect_expr_references(expr: &ast::Expr, out: &mut std::collections::HashSet<String>) {
63    validate::collect_references(expr, out);
64}
65
66/// Return the embedded standard library module sources.
67///
68/// Each entry is `(filename, source_text)` — the same data used by the
69/// compiler's module resolver at build time.
70pub fn stdlib_sources() -> &'static [(&'static str, &'static str)] {
71    compile::stdlib_sources()
72}