Generic pattern_plugin implementation

This commit is contained in:
Tony Garnock-Jones 2023-11-10 23:19:22 +01:00
parent 1e9e60207b
commit 1d61ea0c8e
7 changed files with 19 additions and 7 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "syndicate-schema-plugin"
version = "0.1.0"
version = "0.2.0"
authors = ["Tony Garnock-Jones <tonyg@leastfixedpoint.com>"]
edition = "2018"

View File

@ -4,6 +4,9 @@ use preserves_schema::compiler::context::ModuleContext;
use preserves_schema::gen::schema::*;
use preserves_schema::syntax::block::escape_string;
use preserves_schema::syntax::block::constructors::*;
use preserves_schema::compiler::names;
use preserves_schema::compiler::types::definition_type;
use preserves_schema::compiler::types::Purpose;
use std::iter::FromIterator;
@ -29,12 +32,21 @@ impl Plugin for PatternPlugin {
if ctxt.mode == context::ModuleContextMode::TargetGeneric {
let mut s = WalkState::new(ctxt, ctxt.module_path.clone());
if let Some(p) = definition.wc(&mut s) {
let ty = definition_type(&ctxt.module_path,
Purpose::Codegen,
definition_name,
definition);
let v = syndicate::language().unparse(&p);
let v = preserves_schema::support::preserves::value::TextWriter::encode(
&mut preserves_schema::support::preserves::value::NoEmbeddedDomainCodec,
&v).unwrap();
ctxt.define_type(item(seq![
"impl ", definition_name.to_owned(), " ", codeblock![
"impl",
ty.generic_decl(ctxt),
" ",
names::render_constructor(definition_name),
ty.generic_arg(ctxt),
" ", codeblock![
seq!["#[allow(unused)] pub fn wildcard_dataspace_pattern() ",
"-> syndicate::schemas::dataspace_patterns::Pattern ",
codeblock![

View File

@ -15,7 +15,7 @@ jemalloc = ["dep:tikv-jemallocator"]
[build-dependencies]
preserves-schema = "4.991"
syndicate = { path = "../syndicate", version = "0.30.0"}
syndicate-schema-plugin = { path = "../syndicate-schema-plugin", version = "0.1.0"}
syndicate-schema-plugin = { path = "../syndicate-schema-plugin", version = "0.2.0"}
[dependencies]
preserves-schema = "4.991"

View File

@ -36,7 +36,7 @@ use syndicate_macros::during;
pub fn on_demand(t: &mut Activation, config_ds: Arc<Cap>) {
t.spawn(Some(AnyValue::symbol("config_watcher")), move |t| {
Ok(during!(t, config_ds, language(), <run-service $spec: internal_services::ConfigWatcher>, |t| {
Ok(during!(t, config_ds, language(), <run-service $spec: internal_services::ConfigWatcher::<AnyValue>>, |t| {
Supervisor::start(
t,
Some(rec![AnyValue::symbol("config"), AnyValue::new(spec.path.clone())]),

View File

@ -24,7 +24,7 @@ use syndicate_macros::during;
pub fn on_demand(t: &mut Activation, config_ds: Arc<Cap>, root_ds: Arc<Cap>) {
t.spawn(Some(AnyValue::symbol("daemon_listener")), move |t| {
Ok(during!(t, config_ds, language(), <run-service $spec: DaemonService>,
Ok(during!(t, config_ds, language(), <run-service $spec: DaemonService::<AnyValue>>,
enclose!((config_ds, root_ds) move |t: &mut Activation| {
supervise_daemon(t, config_ds, root_ds, spec)
})))

View File

@ -21,7 +21,7 @@ use syndicate_macros::during;
pub fn on_demand(t: &mut Activation, ds: Arc<Cap>) {
t.spawn(Some(AnyValue::symbol("tcp_relay_listener")), move |t| {
Ok(during!(t, ds, language(), <run-service $spec: TcpRelayListener>, |t| {
Ok(during!(t, ds, language(), <run-service $spec: TcpRelayListener::<AnyValue>>, |t| {
Supervisor::start(
t,
Some(rec![AnyValue::symbol("relay"), language().unparse(&spec)]),

View File

@ -25,7 +25,7 @@ use syndicate_macros::during;
pub fn on_demand(t: &mut Activation, ds: Arc<Cap>) {
t.spawn(Some(AnyValue::symbol("unix_relay_listener")), move |t| {
Ok(during!(t, ds, language(), <run-service $spec: UnixRelayListener>, |t| {
Ok(during!(t, ds, language(), <run-service $spec: UnixRelayListener::<AnyValue>>, |t| {
Supervisor::start(
t,
Some(rec![AnyValue::symbol("relay"), language().unparse(&spec)]),