diff options
author | kpdecker <kpdecker@gmail.com> | 2011-07-30 10:25:30 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2011-07-30 10:25:30 -0500 |
commit | 2fc01ff73a1f53d634f03ac031112b58697e40a5 (patch) | |
tree | 8d9c7c483e4260effb027ec450dfdd9e5fa15809 /lib/handlebars/compiler/ast.js | |
parent | bba08ad95f119cf585558bd761f8c266843e4cff (diff) | |
download | handlebars.js-2fc01ff73a1f53d634f03ac031112b58697e40a5.zip handlebars.js-2fc01ff73a1f53d634f03ac031112b58697e40a5.tar.gz handlebars.js-2fc01ff73a1f53d634f03ac031112b58697e40a5.tar.bz2 |
Move art into compiler dir
Diffstat (limited to 'lib/handlebars/compiler/ast.js')
-rw-r--r-- | lib/handlebars/compiler/ast.js | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/lib/handlebars/compiler/ast.js b/lib/handlebars/compiler/ast.js new file mode 100644 index 0000000..6c3711b --- /dev/null +++ b/lib/handlebars/compiler/ast.js @@ -0,0 +1,103 @@ +var Handlebars = require("handlebars"); + +// BEGIN(BROWSER) +(function() { + + Handlebars.AST = {}; + + Handlebars.AST.ProgramNode = function(statements, inverse) { + this.type = "program"; + this.statements = statements; + if(inverse) { this.inverse = new Handlebars.AST.ProgramNode(inverse); } + }; + + Handlebars.AST.MustacheNode = function(params, hash, unescaped) { + this.type = "mustache"; + this.id = params[0]; + this.params = params.slice(1); + this.hash = hash; + this.escaped = !unescaped; + }; + + Handlebars.AST.PartialNode = function(id, context) { + this.type = "partial"; + + // TODO: disallow complex IDs + + this.id = id; + this.context = context; + }; + + var verifyMatch = function(open, close) { + if(open.original !== close.original) { + throw new Handlebars.Exception(open.original + " doesn't match " + close.original); + } + }; + + Handlebars.AST.BlockNode = function(mustache, program, close) { + verifyMatch(mustache.id, close); + this.type = "block"; + this.mustache = mustache; + this.program = program; + }; + + Handlebars.AST.InverseNode = function(mustache, program, close) { + verifyMatch(mustache.id, close); + this.type = "inverse"; + this.mustache = mustache; + this.program = program; + }; + + Handlebars.AST.ContentNode = function(string) { + this.type = "content"; + this.string = string; + }; + + Handlebars.AST.HashNode = function(pairs) { + this.type = "hash"; + this.pairs = pairs; + }; + + Handlebars.AST.IdNode = function(parts) { + this.type = "ID"; + this.original = parts.join("."); + + var dig = [], depth = 0; + + for(var i=0,l=parts.length; i<l; i++) { + var part = parts[i]; + + if(part === "..") { depth++; } + else if(part === "." || part === "this") { this.isScoped = true; } + else { dig.push(part); } + } + + this.parts = dig; + this.string = dig.join('.'); + this.depth = depth; + this.isSimple = (dig.length === 1) && (depth === 0); + }; + + Handlebars.AST.StringNode = function(string) { + this.type = "STRING"; + this.string = string; + }; + + Handlebars.AST.IntegerNode = function(integer) { + this.type = "INTEGER"; + this.integer = integer; + }; + + Handlebars.AST.BooleanNode = function(bool) { + this.type = "BOOLEAN"; + this.bool = bool; + }; + + Handlebars.AST.CommentNode = function(comment) { + this.type = "comment"; + this.comment = comment; + }; + +})(); +// END(BROWSER) + |