diff options
author | wycats <wycats@gmail.com> | 2010-11-25 00:48:55 -0800 |
---|---|---|
committer | wycats <wycats@gmail.com> | 2010-11-25 00:50:57 -0800 |
commit | 85fa2cb65f4d62d7e48d62d9f6072bf6610b0fa3 (patch) | |
tree | 477e1e7b2847b74f6c204211d8a1340a8bc42f96 /lib/handlebars/jison_ext.js | |
download | handlebars.js-85fa2cb65f4d62d7e48d62d9f6072bf6610b0fa3.zip handlebars.js-85fa2cb65f4d62d7e48d62d9f6072bf6610b0fa3.tar.gz handlebars.js-85fa2cb65f4d62d7e48d62d9f6072bf6610b0fa3.tar.bz2 |
Initial commit. Note that I'm using CommonJS modules and node purely to help me develop this. If this ends up being useful, I will likely distribute the entire package as a single JS file for easier consumption in the browser.
Diffstat (limited to 'lib/handlebars/jison_ext.js')
-rw-r--r-- | lib/handlebars/jison_ext.js | 58 |
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; +} |