1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#[allow(unused)]
#[macro_use]
extern crate reproto_backend as backend;
extern crate reproto_core as core;
extern crate reproto_manifest as manifest;
extern crate serde;
#[allow(unused)]
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate toml;

mod collector;
mod json_backend;
mod json_compiler;
mod json_options;
mod listeners;

use self::ErrorKind::*;
use backend::{ArgMatches, Environment};
use backend::errors::*;
use core::Context;
use json_backend::JsonBackend;
use json_options::JsonOptions;
use listeners::Listeners;
use manifest::{self as m, Lang, Manifest, NoModule, TryFromToml};
use std::path::Path;
use std::rc::Rc;

const EXT: &str = "json";

#[derive(Default)]
pub struct JsonLang;

impl Lang for JsonLang {
    type Module = JsonModule;
}

#[derive(Debug)]
pub enum JsonModule {
}

impl TryFromToml for JsonModule {
    fn try_from_string(path: &Path, id: &str, value: String) -> m::errors::Result<Self> {
        NoModule::illegal(path, id, value)
    }

    fn try_from_value(path: &Path, id: &str, value: toml::Value) -> m::errors::Result<Self> {
        NoModule::illegal(path, id, value)
    }
}

fn setup_listeners(modules: &[JsonModule]) -> Result<(JsonOptions, Box<Listeners>)> {
    let listeners: Vec<Box<Listeners>> = Vec::new();

    for module in modules {
        match *module {}
    }

    let mut options = JsonOptions::new();

    for listener in &listeners {
        listener.configure(&mut options)?;
    }

    Ok((options, Box::new(listeners)))
}

pub fn compile(
    _ctx: Rc<Context>,
    env: Environment,
    _matches: &ArgMatches,
    manifest: Manifest<JsonLang>,
) -> Result<()> {
    let out = manifest.output.ok_or(MissingOutput)?;
    let (options, listeners) = setup_listeners(&manifest.modules)?;
    let backend = JsonBackend::new(env, options, listeners);
    let compiler = backend.compiler(out)?;
    compiler.compile()
}