Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Unescaped var syntax

  • Loading branch information...
commit 48dee50f44133feb5bdb4026976048d71150d364 1 parent f9b22b3
Mark Wunsch authored April 08, 2012
12  src/main/scala/com/gilt/handlebars/Handlebars.scala
@@ -16,13 +16,21 @@ class HandlebarsGrammar(delimiters: (String, String)) extends JavaTokenParsers {
16 16
 
17 17
   def root = rep(mustache | text)
18 18
 
19  
-  def mustache = expression(opt(whiteSpace) ~> ident <~ opt(whiteSpace) ^^ { Mustache(_) })
  19
+  def mustache = unescapedVariable | variable
  20
+
  21
+  def unescapedVariable =
  22
+      expression("{" ~> identifier <~ "}" ^^ { Variable(_, true) }) |
  23
+      expression("&" ~> identifier ^^ { Variable(_, true)})
  24
+
  25
+  def variable = expression(identifier ^^ { Variable(_) })
20 26
 
21 27
   def text = rep1(not(openDelimiter) ~> ".|\r|\n".r) ^^ {t => Text(t.mkString("")) }
22 28
 
23 29
   def expression[T <: Node](parser: Parser[T]) =
24 30
       positioned(openDelimiter ~> parser <~ closeDelimiter)
25 31
 
  32
+  def identifier = opt(whiteSpace) ~> ident <~ opt(whiteSpace)
  33
+
26 34
   def openDelimiter = delimiters._1
27 35
 
28 36
   def closeDelimiter = delimiters._2
@@ -33,6 +41,6 @@ class HandlebarsGrammar(delimiters: (String, String)) extends JavaTokenParsers {
33 41
 
34 42
 sealed abstract class Node extends Positional
35 43
 
36  
-case class Mustache(value: String) extends Node
  44
+case class Variable(value: String, unescape: Boolean = false) extends Node
37 45
 
38 46
 case class Text(value: String) extends Node

0 notes on commit 48dee50

Please sign in to comment.
Something went wrong with that request. Please try again.