From 127d3b7aa429962847300bd28c2ffdef201d0a4a Mon Sep 17 00:00:00 2001 From: "R. Tyler Croy" Date: Sat, 28 Nov 2020 21:40:35 -0800 Subject: [PATCH] Refactor the parser code into its own crate for future development This will inform #46 --- Cargo.lock | 13 ++++++++++++- Cargo.toml | 1 + crates/parser/Cargo.toml | 13 +++++++++++++ crates/parser/README.adoc | 6 ++++++ {services => crates}/parser/src/lib.rs | 3 +++ {services => crates}/parser/src/pipeline.pest | 0 .../parser/test_data/invalid/00_empty.otto | 0 .../parser/test_data/invalid/01_missing_steps.otto | 0 .../parser/test_data/valid/00_multiple_stages.otto | 0 .../parser/test_data/valid/00_pipeline_block.otto | 0 .../parser/test_data/valid/00_simple.otto | 0 .../parser/test_data/valid/00_simple_kwargs.otto | 0 .../parser/test_data/valid/91_orphan_steps.otto | 0 .../test_data/valid/92_orphan_steps_and_stages.otto | 0 {services => crates}/parser/tests/valid.rs | 0 services/parser/Cargo.toml | 9 ++------- services/parser/README.adoc | 4 +--- services/parser/src/main.rs | 1 - 18 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 crates/parser/Cargo.toml create mode 100644 crates/parser/README.adoc rename {services => crates}/parser/src/lib.rs (99%) rename {services => crates}/parser/src/pipeline.pest (100%) rename {services => crates}/parser/test_data/invalid/00_empty.otto (100%) rename {services => crates}/parser/test_data/invalid/01_missing_steps.otto (100%) rename {services => crates}/parser/test_data/valid/00_multiple_stages.otto (100%) rename {services => crates}/parser/test_data/valid/00_pipeline_block.otto (100%) rename {services => crates}/parser/test_data/valid/00_simple.otto (100%) rename {services => crates}/parser/test_data/valid/00_simple_kwargs.otto (100%) rename {services => crates}/parser/test_data/valid/91_orphan_steps.otto (100%) rename {services => crates}/parser/test_data/valid/92_orphan_steps_and_stages.otto (100%) rename {services => crates}/parser/tests/valid.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index c610ff3..77e1f63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1652,11 +1652,22 @@ dependencies = [ name = "otto-parser" version = "0.1.0" dependencies = [ - "async-std", "log", "otto-models", "pest", "pest_derive", + "serde_json", + "uuid", +] + +[[package]] +name = "otto-parser-service" +version = "0.1.0" +dependencies = [ + "async-std", + "log", + "otto-models", + "otto-parser", "pretty_env_logger 0.4.0", "serde_json", "tide 0.15.0", diff --git a/Cargo.toml b/Cargo.toml index 356b844..4d4829f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ members = [ "crates/agent", "crates/models", + "crates/parser", "services/auctioneer", "services/eventbus", diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml new file mode 100644 index 0000000..93527b8 --- /dev/null +++ b/crates/parser/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "otto-parser" +version = "0.1.0" +authors = ["R. Tyler Croy "] +edition = "2018" + +[dependencies] +log = "~0.4.11" +otto-models = { path = "../models" } +pest = "~2.1.3" +pest_derive = "~2.1.0" +serde_json = "~1.0.59" +uuid = { version = "~0.8.1", features = ["v4", "serde"]} diff --git a/crates/parser/README.adoc b/crates/parser/README.adoc new file mode 100644 index 0000000..15867ad --- /dev/null +++ b/crates/parser/README.adoc @@ -0,0 +1,6 @@ += Otto Parser + +The Otto Parser service is basically a parser engine that speaks HTTP. In the +`src/` directory you will find the `.pest` grammar definition which outlines +the Otto Pipeline syntax. + diff --git a/services/parser/src/lib.rs b/crates/parser/src/lib.rs similarity index 99% rename from services/parser/src/lib.rs rename to crates/parser/src/lib.rs index 158badf..e0b1a2f 100644 --- a/services/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -9,6 +9,9 @@ use pest::iterators::{Pair, Pairs}; use pest::Parser; use uuid::Uuid; +pub use pest::error::ErrorVariant; +pub use pest::error::LineColLocation; + #[derive(Parser)] #[grammar = "pipeline.pest"] struct PipelineParser; diff --git a/services/parser/src/pipeline.pest b/crates/parser/src/pipeline.pest similarity index 100% rename from services/parser/src/pipeline.pest rename to crates/parser/src/pipeline.pest diff --git a/services/parser/test_data/invalid/00_empty.otto b/crates/parser/test_data/invalid/00_empty.otto similarity index 100% rename from services/parser/test_data/invalid/00_empty.otto rename to crates/parser/test_data/invalid/00_empty.otto diff --git a/services/parser/test_data/invalid/01_missing_steps.otto b/crates/parser/test_data/invalid/01_missing_steps.otto similarity index 100% rename from services/parser/test_data/invalid/01_missing_steps.otto rename to crates/parser/test_data/invalid/01_missing_steps.otto diff --git a/services/parser/test_data/valid/00_multiple_stages.otto b/crates/parser/test_data/valid/00_multiple_stages.otto similarity index 100% rename from services/parser/test_data/valid/00_multiple_stages.otto rename to crates/parser/test_data/valid/00_multiple_stages.otto diff --git a/services/parser/test_data/valid/00_pipeline_block.otto b/crates/parser/test_data/valid/00_pipeline_block.otto similarity index 100% rename from services/parser/test_data/valid/00_pipeline_block.otto rename to crates/parser/test_data/valid/00_pipeline_block.otto diff --git a/services/parser/test_data/valid/00_simple.otto b/crates/parser/test_data/valid/00_simple.otto similarity index 100% rename from services/parser/test_data/valid/00_simple.otto rename to crates/parser/test_data/valid/00_simple.otto diff --git a/services/parser/test_data/valid/00_simple_kwargs.otto b/crates/parser/test_data/valid/00_simple_kwargs.otto similarity index 100% rename from services/parser/test_data/valid/00_simple_kwargs.otto rename to crates/parser/test_data/valid/00_simple_kwargs.otto diff --git a/services/parser/test_data/valid/91_orphan_steps.otto b/crates/parser/test_data/valid/91_orphan_steps.otto similarity index 100% rename from services/parser/test_data/valid/91_orphan_steps.otto rename to crates/parser/test_data/valid/91_orphan_steps.otto diff --git a/services/parser/test_data/valid/92_orphan_steps_and_stages.otto b/crates/parser/test_data/valid/92_orphan_steps_and_stages.otto similarity index 100% rename from services/parser/test_data/valid/92_orphan_steps_and_stages.otto rename to crates/parser/test_data/valid/92_orphan_steps_and_stages.otto diff --git a/services/parser/tests/valid.rs b/crates/parser/tests/valid.rs similarity index 100% rename from services/parser/tests/valid.rs rename to crates/parser/tests/valid.rs diff --git a/services/parser/Cargo.toml b/services/parser/Cargo.toml index 05ba6fc..bb94c02 100644 --- a/services/parser/Cargo.toml +++ b/services/parser/Cargo.toml @@ -1,13 +1,9 @@ [package] -name = "otto-parser" +name = "otto-parser-service" version = "0.1.0" authors = ["R. Tyler Croy "] edition = "2018" -[lib] -name = "otto_parser" -path = "src/lib.rs" - [[bin]] name = "otto-parser" path = "src/main.rs" @@ -16,8 +12,7 @@ path = "src/main.rs" async-std = { version = "1.6.5", features = ["attributes"]} log = "~0.4.11" otto-models = { path = "../../crates/models" } -pest = "~2.1.3" -pest_derive = "~2.1.0" +otto-parser = { path = "../../crates/parser" } pretty_env_logger = "~0.4.0" serde_json = "~1.0.59" tide = "~0.15.0" diff --git a/services/parser/README.adoc b/services/parser/README.adoc index 0852a8d..82bec7a 100644 --- a/services/parser/README.adoc +++ b/services/parser/README.adoc @@ -1,8 +1,6 @@ = Parser service -The Otto Parser service is basically a parser engine that speaks HTTP. In the -`src/` directory you will find the `.pest` grammar definition which outlines -the Otto Pipeline syntax. +The Otto Parser Service presents the parser crate as an HTTP service. The `apispec.yml` is an link:https://en.wikipedia.org/wiki/Open_API[OpenAPI] specification that describes the public HTTP endpoints that the parser service diff --git a/services/parser/src/main.rs b/services/parser/src/main.rs index f096ef7..ed77c06 100644 --- a/services/parser/src/main.rs +++ b/services/parser/src/main.rs @@ -16,7 +16,6 @@ async fn parse(mut req: Request<()>) -> tide::Result { match parsed { Err(e) => { - use pest::error::*; error!("Failed to parse: {:?}", e); let variant = match e.variant {