Implement log levels
This commit is contained in:
parent
2cdf68082a
commit
874cac2df1
25 changed files with 497 additions and 223 deletions
|
|
@ -17,7 +17,7 @@ pub fn parse(
|
|||
tokens: &mut Vec<Token>,
|
||||
graph: &Graph,
|
||||
) -> bool {
|
||||
log!("Solving: {}", state.clone().buffers.anchor);
|
||||
log!(VERBOSE, "Solving: {}", state.clone().buffers.anchor);
|
||||
let buffer = &mut state.buffers.anchor;
|
||||
let candidate = &mut buffer.candidate;
|
||||
|
||||
|
|
@ -25,16 +25,18 @@ pub fn parse(
|
|||
// would already have set its text to the word before the first pipe
|
||||
if candidate.text().is_empty() {
|
||||
log!(
|
||||
VERBOSE,
|
||||
"Seeking end of text at {:#?} -> {:#?}",
|
||||
lexeme.text(),
|
||||
lexeme.next()
|
||||
);
|
||||
if lexeme.next() == "|" {
|
||||
log!("End: Next lexeme is a pipe");
|
||||
log!(VERBOSE, "End: Next lexeme is a pipe");
|
||||
buffer.text.push_str(&lexeme.text());
|
||||
candidate.set_text(&buffer.text.clone());
|
||||
} else {
|
||||
log!(
|
||||
VERBOSE,
|
||||
"Pushing non-terminal {:#?} into buffer {:#?}",
|
||||
lexeme.text(),
|
||||
buffer.text
|
||||
|
|
@ -46,6 +48,7 @@ pub fn parse(
|
|||
|
||||
if candidate.destination().is_none() {
|
||||
log!(
|
||||
VERBOSE,
|
||||
"Seeking end of destination at {:#?} -> {:#?}",
|
||||
lexeme.text(),
|
||||
lexeme.next()
|
||||
|
|
@ -57,7 +60,7 @@ pub fn parse(
|
|||
&& lexeme.is_next_boundary()
|
||||
&& !lexeme.match_next_char('|')
|
||||
{
|
||||
log!("End: Plural anchor");
|
||||
log!(VERBOSE, "End: Plural anchor");
|
||||
candidate.set_destination(Some(&candidate.text().clone()));
|
||||
candidate.text_push("s");
|
||||
if lexeme.last() {
|
||||
|
|
@ -65,7 +68,7 @@ pub fn parse(
|
|||
}
|
||||
return true;
|
||||
} else if lexeme.match_char('|') && lexeme.is_next_delimiter() {
|
||||
log!("End: Pipe followed by delimiter");
|
||||
log!(VERBOSE, "End: Pipe followed by delimiter");
|
||||
if buffer.destination.is_empty() {
|
||||
if candidate.text().contains(':') {
|
||||
candidate.set_external(true);
|
||||
|
|
@ -76,29 +79,32 @@ pub fn parse(
|
|||
}
|
||||
return true;
|
||||
} else if lexeme.match_char('|') && !candidate.balanced() {
|
||||
log!("State: Found a pipe, but no boundary: destination follows");
|
||||
log!(
|
||||
VERBOSE,
|
||||
"State: Found a pipe, but no boundary: destination follows"
|
||||
);
|
||||
candidate.set_balanced(true);
|
||||
return true;
|
||||
} else if lexeme.match_char(':') {
|
||||
log!("State: Found a colon, marking anchor as external");
|
||||
log!(VERBOSE, "State: Found a colon, marking anchor as external");
|
||||
candidate.set_external(true);
|
||||
buffer.destination.push_str(&lexeme.text());
|
||||
return true;
|
||||
} else if lexeme.match_char('|') {
|
||||
log!("End: Explicit end-of-destination pipe");
|
||||
log!(VERBOSE, "End: Explicit end-of-destination pipe");
|
||||
candidate.set_destination(Some(&buffer.destination.clone()));
|
||||
return true;
|
||||
} else if !candidate.external() && lexeme.is_delimiter() {
|
||||
log!("End: Internal anchor trailed by delimiter");
|
||||
log!(VERBOSE, "End: Internal anchor trailed by delimiter");
|
||||
push(Some(&buffer.destination.clone()), tokens, state, graph);
|
||||
return false;
|
||||
} else if lexeme.is_next_whitespace() {
|
||||
log!("End: next is whitespace");
|
||||
log!(VERBOSE, "End: next is whitespace");
|
||||
buffer.destination.push_str(&lexeme.text());
|
||||
push(Some(&buffer.destination.clone()), tokens, state, graph);
|
||||
return true;
|
||||
} else if lexeme.last() {
|
||||
log!("End: end of input");
|
||||
log!(VERBOSE, "End: end of input");
|
||||
buffer.destination.push_str(&lexeme.text());
|
||||
push(Some(&buffer.destination.clone()), tokens, state, graph);
|
||||
return true;
|
||||
|
|
@ -107,6 +113,7 @@ pub fn parse(
|
|||
// pushing lexemes into the buffer until an end is found above
|
||||
} else {
|
||||
log!(
|
||||
VERBOSE,
|
||||
"Pushing non-terminal {:#?} into buffer {:#?}",
|
||||
lexeme.text(),
|
||||
buffer.destination,
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ pub fn parse(
|
|||
match state.context.block {
|
||||
Block::None => {
|
||||
if PreFormat::probe(lexeme) {
|
||||
log!("Block Context: None -> PreFormat on {lexeme}");
|
||||
log!(VERBOSE, "Block Context: None -> PreFormat on {lexeme}");
|
||||
state.context.block = Block::PreFormat;
|
||||
tokens.push(Token::PreFormat(PreFormat::new(true)));
|
||||
return true;
|
||||
|
|
@ -33,19 +33,19 @@ pub fn parse(
|
|||
iterator.peek().map_or(&Lexeme::default(), |l| l),
|
||||
&mut state.dom_ids,
|
||||
));
|
||||
log!("Block Context: None -> Header on {lexeme}");
|
||||
log!(VERBOSE, "Block Context: None -> Header on {lexeme}");
|
||||
state.context.block = Block::Header(header.level());
|
||||
tokens.push(Token::Header(header));
|
||||
return true;
|
||||
} else if List::probe(lexeme) {
|
||||
log!("Block Context: None -> List on {lexeme}");
|
||||
log!(VERBOSE, "Block Context: None -> List on {lexeme}");
|
||||
state.context.block = Block::List;
|
||||
state.buffers.list.candidate.ordered = lexeme.match_char('+');
|
||||
return super::list::parse(
|
||||
lexeme, state, tokens, iterator, graph,
|
||||
);
|
||||
} else if Paragraph::probe(lexeme) {
|
||||
log!("Block Context: None -> Paragraph on {lexeme}");
|
||||
log!(VERBOSE, "Block Context: None -> Paragraph on {lexeme}");
|
||||
state.context.block = Block::Paragraph;
|
||||
tokens.push(Token::Paragraph(Paragraph::new(true)));
|
||||
}
|
||||
|
|
@ -53,7 +53,7 @@ pub fn parse(
|
|||
Block::PreFormat => {
|
||||
if PreFormat::probe(lexeme) {
|
||||
tokens.push(Token::PreFormat(PreFormat::new(false)));
|
||||
log!("Block Context: PreFormat -> None on {lexeme}");
|
||||
log!(VERBOSE, "Block Context: PreFormat -> None on {lexeme}");
|
||||
state.context.block = Block::None;
|
||||
} else {
|
||||
tokens.push(Token::Literal(Literal::lex(lexeme)));
|
||||
|
|
@ -63,14 +63,14 @@ pub fn parse(
|
|||
Block::Paragraph => {
|
||||
if Paragraph::probe_end(lexeme) {
|
||||
tokens.push(Token::Paragraph(Paragraph::new(false)));
|
||||
log!("Block Context: Paragraph -> None on {lexeme}");
|
||||
log!(VERBOSE, "Block Context: Paragraph -> None on {lexeme}");
|
||||
state.context.block = Block::None;
|
||||
}
|
||||
},
|
||||
Block::Header(n) => {
|
||||
if lexeme.text() == "\n" {
|
||||
tokens.push(Token::Header(Header::from_u8(n, false, None)));
|
||||
log!("Block Context: Header -> None on {lexeme}");
|
||||
log!(VERBOSE, "Block Context: Header -> None on {lexeme}");
|
||||
state.context.block = Block::None;
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -24,12 +24,12 @@ pub fn parse(
|
|||
match state.context.inline {
|
||||
Inline::None => {
|
||||
if Code::probe(lexeme) {
|
||||
log!("Inline Context: None -> Code on {lexeme}");
|
||||
log!(VERBOSE, "Inline Context: None -> Code on {lexeme}");
|
||||
state.context.inline = Inline::Code;
|
||||
tokens.push(Token::Code(Code::new(true)));
|
||||
return true;
|
||||
} else if Anchor::probe(lexeme) {
|
||||
log!("Inline Context: None -> Anchor on {lexeme}");
|
||||
log!(VERBOSE, "Inline Context: None -> Anchor on {lexeme}");
|
||||
state.context.inline = Inline::Anchor;
|
||||
state.buffers.anchor = AnchorBuffer::default();
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ pub fn parse(
|
|||
},
|
||||
Inline::Code => {
|
||||
if Code::probe(lexeme) {
|
||||
log!("Inline Context: Code -> None on {lexeme}");
|
||||
log!(VERBOSE, "Inline Context: Code -> None on {lexeme}");
|
||||
state.context.inline = Inline::None;
|
||||
tokens.push(Token::Code(Code::new(false)));
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -55,14 +55,14 @@ pub fn parse(
|
|||
candidate.items.push(item_candidate.clone());
|
||||
}
|
||||
// push list candidate, reset state and exit context
|
||||
log!("Accepting list candidate {candidate}");
|
||||
log!(VERBOSE, "Accepting list candidate {candidate}");
|
||||
tokens.push(Token::List(candidate.clone()));
|
||||
state.context.block = Block::None;
|
||||
iterator.next();
|
||||
*buffer = state::ListBuffer::default();
|
||||
} else if lexeme.match_char('\n') {
|
||||
// found end of item, push it and reset state
|
||||
log!("Accepting item candidate {item_candidate}");
|
||||
log!(VERBOSE, "Accepting item candidate {item_candidate}");
|
||||
let (text, format_tokens) = format(&item_candidate.text, graph);
|
||||
item_candidate.text = text;
|
||||
state.format_tokens.extend_from_slice(&format_tokens);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue