aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml15
-rw-r--r--README.rst7
-rw-r--r--src/bin.rs36
-rw-r--r--src/document_tree/element_categories.rs4
-rw-r--r--src/lib.rs7
-rw-r--r--src/parser/mod.rs2
6 files changed, 61 insertions, 10 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 9421284..4c7b8aa 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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'
diff --git a/README.rst b/README.rst
index bc08860..adb3d2d 100644
--- a/README.rst
+++ b/README.rst
@@ -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());
diff --git a/src/lib.rs b/src/lib.rs
index e9ad6c7..55c8a31 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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! {