Generic pattern_plugin implementation
This commit is contained in:
parent
1e9e60207b
commit
1d61ea0c8e
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "syndicate-schema-plugin"
|
name = "syndicate-schema-plugin"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
authors = ["Tony Garnock-Jones <tonyg@leastfixedpoint.com>"]
|
authors = ["Tony Garnock-Jones <tonyg@leastfixedpoint.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,9 @@ use preserves_schema::compiler::context::ModuleContext;
|
||||||
use preserves_schema::gen::schema::*;
|
use preserves_schema::gen::schema::*;
|
||||||
use preserves_schema::syntax::block::escape_string;
|
use preserves_schema::syntax::block::escape_string;
|
||||||
use preserves_schema::syntax::block::constructors::*;
|
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;
|
use std::iter::FromIterator;
|
||||||
|
|
||||||
|
@ -29,12 +32,21 @@ impl Plugin for PatternPlugin {
|
||||||
if ctxt.mode == context::ModuleContextMode::TargetGeneric {
|
if ctxt.mode == context::ModuleContextMode::TargetGeneric {
|
||||||
let mut s = WalkState::new(ctxt, ctxt.module_path.clone());
|
let mut s = WalkState::new(ctxt, ctxt.module_path.clone());
|
||||||
if let Some(p) = definition.wc(&mut s) {
|
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 = syndicate::language().unparse(&p);
|
||||||
let v = preserves_schema::support::preserves::value::TextWriter::encode(
|
let v = preserves_schema::support::preserves::value::TextWriter::encode(
|
||||||
&mut preserves_schema::support::preserves::value::NoEmbeddedDomainCodec,
|
&mut preserves_schema::support::preserves::value::NoEmbeddedDomainCodec,
|
||||||
&v).unwrap();
|
&v).unwrap();
|
||||||
ctxt.define_type(item(seq![
|
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() ",
|
seq!["#[allow(unused)] pub fn wildcard_dataspace_pattern() ",
|
||||||
"-> syndicate::schemas::dataspace_patterns::Pattern ",
|
"-> syndicate::schemas::dataspace_patterns::Pattern ",
|
||||||
codeblock![
|
codeblock![
|
||||||
|
|
|
@ -15,7 +15,7 @@ jemalloc = ["dep:tikv-jemallocator"]
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
preserves-schema = "4.991"
|
preserves-schema = "4.991"
|
||||||
syndicate = { path = "../syndicate", version = "0.30.0"}
|
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]
|
[dependencies]
|
||||||
preserves-schema = "4.991"
|
preserves-schema = "4.991"
|
||||||
|
|
|
@ -36,7 +36,7 @@ use syndicate_macros::during;
|
||||||
|
|
||||||
pub fn on_demand(t: &mut Activation, config_ds: Arc<Cap>) {
|
pub fn on_demand(t: &mut Activation, config_ds: Arc<Cap>) {
|
||||||
t.spawn(Some(AnyValue::symbol("config_watcher")), move |t| {
|
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(
|
Supervisor::start(
|
||||||
t,
|
t,
|
||||||
Some(rec![AnyValue::symbol("config"), AnyValue::new(spec.path.clone())]),
|
Some(rec![AnyValue::symbol("config"), AnyValue::new(spec.path.clone())]),
|
||||||
|
|
|
@ -24,7 +24,7 @@ use syndicate_macros::during;
|
||||||
|
|
||||||
pub fn on_demand(t: &mut Activation, config_ds: Arc<Cap>, root_ds: Arc<Cap>) {
|
pub fn on_demand(t: &mut Activation, config_ds: Arc<Cap>, root_ds: Arc<Cap>) {
|
||||||
t.spawn(Some(AnyValue::symbol("daemon_listener")), move |t| {
|
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| {
|
enclose!((config_ds, root_ds) move |t: &mut Activation| {
|
||||||
supervise_daemon(t, config_ds, root_ds, spec)
|
supervise_daemon(t, config_ds, root_ds, spec)
|
||||||
})))
|
})))
|
||||||
|
|
|
@ -21,7 +21,7 @@ use syndicate_macros::during;
|
||||||
|
|
||||||
pub fn on_demand(t: &mut Activation, ds: Arc<Cap>) {
|
pub fn on_demand(t: &mut Activation, ds: Arc<Cap>) {
|
||||||
t.spawn(Some(AnyValue::symbol("tcp_relay_listener")), move |t| {
|
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(
|
Supervisor::start(
|
||||||
t,
|
t,
|
||||||
Some(rec![AnyValue::symbol("relay"), language().unparse(&spec)]),
|
Some(rec![AnyValue::symbol("relay"), language().unparse(&spec)]),
|
||||||
|
|
|
@ -25,7 +25,7 @@ use syndicate_macros::during;
|
||||||
|
|
||||||
pub fn on_demand(t: &mut Activation, ds: Arc<Cap>) {
|
pub fn on_demand(t: &mut Activation, ds: Arc<Cap>) {
|
||||||
t.spawn(Some(AnyValue::symbol("unix_relay_listener")), move |t| {
|
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(
|
Supervisor::start(
|
||||||
t,
|
t,
|
||||||
Some(rec![AnyValue::symbol("relay"), language().unparse(&spec)]),
|
Some(rec![AnyValue::symbol("relay"), language().unparse(&spec)]),
|
||||||
|
|
Loading…
Reference in New Issue