Skip to content

Commit

Permalink
fix: move dist-ref parser to scoped-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
mhatzl committed Feb 11, 2024
1 parent 590ee62 commit 2f549b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
13 changes: 5 additions & 8 deletions inline/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use unimarkup_commons::lexer::token::iterator::{IteratorEndFn, IteratorPrefixFn, TokenIterator};

use crate::InlineTokenKind::Cite;
use crate::{
element::{formatting::OpenFormatMap, Inline},
tokenize::{iterator::InlineTokenIterator, kind::InlineTokenKind},
Expand Down Expand Up @@ -108,9 +107,8 @@ impl<'slice, 'input> InlineParser<'slice, 'input> {
break 'outer;
}

let parser_fn_opt = if kind == Cite {
get_distinct_reference_parser()
} else if (!parser.context.flags.logic_only && kind.is_scoped_format_keyword())
let parser_fn_opt = if (!parser.context.flags.logic_only
&& kind.is_scoped_format_keyword())
|| kind.is_open_parenthesis()
{
get_scoped_parser(kind, parser.context.flags.logic_only)
Expand Down Expand Up @@ -222,14 +220,13 @@ fn get_scoped_parser(kind: InlineTokenKind, logic_only: bool) -> Option<InlinePa
Some(crate::element::formatting::scoped::parse_math)
}
InlineTokenKind::OpenBracket if !logic_only => Some(crate::element::textbox::parse),
InlineTokenKind::Cite if !logic_only => {
Some(crate::element::substitution::parse_distinct_reference)
}
_ => None,
}
}

fn get_distinct_reference_parser() -> Option<InlineParserFn> {
Some(crate::element::substitution::parse_distinct_reference)
}

#[cfg(test)]
mod test {
use unimarkup_commons::lexer::token::iterator::TokenIterator;
Expand Down
5 changes: 4 additions & 1 deletion inline/src/tokenize/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ impl InlineTokenKind {
pub fn is_scoped_format_keyword(&self) -> bool {
matches!(
self,
InlineTokenKind::Verbatim | InlineTokenKind::Math | InlineTokenKind::NamedSubstitution
InlineTokenKind::Verbatim
| InlineTokenKind::Math
| InlineTokenKind::NamedSubstitution
| InlineTokenKind::Cite
)
}
}
Expand Down

0 comments on commit 2f549b9

Please sign in to comment.