Skip to content

Instantly share code, notes, and snippets.

@localhostdotdev
Created May 12, 2019 16:05
Show Gist options
  • Save localhostdotdev/ba7b38b1b4a1c6ba6c799ee3c63c1fa6 to your computer and use it in GitHub Desktop.
Save localhostdotdev/ba7b38b1b4a1c6ba6c799ee3c63c1fa6 to your computer and use it in GitHub Desktop.
{ function j(string) { return string.join('') } }
template =
(
interpolation /
tag /
$(!interpolation !tag .)
)+
ws = (" " / "\n")*
value = [^ ]
// {{ this }}
open_interpolation = "{{"
close_interpolation = "}}"
not_close_interpolation =
ws !close_interpolation m:value ws { return m }
interpolation =
open_interpolation m:not_close_interpolation+ close_interpolation { return j(m) }
// {% this %}
open_tag = "{%"
close_tag = "%}"
not_close_tag =
ws !close_tag m:value ws { return m }
tag_start = !tag_end open_tag m:not_close_tag+ close_tag { return j(m) }
tag_end = open_tag ws "end" not_close_tag+ close_tag
tag = tag_start template tag_end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment