use crate::parsing::Parser;
use crate::parsing::result::ParseResult;
use crate::parsing::rule::{LineRequirement, Rule};
use crate::tree::Elements;
use std::fmt::{self, Debug};
mod arguments;
mod mapping;
mod parser;
mod rule;
pub mod blocks;
pub use self::arguments::Arguments;
pub use self::rule::{RULE_BLOCK, RULE_BLOCK_SKIP_NEWLINE, RULE_BLOCK_STAR};
#[derive(Clone)]
pub struct BlockRule {
name: &'static str,
accepts_names: &'static [&'static str],
accepts_star: bool,
accepts_score: bool,
accepts_newlines: bool,
parse_fn: BlockParseFn,
}
impl BlockRule {
#[cold]
pub fn rule(&self) -> Rule {
fn try_consume_fn<'r, 't>(
_: &mut Parser<'r, 't>,
) -> ParseResult<'r, 't, Elements<'t>> {
panic!("Pseudo rule for this block should not be executed directly!");
}
Rule {
name: self.name,
position: LineRequirement::Any,
try_consume_fn,
}
}
}
impl Debug for BlockRule {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("BlockRule")
.field("name", &self.name)
.field("accepts_names", &self.accepts_names)
.field("accepts_star", &self.accepts_star)
.field("accepts_score", &self.accepts_score)
.field("accepts_newlines", &self.accepts_newlines)
.field("parse_fn", &(self.parse_fn as *const ()))
.finish()
}
}
pub type BlockParseFn = for<'r, 't> fn(
&mut Parser<'r, 't>,
&'t str,
bool,
bool,
bool,
) -> ParseResult<'r, 't, Elements<'t>>;