1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
# frozen_string_literal: true
module Temple
# Temple expression grammar which can be used to validate Temple expressions.
#
# Example:
# Temple::Grammar.match? [:static, 'Valid Temple Expression']
# Temple::Grammar.validate! [:multi, 'Invalid Temple Expression']
#
# See {file:EXPRESSIONS.md Expression documentation}.
#
# @api public
module Grammar
extend Mixins::GrammarDSL
Expression <<
# Core abstraction
[:multi, 'Expression*'] |
[:static, String] |
[:dynamic, String] |
[:code, String] |
[:capture, String, Expression] |
[:newline] |
# Control flow abstraction
[:if, String, Expression, 'Expression?'] |
[:block, String, Expression] |
[:case, String, 'Case*'] |
[:cond, 'Case*'] |
# Escape abstraction
[:escape, Bool, Expression] |
# HTML abstraction
[:html, :doctype, String] |
[:html, :comment, Expression] |
[:html, :condcomment, String, Expression]|
[:html, :js, Expression] |
[:html, :tag, HTMLIdentifier, Expression, 'Expression?'] |
[:html, :attrs, 'HTMLAttr*'] |
HTMLAttr
EmptyExp <<
[:newline] | [:multi, 'EmptyExp*']
HTMLAttr <<
[:html, :attr, HTMLIdentifier, Expression]
HTMLIdentifier <<
Symbol | String
Case <<
[Condition, Expression]
Condition <<
String | :else
Bool <<
true | false
end
end
|