Skip to content
Browse files

Use HandlebarsGrammar companion object

  • Loading branch information...
1 parent e179afd commit 49f3da5122cc9cf3a76f4dce8c9136c49d25167f @mwunsch committed Apr 13, 2012
View
3 src/main/scala/com/gilt/handlebars/Handlebars.scala
@@ -5,8 +5,7 @@ import com.gilt.handlebars._
object Handlebars {
def parse(template: String, delimiters: (String, String) = ("{{", "}}")) = {
- val grammar = new HandlebarsGrammar(delimiters)
- grammar.parseAll(grammar.root, template)
+ HandlebarsGrammar(delimiters).scan(template)
}
}
View
10 src/main/scala/com/gilt/handlebars/HandlebarsGrammar.scala
@@ -18,7 +18,15 @@ case class Mustache(value: Path,
case class Section(name: Path, value: Program, inverted: Boolean = false) extends Node
case class Program(value: List[Node]) extends Node
-class HandlebarsGrammar(delimiters: (String, String) = ("{{", "}}")) extends JavaTokenParsers {
+object HandlebarsGrammar {
+ def apply(delimiters: (String,String) = ("{{","}}")) = new HandlebarsGrammar(delimiters)
+}
+
+class HandlebarsGrammar(delimiters: (String, String)) extends JavaTokenParsers {
+
+ def scan(in: String) = {
+ parseAll(root, in)
+ }
def root: Parser[Program] = rep(content | statement) ^^ {Program(_)}
View
2 src/test/scala/com/gilt/handlebars/HandlebarsGrammarSpec.scala
@@ -6,7 +6,7 @@ import com.gilt.handlebars._
class HandlebarsGrammarSpec extends Specification with ParserMatchers {
- val parsers = new HandlebarsGrammar(("{{","}}"))
+ val parsers = HandlebarsGrammar(("{{","}}"))
"The Handlebars root grammar" should {

0 comments on commit 49f3da5

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