diff options
| author | Philipp A | 2018-11-15 21:53:55 +0100 |
|---|---|---|
| committer | Philipp A | 2018-11-15 21:53:55 +0100 |
| commit | 336e3b0ff159f8344ed07d7e23b87cff41084502 (patch) | |
| tree | d93c5d23e7bf3292b65b96e48b3f9114c7b96d06 /src/parser.rs | |
| parent | 42774e932f29af18798791d4d5efb4b4e05db116 (diff) | |
| download | rust-rst-336e3b0ff159f8344ed07d7e23b87cff41084502.tar.bz2 | |
renamed mod.rs
Diffstat (limited to 'src/parser.rs')
| -rw-r--r-- | src/parser.rs | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/parser.rs b/src/parser.rs new file mode 100644 index 0000000..6e3f65e --- /dev/null +++ b/src/parser.rs @@ -0,0 +1,104 @@ +pub mod token; +pub mod serialize; + +#[allow(unused_imports)] +use pest::consumes_to; +#[allow(unused_imports)] +use pest::parses_to; +use pest_derive::Parser; + +#[derive(Parser)] +#[grammar = "rst.pest"] +pub struct RstParser; + + +#[test] +fn plain() { + parses_to! { + parser: RstParser, + input: "line\n", + rule: Rule::paragraph, + tokens: [ + paragraph(0, 5, [ + line(0, 5) + ]) + ] + }; +} + +/* #[test] +fn title() { + parses_to! { + parser: RstParser, + input: "\ +Title +===== +", + rule: Rule::title, + tokens: [ + title(0, 12, [ + line(0, 6), + adornments(6, 11), + ]) + ] + }; +} + +#[test] +fn title_overline() { + parses_to! { + parser: RstParser, + input: "\ +----- +Title +----- +", + rule: Rule::title, + tokens: [ + title(0, 18, [ + adornments(0, 6), + line(6, 12), + adornments(12, 18), + ]) + ] + }; +} */ + +#[test] +fn nested_lists() { + parses_to! { + parser: RstParser, + input: "\ +paragraph + +- item 1 +- item 2 + more text + more text 2 + more text 3 + - nested item 1 + - nested item 2 + - nested item 3 +", + rule: Rule::document, + tokens: [ + paragraph(0, 10, [ line(0, 10) ]), + bullet_list(11, 131, [ + bullet_item(11, 21, [ line(14, 21) ]), + bullet_item(21, 131, [ + line(24, 31), + paragraph(34, 74, [ + line(34, 44), + line(47, 59), + line(62, 74), + ]), + bullet_list(77, 131, [ + bullet_item(77, 93, [ line(79, 93) ]), + bullet_item(96, 112, [ line(98, 112) ]), + bullet_item(115, 131, [ line(117, 131) ]), + ]), + ]), + ]), + ] + } +} |
