aboutsummaryrefslogtreecommitdiffstats
path: root/src/content
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-22 15:03:15 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-22 15:03:15 +0200
commit41fc406af206e21014eaaba94bcf6b1854f892b3 (patch)
tree510f6e1d763643da9072f9cf7e097e777fdbd5b8 /src/content
parent37fad739ba73d488d4c3652caee01f1ec5d0aaaa (diff)
downloadmarkdown-rs-41fc406af206e21014eaaba94bcf6b1854f892b3.tar.gz
markdown-rs-41fc406af206e21014eaaba94bcf6b1854f892b3.tar.bz2
markdown-rs-41fc406af206e21014eaaba94bcf6b1854f892b3.zip
Refactor to pass ints instead of vecs around
Diffstat (limited to 'src/content')
-rw-r--r--src/content/document.rs8
-rw-r--r--src/content/flow.rs12
-rw-r--r--src/content/string.rs2
-rw-r--r--src/content/text.rs2
4 files changed, 12 insertions, 12 deletions
diff --git a/src/content/document.rs b/src/content/document.rs
index 1a0ffee..163dcda 100644
--- a/src/content/document.rs
+++ b/src/content/document.rs
@@ -363,10 +363,10 @@ fn containers_after(
tokenizer.go_until(
state,
|code| matches!(code, Code::CarriageReturnLineFeed | Code::Char('\n' | '\r')),
- move |(state, remainder)| {
+ move |(state, back)| {
(
State::Fn(Box::new(move |t, c| flow_end(t, c, info, state))),
- remainder,
+ back,
)
},
)(tokenizer, code)
@@ -415,7 +415,7 @@ fn flow_end(
resolve(tokenizer, &mut info);
- (State::Ok, Some(vec![code]))
+ (State::Ok, if matches!(code, Code::None) { 0 } else { 1 })
}
State::Nok => unreachable!("unexpected `nok` from flow"),
State::Fn(func) => {
@@ -441,7 +441,7 @@ fn exit_containers(
info.next = Box::new(flow); // This is weird but Rust needs a function there.
let result = tokenizer.flush(next);
assert!(matches!(result.0, State::Ok));
- assert!(result.1.is_none());
+ assert_eq!(result.1, 0);
if *phase == Phase::Prefix {
info.index = tokenizer.events.len();
diff --git a/src/content/flow.rs b/src/content/flow.rs
index e52f113..722e2bb 100644
--- a/src/content/flow.rs
+++ b/src/content/flow.rs
@@ -41,7 +41,7 @@ use crate::tokenizer::{Code, State, StateFnResult, Tokenizer};
/// ```
pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
match code {
- Code::None => (State::Ok, None),
+ Code::None => (State::Ok, 0),
_ => tokenizer.attempt(blank_line, |ok| {
Box::new(if ok { blank_line_after } else { initial_before })
})(tokenizer, code),
@@ -62,7 +62,7 @@ pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
/// ```
fn initial_before(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
match code {
- Code::None => (State::Ok, None),
+ Code::None => (State::Ok, 0),
_ => tokenizer.attempt_n(
vec![
Box::new(code_indented),
@@ -87,14 +87,14 @@ fn initial_before(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
/// ```
fn blank_line_after(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
match code {
- Code::None => (State::Ok, None),
+ Code::None => (State::Ok, 0),
Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => {
tokenizer.enter(Token::BlankLineEnding);
tokenizer.consume(code);
tokenizer.exit(Token::BlankLineEnding);
// Feel free to interrupt.
tokenizer.interrupt = false;
- (State::Fn(Box::new(start)), None)
+ (State::Fn(Box::new(start)), 0)
}
_ => unreachable!("expected eol/eof"),
}
@@ -111,12 +111,12 @@ fn blank_line_after(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
/// ```
fn after(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
match code {
- Code::None => (State::Ok, None),
+ Code::None => (State::Ok, 0),
Code::CarriageReturnLineFeed | Code::Char('\n' | '\r') => {
tokenizer.enter(Token::LineEnding);
tokenizer.consume(code);
tokenizer.exit(Token::LineEnding);
- (State::Fn(Box::new(start)), None)
+ (State::Fn(Box::new(start)), 0)
}
_ => unreachable!("expected eol/eof"),
}
diff --git a/src/content/string.rs b/src/content/string.rs
index 609a788..f63b8be 100644
--- a/src/content/string.rs
+++ b/src/content/string.rs
@@ -29,7 +29,7 @@ const MARKERS: [Code; 5] = [
/// Before string.
pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
match code {
- Code::None => (State::Ok, None),
+ Code::None => (State::Ok, 0),
_ => tokenizer.attempt_n(
vec![
Box::new(character_reference),
diff --git a/src/content/text.rs b/src/content/text.rs
index 73a798a..c339324 100644
--- a/src/content/text.rs
+++ b/src/content/text.rs
@@ -47,7 +47,7 @@ const MARKERS: [Code; 12] = [
/// Before text.
pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
match code {
- Code::None => (State::Ok, None),
+ Code::None => (State::Ok, 0),
_ => tokenizer.attempt_n(
vec![
Box::new(attention),