small refactor.

This commit is contained in:
Christopher Jeffrey 2013-01-03 01:06:58 -06:00
parent aef3a954da
commit 079cbe8b6a

View File

@ -89,11 +89,11 @@ Lexer.lex = function(src, options) {
}; };
Lexer.prototype.lex = function(src) { Lexer.prototype.lex = function(src) {
this.src = src src = src
.replace(/\r\n|\r/g, '\n') .replace(/\r\n|\r/g, '\n')
.replace(/\t/g, ' '); .replace(/\t/g, ' ');
return this.token(this.src, true); return this.token(src, true);
}; };
Lexer.prototype.token = function(src, top) { Lexer.prototype.token = function(src, top) {
@ -562,9 +562,6 @@ Parser.prototype.parse = function(src) {
out += this.tok(); out += this.tok();
} }
this.tokens = [];
this.token = null;
return out; return out;
}; };
@ -572,12 +569,14 @@ Parser.prototype.next = function() {
return this.token = this.tokens.pop(); return this.token = this.tokens.pop();
}; };
Parser.prototype.parseText = function() { Parser.prototype.peek = function() {
var body = this.token.text return this.tokens[this.tokens.length-1] || 0;
, top; };
while ((top = this.tokens[this.tokens.length-1]) Parser.prototype.parseText = function() {
&& top.type === 'text') { var body = this.token.text;
while (this.peek().type === 'text') {
body += '\n' + this.next().text; body += '\n' + this.next().text;
} }