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 | |
| parent | 928da429a61fd98891f8b59fedb5f2de45dbc45d (diff) | |
| download | rust-rst-07ada348558204e1736e29056eba6d73b2084cc2.tar.bz2 | |
Rust 2018
| -rw-r--r-- | Cargo.toml | 15 | ||||
| -rw-r--r-- | README.rst | 7 | ||||
| -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 |
6 files changed, 61 insertions, 10 deletions
@@ -10,9 +10,24 @@ documentation = 'https://flying-sheep.github.io/rust-rst' homepage = 'https://github.com/flying-sheep/rust-rst' repository = 'https://github.com/flying-sheep/rust-rst.git' +edition = '2018' + +[lib] +name = "rst" +path = "src/lib.rs" + +[[bin]] +name = "rst" +path = "src/bin.rs" + [dependencies] url = '1.7.1' bitflags = '1.0.4' unicode_categories = '0.1.1' pest = '2.0.2' pest_derive = '2.0.1' + +quicli = '0.3.1' +structopt = '0.2.12' +structopt-derive = '0.2.12' +clap = '2.32.0' @@ -11,3 +11,10 @@ This project is dual-licensed under Apache 2.0 and MIT. .. note:: If you are looking for the requirements tracking tool rst (Requirements, Specifications and Tests), have a look at the rst_app package instead. + +Inspiration +----------- +The design was inspired by the comrak_ Markdown parser library. The rST grammar was adapted from peg-rst_ + +.. _comrak: https://github.com/kivikakk/comrak +.. _peg-rst: https://github.com/hhatto/peg-rst 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! { |
