Skip to main content

sim_lib_topology/
text.rs

1//! Tiny line-oriented topology DSL.
2
3use sim_kernel::{Cx, Expr, Result};
4
5use crate::{Graph, TopologyConnection, connection_from_graph};
6
7mod data;
8mod parser;
9mod value;
10
11pub use data::graph_to_expr;
12pub use parser::graph_from_text;
13
14/// Parses topology text and returns canonical graph data.
15pub fn parse_text(source: &str) -> Result<Expr> {
16    graph_from_text(source).map(|graph| graph_to_expr(&graph))
17}
18
19/// Parses topology text and returns a runnable topology connection.
20pub fn from_text(cx: &mut Cx, source: &str) -> Result<TopologyConnection> {
21    let graph: Graph = graph_from_text(source)?;
22    connection_from_graph(cx, &graph)
23}