-
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
11 changed files
with
155 additions
and
17 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
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 |
---|---|---|
@@ -1,22 +1,31 @@ | ||
use nom::{multi::many1, IResult}; | ||
|
||
use crate::{ | ||
primitives::{consume_empty_lines, non_empty_line}, | ||
Span, | ||
primitives::{consume_empty_lines, non_empty_line, trim_input_for_rem}, | ||
HasSpan, Span, | ||
}; | ||
|
||
/// 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. | ||
/// TO DO: Make private | ||
pub inlines: Vec<Span<'a>>, | ||
|
||
source: Span<'a>, | ||
} | ||
|
||
impl<'a> SimpleBlock<'a> { | ||
#[allow(dead_code)] // TEMPORARY | ||
pub(crate) fn parse(i: Span<'a>) -> IResult<Span, Self> { | ||
let (i, inlines) = many1(non_empty_line)(i)?; | ||
Ok((consume_empty_lines(i), Self { inlines })) | ||
pub(crate) fn parse(source: Span<'a>) -> IResult<Span, Self> { | ||
let (rem, inlines) = many1(non_empty_line)(source)?; | ||
let source = trim_input_for_rem(source, rem); | ||
Ok((consume_empty_lines(rem), Self { inlines, source })) | ||
} | ||
} | ||
|
||
impl<'a> HasSpan<'a> for SimpleBlock<'a> { | ||
fn span(&'a self) -> &'a Span<'a> { | ||
&self.source | ||
} | ||
} |
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,9 @@ | ||
use crate::Span; | ||
|
||
/// Any syntactic element can describe its location | ||
/// within the source material using this trait. | ||
pub trait HasSpan<'a> { | ||
/// Return a [`Span`] describing the syntactic element's | ||
/// location within the source string/file. | ||
fn span(&'a self) -> &'a Span<'a>; | ||
} |
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
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
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
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