diff options
| author | Philipp A | 2018-10-29 15:12:55 +0100 | 
|---|---|---|
| committer | Philipp A | 2018-10-29 15:12:55 +0100 | 
| commit | 07ada348558204e1736e29056eba6d73b2084cc2 (patch) | |
| tree | aaa102c1282572824dffb8fc0c873816177a1a83 /src | |
| parent | 928da429a61fd98891f8b59fedb5f2de45dbc45d (diff) | |
| download | rust-rst-07ada348558204e1736e29056eba6d73b2084cc2.tar.bz2 | |
Rust 2018
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! {  | 
