grammar ValkyrieTemplate { patterns: ("*.vt", ".asgard"), parser: { text_raw: { rust: crate::helpers::parse_text_raw } }, inline: { import: false } } // === import rules === --------------------------------------------------------------------------------------------- //import Valkyrie.parser.{MainExpression, Identifier}; // === string template === --------------------------------------------------------------------------------------------- atomic class StringTemplates { StringTemplateTerm* EOI } union StringTemplateTerm { | ForTemplate | ExpressionTemplate } class ExpressionTemplate { TEMPLATE_S MainExpression TEMPLATE_E } // === for template === --------------------------------------------------------------------------------------------- atomic class ForTemplate { ForTemplateBegin ForTemplateElse? ForTemplateEnd } class ForTemplateBegin { TEMPLATE_S KW_FOR LetPattern KW_IN InlineExpression? IfGuard? TEMPLATE_E } class ForTemplateElse { TEMPLATE_S KW_ELSE TEMPLATE_E } class ForTemplateEnd { TEMPLATE_S KW_END KW_FOR? TEMPLATE_E } @railway(false) atomic class TEMPLATE_S { ^TEMPLATE_L TEMPLATE_M? } @railway(false) atomic class TEMPLATE_E { TEMPLATE_M? ^TEMPLATE_R } @railway(false) token { TEMPLATE_L: '<%' TEMPLATE_R: '%>' TEMPLATE_M: [-_~.=] }