diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-06-20 17:06:00 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-06-20 17:06:00 +0200 |
commit | 65dd765cceee8bdccc74c08066eec59a579a16b1 (patch) | |
tree | cb60ab00039135b6f0a65efcb508f73a8b39aa11 /src/construct/partial_whitespace.rs | |
parent | 61271d73128f8553f8c4c17927828cde52a25eba (diff) | |
download | markdown-rs-65dd765cceee8bdccc74c08066eec59a579a16b1.tar.gz markdown-rs-65dd765cceee8bdccc74c08066eec59a579a16b1.tar.bz2 markdown-rs-65dd765cceee8bdccc74c08066eec59a579a16b1.zip |
Add improved whitespace handling
* add several helpers for parsing betwen x and y `space_or_tab`s
* use those helpers in a bunch of places
* move initial indent parsing to flow constructs themselves
Diffstat (limited to '')
-rw-r--r-- | src/construct/partial_whitespace.rs | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/src/construct/partial_whitespace.rs b/src/construct/partial_whitespace.rs deleted file mode 100644 index b8cf9a7..0000000 --- a/src/construct/partial_whitespace.rs +++ /dev/null @@ -1,64 +0,0 @@ -//! A little helper to parse `space_or_tab` -//! -//! They’re formed with the following BNF: -//! -//! ```bnf -//! space_or_tab ::= 1*(' ' '\t') -//! ``` -//! -//! Depending on where whitespace can occur, it can be optional (or not), -//! and present in the rendered result (or not). -//! -//! ## References -//! -//! * [`micromark-factory-space/index.js` in `micromark`](https://github.com/micromark/micromark/blob/main/packages/micromark-factory-space/dev/index.js) - -use crate::tokenizer::{Code, State, StateFnResult, TokenType, Tokenizer}; - -// To do: should `token_type` be a `Some`, with `None` defaulting to something? -// To do: should `max: Some(usize)` be added? - -/// Before whitespace. -/// -/// ```markdown -/// alpha| bravo -/// ``` -pub fn start(tokenizer: &mut Tokenizer, code: Code, token_type: TokenType) -> StateFnResult { - match code { - Code::VirtualSpace | Code::Char('\t' | ' ') => { - // To do: lifetimes. - let clone = token_type.clone(); - tokenizer.enter(token_type); - tokenizer.consume(code); - ( - State::Fn(Box::new(|tokenizer, code| inside(tokenizer, code, clone))), - None, - ) - } - _ => (State::Nok, None), - } -} - -/// In whitespace. -/// -/// ```markdown -/// alpha |bravo -/// alpha | bravo -/// ``` -fn inside(tokenizer: &mut Tokenizer, code: Code, token_type: TokenType) -> StateFnResult { - match code { - Code::VirtualSpace | Code::Char('\t' | ' ') => { - tokenizer.consume(code); - ( - State::Fn(Box::new(|tokenizer, code| { - inside(tokenizer, code, token_type) - })), - None, - ) - } - _ => { - tokenizer.exit(token_type); - (State::Ok, Some(vec![code])) - } - } -} |