use std::fmt;
use std::sync::Arc;
use techy::core::constructs::{
ArgumentParser, ConstructParserResult, OptionalGroupArgumentParser, ParseContext, ParsedArgumentNodes,
};
use techy::core::specs::ArgumentSpec;
use techy::core::token::GroupRule;
use crate::lang::mint::{DefinitionShape, FlmArgumentParser};
use crate::lang::{Flm, FlmGroupType};
pub const IDENTITY: &str = "flm.cells.styles";
pub struct CellStylesParser {
angles: OptionalGroupArgumentParser<Flm>,
}
impl CellStylesParser {
pub fn new() -> CellStylesParser {
let rule = Arc::new(GroupRule {
group_type: FlmGroupType::Content,
open: String::from("<"),
close: String::from(">"),
});
CellStylesParser { angles: OptionalGroupArgumentParser::new(rule) }
}
}
impl Default for CellStylesParser {
fn default() -> CellStylesParser {
CellStylesParser::new()
}
}
impl fmt::Debug for CellStylesParser {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("CellStylesParser")
}
}
impl ArgumentParser<Flm> for CellStylesParser {
fn parse_argument(
&self,
cx: &mut ParseContext<'_, '_, Flm>,
spec: &ArgumentSpec<Flm>,
) -> ConstructParserResult<Flm, Option<ParsedArgumentNodes<Flm>>> {
self.angles.parse_argument(cx, spec)
}
}
impl FlmArgumentParser for CellStylesParser {
fn identity(&self) -> Vec<u8> {
IDENTITY.as_bytes().to_vec()
}
fn definition_shape(&self) -> DefinitionShape {
DefinitionShape::NoShape { token: "cell-styles" }
}
fn description(&self) -> String {
String::from("an optional `<…>` group of style tokens")
}
}