Sha256: 8de48b0891502f4d848c49a474e27575ba5912cad9f7104b745ef5c88a71e002

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

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, :tag, HTMLIdentifier, HTMLAttrs, 'Expression?']

    EmptyExp <<
      [:newline] | [:multi, 'EmptyExp*']

    HTMLAttrs <<
      Expression | [:html, :attrs, 'HTMLAttr*']

    HTMLAttr <<
      [:html, :attr, HTMLIdentifier, Expression]

    HTMLIdentifier <<
      Symbol | String

    Case <<
      [Condition, 'Expression*']

    Condition <<
      String | :else

    Bool <<
      true | false

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
temple-0.3.2 lib/temple/grammar.rb
temple-0.3.1 lib/temple/grammar.rb
temple-0.3.0 lib/temple/grammar.rb