Permalink
Browse files

Fixed code indentation when followed by newline(s). Closes #295 [repo…

…rted by masylum]
  • Loading branch information...
1 parent 71351b4 commit 727a3485f36ad768d1207553412b748f7e0fb63c @tj tj committed Aug 15, 2011
Showing with 18 additions and 2 deletions.
  1. +18 −2 lib/parser.js
View
@@ -63,6 +63,17 @@ Parser.prototype = {
advance: function(){
return this.lexer.advance();
},
+
+ /**
+ * Skip `n` tokens.
+ *
+ * @param {Number} n
+ * @api private
+ */
+
+ skip: function(n){
+ while (n--) this.advance();
+ },
/**
* Single token lookahead.
@@ -208,9 +219,14 @@ Parser.prototype = {
parseCode: function(){
var tok = this.expect('code')
- , node = new nodes.Code(tok.val, tok.buffer, tok.escape);
+ , node = new nodes.Code(tok.val, tok.buffer, tok.escape)
+ , block
+ , i = 1;
node.line = this.line();
- if ('indent' == this.peek().type) {
+ while (this.lookahead(i) && 'newline' == this.lookahead(i).type) ++i;
+ block = 'indent' == this.lookahead(i).type;
+ if (block) {
+ this.skip(i-1);
node.block = this.parseBlock();
}
return node;

0 comments on commit 727a348

Please sign in to comment.