flm_core/stdlib/features/cells/
parser.rs1use std::fmt;
15use std::sync::Arc;
16
17use techy::core::constructs::{
18 ArgumentParser, ConstructParserResult, OptionalGroupArgumentParser, ParseContext, ParsedArgumentNodes,
19};
20use techy::core::specs::ArgumentSpec;
21use techy::core::token::GroupRule;
22
23use crate::lang::mint::{DefinitionShape, FlmArgumentParser};
24use crate::lang::{Flm, FlmGroupType};
25
26pub const IDENTITY: &str = "flm.cells.styles";
28
29pub struct CellStylesParser {
39 angles: OptionalGroupArgumentParser<Flm>,
40}
41
42impl CellStylesParser {
43 pub fn new() -> CellStylesParser {
45 let rule = Arc::new(GroupRule {
46 group_type: FlmGroupType::Content,
47 open: String::from("<"),
48 close: String::from(">"),
49 });
50 CellStylesParser { angles: OptionalGroupArgumentParser::new(rule) }
51 }
52}
53
54impl Default for CellStylesParser {
55 fn default() -> CellStylesParser {
56 CellStylesParser::new()
57 }
58}
59
60impl fmt::Debug for CellStylesParser {
61 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62 f.write_str("CellStylesParser")
63 }
64}
65
66impl ArgumentParser<Flm> for CellStylesParser {
67 fn parse_argument(
68 &self,
69 cx: &mut ParseContext<'_, '_, Flm>,
70 spec: &ArgumentSpec<Flm>,
71 ) -> ConstructParserResult<Flm, Option<ParsedArgumentNodes<Flm>>> {
72 self.angles.parse_argument(cx, spec)
73 }
74}
75
76impl FlmArgumentParser for CellStylesParser {
77 fn identity(&self) -> Vec<u8> {
78 IDENTITY.as_bytes().to_vec()
79 }
80
81 fn definition_shape(&self) -> DefinitionShape {
82 DefinitionShape::NoShape { token: "cell-styles" }
83 }
84
85 fn description(&self) -> String {
86 String::from("an optional `<…>` group of style tokens")
87 }
88}