Skip to content

Commit

Permalink
revise: namespaces grammar as v1
Browse files Browse the repository at this point in the history
  • Loading branch information
claymcleod committed Nov 8, 2023
1 parent d843c83 commit 388e86d
Show file tree
Hide file tree
Showing 74 changed files with 175 additions and 169 deletions.
43 changes: 23 additions & 20 deletions wdl-grammar/src/bin/wdl-grammar-create-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub enum Error {
RuleMismatch(PathBuf),

/// An error from Pest.
PestError(Box<pest::error::Error<wdl::Rule>>),
PestError(Box<pest::error::Error<wdl::v1::Rule>>),
}

impl std::fmt::Display for Error {
Expand Down Expand Up @@ -75,8 +75,8 @@ fn inner() -> Result<()> {
.init();

let (contents, rule) = parse_from_path(&args.rule, &args.path)?;
let parse_tree: pest::iterators::Pairs<'_, wdl::Rule> =
wdl::Parser::parse(rule, &contents).map_err(|err| Error::PestError(Box::new(err)))?;
let parse_tree: pest::iterators::Pairs<'_, wdl::v1::Rule> =
wdl::v1::Parser::parse(rule, &contents).map_err(|err| Error::PestError(Box::new(err)))?;

for pair in parse_tree {
print_create_test_recursive(pair, 0);
Expand All @@ -85,7 +85,7 @@ fn inner() -> Result<()> {
Ok(())
}

fn print_create_test_recursive(pair: Pair<'_, wdl::Rule>, indent: usize) {
fn print_create_test_recursive(pair: Pair<'_, wdl::v1::Rule>, indent: usize) {
let span = pair.as_span();
let comment = pair
.as_str()
Expand Down Expand Up @@ -122,7 +122,10 @@ fn print_create_test_recursive(pair: Pair<'_, wdl::Rule>, indent: usize) {
print!(")");
}

fn parse_from_path(rule: impl AsRef<str>, path: impl AsRef<Path>) -> Result<(String, wdl::Rule)> {
fn parse_from_path(
rule: impl AsRef<str>,
path: impl AsRef<Path>,
) -> Result<(String, wdl::v1::Rule)> {
let rule = rule.as_ref();
let path = path.as_ref();

Expand All @@ -135,24 +138,24 @@ fn parse_from_path(rule: impl AsRef<str>, path: impl AsRef<Path>) -> Result<(Str
Ok((contents, rule))
}

fn map_rule(rule: &str) -> Option<wdl::Rule> {
fn map_rule(rule: &str) -> Option<wdl::v1::Rule> {
match rule {
"document" => Some(wdl::Rule::document),
"if" => Some(wdl::Rule::r#if),
"task" => Some(wdl::Rule::task),
"core" => Some(wdl::Rule::core),
"expression" => Some(wdl::Rule::expression),
"object_literal" => Some(wdl::Rule::object_literal),
"task_metadata_object" => Some(wdl::Rule::task_metadata_object),
"task_parameter_metadata" => Some(wdl::Rule::task_parameter_metadata),
"workflow_metadata_kv" => Some(wdl::Rule::workflow_metadata_kv),
"document" => Some(wdl::v1::Rule::document),
"if" => Some(wdl::v1::Rule::r#if),
"task" => Some(wdl::v1::Rule::task),
"core" => Some(wdl::v1::Rule::core),
"expression" => Some(wdl::v1::Rule::expression),
"object_literal" => Some(wdl::v1::Rule::object_literal),
"task_metadata_object" => Some(wdl::v1::Rule::task_metadata_object),
"task_parameter_metadata" => Some(wdl::v1::Rule::task_parameter_metadata),
"workflow_metadata_kv" => Some(wdl::v1::Rule::workflow_metadata_kv),
"command_heredoc_interpolated_contents" => {
Some(wdl::Rule::command_heredoc_interpolated_contents)
Some(wdl::v1::Rule::command_heredoc_interpolated_contents)
}
"workflow_scatter" => Some(wdl::Rule::workflow_scatter),
"workflow_call" => Some(wdl::Rule::workflow_call),
"workflow_conditional" => Some(wdl::Rule::workflow_conditional),
"postfix" => Some(wdl::Rule::postfix),
"workflow_scatter" => Some(wdl::v1::Rule::workflow_scatter),
"workflow_call" => Some(wdl::v1::Rule::workflow_call),
"workflow_conditional" => Some(wdl::v1::Rule::workflow_conditional),
"postfix" => Some(wdl::v1::Rule::postfix),
_ => todo!("must implement mapping for rule: {rule}"),
}
}
Expand Down
2 changes: 0 additions & 2 deletions wdl-grammar/src/grammar.rs

This file was deleted.

8 changes: 1 addition & 7 deletions wdl-grammar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,4 @@
#![warn(missing_debug_implementations)]
#![deny(rustdoc::broken_intra_doc_links)]

mod grammar;

use pest_derive::Parser;

#[derive(Debug, Parser)]
#[grammar = "grammar/wdl.pest"]
pub struct Parser;
pub mod v1;
31 changes: 17 additions & 14 deletions wdl-grammar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub enum Error {
RuleMismatch(PathBuf),

/// An error from Pest.
PestError(Box<pest::error::Error<wdl::Rule>>),
PestError(Box<pest::error::Error<wdl::v1::Rule>>),
}

impl std::fmt::Display for Error {
Expand Down Expand Up @@ -93,14 +93,14 @@ fn inner() -> Result<()> {
match args.command {
Command::Parse(args) => {
let (contents, rule) = parse_from_path(&args.rule, &args.path)?;
let mut parse_tree = wdl::Parser::parse(rule, &contents)
let mut parse_tree = wdl::v1::Parser::parse(rule, &contents)
.map_err(|err| Error::PestError(Box::new(err)))?;

// For documents, we don't care about the parent element: it is much
// more informative to see the children of the document split by
// spaces. This is a stylistic choice.
match rule {
wdl::Rule::document => {
wdl::v1::Rule::document => {
for element in parse_tree.next().unwrap().into_inner() {
dbg!(element);
}
Expand All @@ -115,7 +115,10 @@ fn inner() -> Result<()> {
Ok(())
}

fn parse_from_path(rule: impl AsRef<str>, path: impl AsRef<Path>) -> Result<(String, wdl::Rule)> {
fn parse_from_path(
rule: impl AsRef<str>,
path: impl AsRef<Path>,
) -> Result<(String, wdl::v1::Rule)> {
let rule = rule.as_ref();
let path = path.as_ref();

Expand All @@ -128,18 +131,18 @@ fn parse_from_path(rule: impl AsRef<str>, path: impl AsRef<Path>) -> Result<(Str
Ok((contents, rule))
}

fn map_rule(rule: &str) -> Option<wdl::Rule> {
fn map_rule(rule: &str) -> Option<wdl::v1::Rule> {
match rule {
"document" => Some(wdl::Rule::document),
"task" => Some(wdl::Rule::task),
"core" => Some(wdl::Rule::core),
"expression" => Some(wdl::Rule::expression),
"object_literal" => Some(wdl::Rule::object_literal),
"task_metadata_object" => Some(wdl::Rule::task_metadata_object),
"task_parameter_metadata" => Some(wdl::Rule::task_parameter_metadata),
"workflow_metadata_kv" => Some(wdl::Rule::workflow_metadata_kv),
"document" => Some(wdl::v1::Rule::document),
"task" => Some(wdl::v1::Rule::task),
"core" => Some(wdl::v1::Rule::core),
"expression" => Some(wdl::v1::Rule::expression),
"object_literal" => Some(wdl::v1::Rule::object_literal),
"task_metadata_object" => Some(wdl::v1::Rule::task_metadata_object),
"task_parameter_metadata" => Some(wdl::v1::Rule::task_parameter_metadata),
"workflow_metadata_kv" => Some(wdl::v1::Rule::workflow_metadata_kv),
"command_heredoc_interpolated_contents" => {
Some(wdl::Rule::command_heredoc_interpolated_contents)
Some(wdl::v1::Rule::command_heredoc_interpolated_contents)
}
_ => todo!("must implement mapping for rule: {rule}"),
}
Expand Down
8 changes: 8 additions & 0 deletions wdl-grammar/src/v1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use pest_derive::Parser;

#[cfg(test)]
mod tests;

#[derive(Debug, Parser)]
#[grammar = "v1/wdl.pest"]
pub struct Parser;
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use pest::consumes_to;
use pest::fails_with;
use pest::parses_to;

use crate::Parser as WdlParser;
use crate::Rule;
use crate::v1::Parser as WdlParser;
use crate::v1::Rule;

#[test]
fn it_fails_to_parse_an_empty_one_or_more() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use pest::consumes_to;
use pest::fails_with;
use pest::parses_to;

use crate::Parser as WdlParser;
use crate::Rule;
use crate::v1::Parser as WdlParser;
use crate::v1::Rule;

#[test]
fn it_fails_to_parse_an_empty_option() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use pest::consumes_to;
use pest::fails_with;
use pest::parses_to;

use crate::Parser as WdlParser;
use crate::Rule;
use crate::v1::Parser as WdlParser;
use crate::v1::Rule;

#[test]
fn it_fails_to_parse_an_empty_zero_or_more() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use pest::consumes_to;
use pest::parses_to;

use crate::Parser as WdlParser;
use crate::Rule;
use crate::v1::Parser as WdlParser;
use crate::v1::Rule;

mod core;
mod infix;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use pest::consumes_to;
use pest::parses_to;

use crate::Parser as WdlParser;
use crate::Rule;
use crate::v1::Parser as WdlParser;
use crate::v1::Rule;

mod array_literal;
mod group;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use pest::consumes_to;
use pest::fails_with;
use pest::parses_to;

use crate::Parser as WdlParser;
use crate::Rule;
use crate::v1::Parser as WdlParser;
use crate::v1::Rule;

#[test]
fn it_fails_to_parse_an_empty_string() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use pest::consumes_to;
use pest::fails_with;
use pest::parses_to;

use crate::Parser as WdlParser;
use crate::Rule;
use crate::v1::Parser as WdlParser;
use crate::v1::Rule;

#[test]
fn it_fails_to_parse_an_empty_string() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use pest::consumes_to;
use pest::fails_with;
use pest::parses_to;

use crate::Parser as WdlParser;
use crate::Rule;
use crate::v1::Parser as WdlParser;
use crate::v1::Rule;

#[test]
fn it_fails_to_parse_an_empty_string() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use pest::consumes_to;
use pest::fails_with;
use pest::parses_to;

use crate::Parser as WdlParser;
use crate::Rule;
use crate::v1::Parser as WdlParser;
use crate::v1::Rule;

#[test]
fn it_fails_to_parse_an_empty_string() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use pest::consumes_to;
use pest::fails_with;
use pest::parses_to;

use crate::Parser as WdlParser;
use crate::Rule;
use crate::v1::Parser as WdlParser;
use crate::v1::Rule;

#[test]
fn it_fails_to_parse_an_empty_string() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use pest::consumes_to;
use pest::fails_with;
use pest::parses_to;

use crate::Parser as WdlParser;
use crate::Rule;
use crate::v1::Parser as WdlParser;
use crate::v1::Rule;

#[test]
fn it_fails_to_parse_an_empty_string() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use pest::consumes_to;
use pest::fails_with;
use pest::parses_to;

use crate::Parser as WdlParser;
use crate::Rule;
use crate::v1::Parser as WdlParser;
use crate::v1::Rule;

#[test]
fn it_fails_to_parse_an_empty_string() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use pest::consumes_to;
use pest::fails_with;
use pest::parses_to;

use crate::Parser as WdlParser;
use crate::Rule;
use crate::v1::Parser as WdlParser;
use crate::v1::Rule;

#[test]
fn it_fails_to_parse_an_empty_string() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use pest::consumes_to;
use pest::fails_with;
use pest::parses_to;

use crate::Parser as WdlParser;
use crate::Rule;
use crate::v1::Parser as WdlParser;
use crate::v1::Rule;

#[test]
fn it_fails_to_parse_an_empty_string() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use pest::consumes_to;
use pest::parses_to;

use crate::Parser as WdlParser;
use crate::Rule;
use crate::v1::Parser as WdlParser;
use crate::v1::Rule;

mod and;
mod eq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use pest::consumes_to;
use pest::fails_with;
use pest::parses_to;

use crate::Parser as WdlParser;
use crate::Rule;
use crate::v1::Parser as WdlParser;
use crate::v1::Rule;

#[test]
fn it_fails_to_parse_an_empty_add() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use pest::consumes_to;
use pest::fails_with;
use pest::parses_to;

use crate::Parser as WdlParser;
use crate::Rule;
use crate::v1::Parser as WdlParser;
use crate::v1::Rule;

#[test]
fn it_fails_to_parse_an_empty_and() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use pest::consumes_to;
use pest::fails_with;
use pest::parses_to;

use crate::Parser as WdlParser;
use crate::Rule;
use crate::v1::Parser as WdlParser;
use crate::v1::Rule;

#[test]
fn it_fails_to_parse_an_empty_div() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use pest::consumes_to;
use pest::fails_with;
use pest::parses_to;

use crate::Parser as WdlParser;
use crate::Rule;
use crate::v1::Parser as WdlParser;
use crate::v1::Rule;

#[test]
fn it_fails_to_parse_an_empty_eq() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use pest::consumes_to;
use pest::fails_with;
use pest::parses_to;

use crate::Parser as WdlParser;
use crate::Rule;
use crate::v1::Parser as WdlParser;
use crate::v1::Rule;

#[test]
fn it_fails_to_parse_an_empty_gt() {
Expand Down
Loading

0 comments on commit 388e86d

Please sign in to comment.