From a53ddfe2c6c6736348b78565a8334c1b217e128f Mon Sep 17 00:00:00 2001 From: Philipp A Date: Sun, 19 Jun 2016 18:06:55 +0200 Subject: some cleanups, parser module files (empty) --- Cargo.toml | 11 ++++---- README.rst | 5 ++-- docutils.dtd | 2 ++ src/document_tree/elements.rs | 61 ++++++++++++++++++------------------------ src/lib.rs | 5 ++++ src/parser/mod.rs | 1 + src/parser/token.rs | 62 +++++++++++++++++++++++++++++++++++++++++++ src/renderer/mod.rs | 1 + 8 files changed, 106 insertions(+), 42 deletions(-) create mode 100644 src/parser/mod.rs create mode 100644 src/parser/token.rs create mode 100644 src/renderer/mod.rs diff --git a/Cargo.toml b/Cargo.toml index dac4b26..ba1907a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,9 @@ [package] - -name = "rst" -version = "0.0.0" -authors = [ "Phil Schaf " ] +name = 'rst' +version = '0.0.0' +authors = [ 'Phil Schaf ' ] [dependencies] -url = "0.2.37" +url = '0.5' +bitflags = '0.5' +unicode_categories = '0.1.0' diff --git a/README.rst b/README.rst index a9af870..de2d11a 100644 --- a/README.rst +++ b/README.rst @@ -2,8 +2,9 @@ RuSTructuredText ================ - Designed around the `Docutils Document Tree`_ and the `reStructuredText specification`_, this is supposed to become a library able to convert reStructuredText and Docutils XML to both each other and HTML5. +This project is dual-licensed under Apache 2.0 and MIT. + .. _Docutils Document Tree: http://docutils.sourceforge.net/docs/ref/doctree.html -.. _reStructuredText specification: http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html \ No newline at end of file +.. _reStructuredText specification: http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html diff --git a/docutils.dtd b/docutils.dtd index 229a6d9..c39d08a 100644 --- a/docutils.dtd +++ b/docutils.dtd @@ -1,3 +1,4 @@ + +]> diff --git a/src/document_tree/elements.rs b/src/document_tree/elements.rs index 4928cee..ba5d78e 100644 --- a/src/document_tree/elements.rs +++ b/src/document_tree/elements.rs @@ -32,7 +32,7 @@ pub struct CommonAttributes { //impl\\ //----\\ -macro_rules! impl_element(($name:ident) => { +macro_rules! impl_element { ($name:ident) => ( impl Element for $name { fn ids (& self) -> & Vec { & self.common.ids } fn ids_mut(&mut self) -> &mut Vec { &mut self.common.ids } @@ -43,70 +43,61 @@ macro_rules! impl_element(($name:ident) => { fn classes (& self) -> & Vec { & self.common.classes } fn classes_mut(&mut self) -> &mut Vec { &mut self.common.classes } } -}); +)} -macro_rules! impl_children(($name:ident, $childtype:ident) => { +macro_rules! impl_children { ($name:ident, $childtype:ident) => ( impl HasChildren<$childtype> for $name { fn with_children(children: Vec<$childtype>) -> $name { $name { children: children, ..Default::default() } } fn children (& self) -> & Vec<$childtype> { & self.children } fn children_mut(&mut self) -> &mut Vec<$childtype> { &mut self.children } } -}); +)} -macro_rules! impl_extra(($name:ident) => { +macro_rules! impl_extra { ($name:ident) => ( impl ExtraAttributes for $name { // fn with_extra(extra: extra_attributes::$name) -> $name { $name { extra: extra, ..Default::default() } } fn extra (& self) -> & extra_attributes::$name { & self.extra } fn extra_mut(&mut self) -> &mut extra_attributes::$name { &mut self.extra } } -}); +)} -macro_rules! impl_elem( +macro_rules! impl_new {( + $(#[$attr:meta])* + pub struct $name:ident { $( $field:ident : $typ:path ),* +}) => ( + $(#[$attr])* + pub struct $name { $( $field: $typ, )* } + impl $name { + pub fn new( $( $field: $typ, )* ) -> $name { $name { $( $field: $field, )* } } + } +)} + +macro_rules! impl_elem { ($name:ident) => { - #[derive(Default,Debug)] - pub struct $name { common: CommonAttributes } - impl $name { - pub fn new(common: CommonAttributes) -> $name { $name { common: common } } - } + impl_new!(#[derive(Default,Debug)] pub struct $name { common: CommonAttributes }); impl_element!($name); }; ($name:ident; +) => { - #[derive(Default,Debug)] - pub struct $name { common: CommonAttributes, extra: extra_attributes::$name } - impl $name { - pub fn new(common: CommonAttributes, extra: extra_attributes::$name ) -> $name { $name { common: common, extra: extra } } - } + impl_new!(#[derive(Default,Debug)] pub struct $name { common: CommonAttributes, extra: extra_attributes::$name }); impl_element!($name); impl_extra!($name); }; ($name:ident; *) => { //same as above with no default - #[derive(Debug)] - pub struct $name { common: CommonAttributes, extra: extra_attributes::$name } - impl $name { - pub fn new(common: CommonAttributes, extra: extra_attributes::$name ) -> $name { $name { common: common, extra: extra } } - } + impl_new!(#[derive(Debug)] pub struct $name { common: CommonAttributes, extra: extra_attributes::$name }); impl_element!($name); impl_extra!($name); }; ($name:ident, $childtype:ident) => { - #[derive(Default,Debug)] - pub struct $name { common: CommonAttributes, children: Vec<$childtype> } - impl $name { - pub fn new(common: CommonAttributes, children: Vec<$childtype> ) -> $name { $name { common: common, children: children } } - } + impl_new!(#[derive(Default,Debug)] pub struct $name { common: CommonAttributes, children: Vec<$childtype> }); impl_element!($name); impl_children!($name, $childtype); }; ($name:ident, $childtype:ident; +) => { - #[derive(Default,Debug)] - pub struct $name { common: CommonAttributes, extra: extra_attributes::$name, children: Vec<$childtype> } - impl $name { - pub fn new(common: CommonAttributes, extra: extra_attributes::$name, children: Vec<$childtype> ) -> $name { $name { common: common, extra: extra, children: children } } - } + impl_new!(#[derive(Default,Debug)] pub struct $name { common: CommonAttributes, extra: extra_attributes::$name, children: Vec<$childtype> }); impl_element!($name); impl_extra!($name); impl_children!($name, $childtype); }; -); +} -macro_rules! impl_elems(( $( ($($args:tt)*) )* ) => { +macro_rules! impl_elems { ( $( ($($args:tt)*) )* ) => ( $( impl_elem!($($args)*); )* -}); +)} #[derive(Default,Debug)] diff --git a/src/lib.rs b/src/lib.rs index 3a3c6d8..f27c9ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,8 @@ extern crate url; +#[macro_use] +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 new file mode 100644 index 0000000..79c66ba --- /dev/null +++ b/src/parser/mod.rs @@ -0,0 +1 @@ +pub mod token; diff --git a/src/parser/token.rs b/src/parser/token.rs new file mode 100644 index 0000000..8c3a445 --- /dev/null +++ b/src/parser/token.rs @@ -0,0 +1,62 @@ +// rST does indentation for lists by using the column after the list item +// i’ll represent it as BulletList → Indent. e.g.: +// +//1. * foo +// * bar +// +// becomes: +// +//EnumList(Arabic, Period) → Indent(3) +// → BulletList(Asterisk) → Indent(2) +// → Line("foo") +// → Dedent(2) +// → BulletList(Asterisk) → Indent(2) +// → Line("bar") +//→ Dedent(5) + +//http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#bullet-lists + +enum BulletListType { Ast, Plus, Minus, Bullet, TriBullet, HyphenBullet } +enum EnumListChar { Arabic, AlphaUpper, AlphaLower, RomanUpper, RomanLower, Auto } +enum EnumListType { Period, ParenEnclosed, Paren } +enum AdornmentChar { + Bang, DQuote, Hash, Dollar, Percent, Amp, SQuote, LParen, RParen, Ast, Plus, Comma, + Minus, Period, Slash, Colon, Semicolon, Less, Eq, More, Question, At, LBrack, + Backslash, RBrack, Caret, Underscore, Backtick, LBrace, Pipe, RBrace, Tilde, +} +enum FootnoteType { Numbered(usize), AutoNumber, AutoSymbol, AutoNamed(String) } + +enum TokenBlockLevel { + EmptyLine, + Indent(u8), // plain indents mean blockquotes + Dedent(u8), + Line(String), + + Adornment(AdornmentChar, u32), // ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~ + // for a transition, this must be surrounded by blank lines, and be of length ≥ 4 + + ListBulletItem(BulletListType), // *, +, -, •, ‣, ⁃ + ListEnumItem(EnumListChar, EnumListType), // 1, A, a, I, i; 1., (1), 1) + ListDefinitionTerm(String, Option), //term and classifiers + ListFieldName(String), + ListOption(String), + ListOptionArg(String), + + BlockLiteral, + BlockQuotedLiteral(AdornmentChar), + // line blocks use pipes (|) + BlockDoctest(String), + + GridTableLine(String), + GridTableRow(String), + SimpleTableLine(String), + + Footnote(FootnoteType), // [1], [#], [*], [#foo] + Citation(String), + Directive(String, String), // name and args + SubstitutionDef(String, String), // symbol and substitited line TODO: maybe only the former? + Comment, + CommentEmpty, // if not followed by anything, “..” is special + Target(String, String), + TargetAnonymous(String), +} diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs new file mode 100644 index 0000000..0b13441 --- /dev/null +++ b/src/renderer/mod.rs @@ -0,0 +1 @@ +pub static FOOTNOTE_SYMBOLS: [char; 10] = ['*', '†', '‡', '§', '¶', '#', '♠', '♥', '♦', '♣']; -- cgit v1.2.3