diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin.rs | 36 | ||||
| -rw-r--r-- | src/document_tree/element_categories.rs | 4 | ||||
| -rw-r--r-- | src/lib.rs | 7 | ||||
| -rw-r--r-- | src/parser/mod.rs | 2 |
4 files changed, 39 insertions, 10 deletions
diff --git a/src/bin.rs b/src/bin.rs new file mode 100644 index 0000000..5eeb768 --- /dev/null +++ b/src/bin.rs @@ -0,0 +1,36 @@ +mod parser; + + +use pest::Parser; +use structopt::StructOpt; +use clap::{_clap_count_exprs, arg_enum}; +use quicli::{main, fs::read_file, prelude::Verbosity}; + +use self::parser::{RstParser, Rule}; + + +arg_enum! { + #[derive(Debug)] + enum Format { json } +} + +#[derive(Debug, StructOpt)] +#[structopt(raw(setting = "structopt::clap::AppSettings::ColoredHelp"))] +struct Cli { + #[structopt( + long = "format", short = "f", default_value = "json", + raw(possible_values = "&Format::variants()", case_insensitive = "true"), + )] + format: Format, + file: String, + #[structopt(flatten)] + verbosity: Verbosity, +} + +main!(|args: Cli, log_level: verbosity| { + let content = read_file(args.file)?; + let parsed = RstParser::parse(Rule::doc, &content)?; + match args.format { + Format::json => println!("{}", parsed.to_string()) + } +}); diff --git a/src/document_tree/element_categories.rs b/src/document_tree/element_categories.rs index 7fcce82..bc2e347 100644 --- a/src/document_tree/element_categories.rs +++ b/src/document_tree/element_categories.rs @@ -3,8 +3,8 @@ use std::fmt::{self,Debug,Formatter}; use super::elements::*; pub trait HasChildren<C> { - fn with_children(Vec<C>) -> Self; - fn children(& self) -> &Vec<C>; + fn with_children(children: Vec<C>) -> Self; + fn children(&self) -> &Vec<C>; fn children_mut(&mut self) -> &mut Vec<C>; fn append_child<R: Into<C>>(&mut self, child: R) { self.children_mut().push(child.into()); @@ -1,10 +1,3 @@ -extern crate url; -extern crate pest; -#[macro_use] -extern crate pest_derive; -extern crate bitflags; -extern crate unicode_categories; - pub mod document_tree; pub mod parser; pub mod renderer; diff --git a/src/parser/mod.rs b/src/parser/mod.rs index ab7e232..2ae47cb 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -4,13 +4,13 @@ pub mod token; use pest::consumes_to; #[allow(unused_imports)] use pest::parses_to; +use pest_derive::*; #[derive(Parser)] #[grammar = "rst.pest"] pub struct RstParser; - #[test] fn plain() { parses_to! { |
