Skip to content

Instantly share code, notes, and snippets.

@pvande
Created July 14, 2014 06:28
Show Gist options
  • Save pvande/3e59ef36a1f6a67b9716 to your computer and use it in GitHub Desktop.
Save pvande/3e59ef36a1f6a67b9716 to your computer and use it in GitHub Desktop.
# Casual Grammar
/{{\s*\W?\s*\w+\s*}}|{{!.*?}}|{{{\s*(\w+)\s*}}}/g
# Informal Grammar
<template> ::= (<static-content> <tag>)* <static-content>
<static-content> ::= <text>+
<tag> ::= "{{" <whitespace>* [<tag-type>] <whitespace>* <tag-name> <whitespace>* "}}" |
"{{!" <text>* "}}" |
"{{{" <whitespace>* <tag-name> <whitespace>* "}}}"
<tag-type> ::= "#" | "^" | "/" | "&" | ">"
<tag-name> ::= <non-whitespace>+ ["." <tag-name>]
# Formal Grammar
<template> ::= (<static-content> <tag>)* <static-content>
<static-content> ::= <text>+
<tag-content> ::= <whitespace>* <tag-name> <whitespace>*
<tag-name> ::= <non-whitespace>+ ["." <tag-name>]
<tag> ::= <tag:comment> |
<tag:raw-interpolation> |
<tag:escaped-interpolation> |
<tag:section> |
<tag:inverted-section> |
<tag:section-close> |
<tag:partial>
<tag:comment> ::= "{{!" <text>* "}}"
<tag:raw-interpolation> ::= "{{{" <tag-content> "}}}" |
"{{" <whitespace>* "&" <tag-content> "}}"
<tag:escaped-interpolation> ::= "{{" <tag-content> "}}"
<tag:section> ::= "{{" <whitespace>* "#" <tag-content> "}}"
<tag:inverted-section> ::= "{{" <whitespace>* "^" <tag-content> "}}"
<tag:section-close> ::= "{{" <whitespace>* "/" <tag-content> "}}"
<tag:partial> ::= "{{" <whitespace>* ">" <tag-content> "}}"
# Super Formal Grammar
<tag-delimiter:open> ::= "{{"
<tag-delimiter:close> ::= "}}"
<template> ::= (<text> <tag>)* <text>
<tag-name> ::= <non-whitespace>+ ["." <tag-name>]
<tag-open> ::= <tag-delimiter:open> <whitespace>*
<tag-close> ::= <whitespace>* <tag-delimiter:close>
<tag> ::= <tag:comment> |
<tag:change-delimiter> |
<tag:raw-interpolation> |
<tag:escaped-interpolation> |
<tag:section> |
<tag:inverted-section> |
<tag:section-close> |
<tag:partial>
<tag:comment> ::= <tag-open> "!" <text>* <tag-close>
<tag:change-delimiter> ::= <tag-delimiter:open> "=" <whitespace>* <new-delimiters> <whitespace>* "=" <tag-delimiter:close>
<new-delimiters> ::= <new-delimiter:open> <whitespace>+ <new-delimiter:close>
<new-delimiter:open> ::= <non-whitespace>+
<new-delimiter:close> ::= <non-whitespace>+
<tag:raw-interpolation> ::= <tag-delimiter:open> "{" <whitespace>* <tag-name> <whitespace>* "}" <tag-delimiter:close> |
<tag-open> "&" <whitespace>* <tag-name> <tag-close>
<tag:escaped-interpolation> ::= <tag-open> <tag-name> <tag-close>
<tag:section> ::= <tag-open> "#" <whitespace>* <tag-name> <tag-close>
<tag:inverted-section> ::= <tag-open> "^" <whitespace>* <tag-name> <tag-close>
<tag:section-close> ::= <tag-open> "/" <whitespace>* <tag-name> <tag-close>
<tag:partial> ::= <tag-open> ">" <whitespace>* <tag-name> <tag-close>
@tenderlove
Copy link

This is awesome, but will it work with this spec? It looks like there's weird stuff with "standalone" tags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment