grammar ValkyrieTemplate { patterns: ("*.vt", ".asgard"), inline: { import: false } } // === import rules === ------------------------------------------------------------------------------------------------ @replace_hide(false) import Valkyrie.{KW_FOR, KW_ELSE, LetPattern}; // === 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: [-_~.=] }