-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//! Block elements form the main structure of an AsciiDoc document, starting | ||
//! with the document itself. | ||
//! | ||
//! A block element (aka block) is a discrete, line-oriented chunk of content in | ||
//! an AsciiDoc document. Once parsed, that chunk of content becomes a block | ||
//! element in the parsed document model. Certain blocks may contain other | ||
//! blocks, so we say that blocks can be nested. The converter visits each block | ||
//! in turn, in document order, converting it to a corresponding chunk of | ||
//! output. | ||
|
||
pub(crate) mod simple; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use nom::{multi::many1, IResult}; | ||
|
||
use crate::primitives::non_empty_line; | ||
|
||
/// A block that's treated as contiguous lines of paragraph text (and subject to | ||
/// normal substitutions) (e.g., a paragraph block). | ||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub struct SimpleBlock<'a> { | ||
/// Lines that were found. | ||
pub inlines: Vec<&'a str>, | ||
} | ||
|
||
impl<'a> SimpleBlock<'a> { | ||
/// Parse a byte-slice as a simple AsciiDoc block. | ||
/// | ||
/// Returns a tuple of the remaining input and the simple block. | ||
#[allow(dead_code)] // TEMPORARY | ||
pub fn from_str(i: &'a str) -> IResult<&str, Self> { | ||
let (i, inlines) = many1(non_empty_line)(i)?; | ||
|
||
Ok((i, Self { inlines })) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub(crate) mod simple; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use nom::{ | ||
error::{Error, ErrorKind}, | ||
Err, | ||
}; | ||
|
||
use crate::blocks::simple::SimpleBlock; | ||
|
||
#[test] | ||
fn empty_source() { | ||
let expected_err: Err<Error<&str>> = Err::Error(Error::new("", ErrorKind::TakeTill1)); | ||
|
||
let actual_err = SimpleBlock::from_str("").unwrap_err(); | ||
|
||
assert_eq!(expected_err, actual_err); | ||
} | ||
|
||
#[test] | ||
fn only_spaces() { | ||
let expected_err: Err<Error<&str>> = Err::Error(Error::new(" ", ErrorKind::TakeTill1)); | ||
|
||
let actual_err = SimpleBlock::from_str(" ").unwrap_err(); | ||
|
||
assert_eq!(expected_err, actual_err); | ||
} | ||
|
||
#[test] | ||
fn single_line() { | ||
let expected = SimpleBlock { | ||
inlines: vec!["abc"], | ||
}; | ||
|
||
assert_eq!(SimpleBlock::from_str("abc"), Ok(("", expected))); | ||
} | ||
|
||
#[test] | ||
fn multiple_lines() { | ||
let expected = SimpleBlock { | ||
inlines: vec!["abc", "def"], | ||
}; | ||
|
||
assert_eq!( | ||
SimpleBlock::from_str("abc\ndef\n\nghi"), | ||
Ok(("\nghi", expected)) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
#![allow(clippy::panic)] | ||
#![allow(clippy::unwrap_used)] | ||
|
||
mod blocks; | ||
mod fixtures; | ||
mod primitives; | ||
mod strings; |