summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/jison_ext.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/handlebars/jison_ext.js')
-rw-r--r--lib/handlebars/jison_ext.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/handlebars/jison_ext.js b/lib/handlebars/jison_ext.js
new file mode 100644
index 0000000..0608034
--- /dev/null
+++ b/lib/handlebars/jison_ext.js
@@ -0,0 +1,58 @@
+var Lexer = function() {};
+
+Lexer.prototype = {
+ setInput: function(input) {
+ this.input = input;
+ this.yylineno = 0;
+ },
+
+ setupLex: function() {
+ this.yyleng = 0;
+ this.yytext = '';
+ },
+
+ getchar: function(n) {
+ n = n || 1;
+ var char = "";
+
+ for(var i=0; i<n; i++) {
+ char += this.input[0];
+ this.yytext += this.input[0];
+ this.yyleng++;
+
+ if(char === "\n") this.yylineno++;
+
+ this.input = this.input.slice(1);
+ }
+ return char;
+ },
+
+ readchar: function(n) {
+ n = n || 1;
+ var char;
+
+ for(var i=0; i<n; i++) {
+ char = this.input[i];
+ if(char === "\n") this.yylineno++;
+ }
+
+ this.input = this.input.slice(n);
+ },
+
+ peek: function(n) {
+ return this.input.slice(0, n || 1);
+ }
+};
+
+var Visitor = function() {};
+
+Visitor.prototype = {
+ accept: function(object) {
+ return this[object.type](object);
+ }
+}
+
+if(exports) {
+ exports.Lexer = Lexer;
+ exports.Visitor = Visitor;
+}