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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#![feature(nll)]
#![allow(unknown_lints)]
#![allow(single_char_pattern)]
#![allow(ptr_arg)]
#![allow(unused_variables)]
#![allow(dead_code)]
#![allow(unused_imports)]
#[macro_use]
extern crate log;
#[macro_use]
extern crate maplit;
#[macro_use]
extern crate serde_derive;
extern crate yansi;
extern crate serde_json;
extern crate term_painter;
#[macro_use]
extern crate failure;
extern crate regex;
extern crate either;
extern crate ron;
extern crate serde;
macro_rules! log_transform {
( $( $x:expr ),* $(,)* ) => {
};
}
macro_rules! log_compose {
( $( $x:expr ),* $(,)* ) => {
};
}
pub mod compose;
pub mod doc;
pub mod schema;
pub mod stepper;
pub mod transform;
pub mod writer;
pub mod transform_test;
pub mod macros;
pub mod apply;
mod parse;
pub mod validate;
use apply::*;
use doc::*;
use compose::*;
use std::collections::HashMap;
use std::fmt::Debug;
pub use transform::{Schema, Track};
use transform::transform;
pub trait OT where Self: Sized {
type Doc;
fn apply(&Self::Doc, &Self) -> Self::Doc;
fn empty() -> Self;
fn compose(&Self, &Self) -> Self;
fn compose_iter<'a, I>(iter: I) -> Self where I: Iterator<Item=&'a Self>, Self: 'a;
fn transform<S: Schema>(&Self, &Self) -> (Self, Self);
fn transform_advance<S: Schema>(a: &Self, b: &Self) -> Self;
}
impl OT for Op {
type Doc = Doc;
fn apply(doc: &Self::Doc, op: &Self) -> Self::Doc {
Doc(apply_operation(&doc.0, op))
}
fn empty() -> Self {
(vec![], vec![])
}
fn compose(a: &Self, b: &Self) -> Self {
compose(a, b)
}
fn compose_iter<'a, I>(iter: I) -> Self where I: Iterator<Item=&'a Self> {
let mut base = Self::empty();
for item in iter {
base = Self::compose(&base, item);
}
base
}
fn transform<S: Schema>(a: &Self, b: &Self) -> (Self, Self) {
transform::<S>(&a, &b)
}
fn transform_advance<S: Schema>(a: &Self, b: &Self) -> Self {
let (a_transform, b_transform) = Self::transform::<S>(a, b);
let a_res = Self::compose(a, &a_transform);
let b_res = Self::compose(a, &a_transform);
a_res
}
}