diff --git a/lib/lexer.js b/lib/lexer.js index 77717bf7..fde8b3e4 100644 --- a/lib/lexer.js +++ b/lib/lexer.js @@ -163,17 +163,16 @@ return true; }; Lexer.prototype.commentToken = function() { - var comment, match; + var match; if (!(match = this.chunk.match(COMMENT))) { return false; } this.line += count(match[1], "\n"); this.i += match[1].length; if (match[2]) { - comment = this.sanitizeHeredoc(match[2], { + this.token('HERECOMMENT', this.sanitizeHeredoc(match[2], { herecomment: true - }); - this.token('HERECOMMENT', comment.split(MULTILINER)); + })); this.token('TERMINATOR', '\n'); } return true; @@ -604,7 +603,7 @@ HEREDOC = /^("{6}|'{6}|"{3}\n?([\s\S]*?)\n?([ \t]*)"{3}|'{3}\n?([\s\S]*?)\n?([ \t]*)'{3})/; OPERATOR = /^(-[\-=>]?|\+[+=]?|[*&|\/%=<>^:!?]+)([ \t]*)/; WHITESPACE = /^([ \t]+)/; - COMMENT = /^(\s*\#{3}(?!#)[ \t]*\n+([\s\S]*?)[ \t]*\n+[ \t]*\#{3}|(\s*#(?!##[^#])[^\n]*)+)/; + COMMENT = /^(\s*\#{3}(?!#)([\s\S]*?)\#{3}[ \t]*\n|(\s*#(?!##[^#])[^\n]*)+)/; CODE = /^((-|=)>)/; MULTI_DENT = /^((\n([ \t]*))+)(\.)?/; LAST_DENTS = /\n([ \t]*)/g; diff --git a/lib/nodes.js b/lib/nodes.js index 793118b5..1c626437 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -425,7 +425,7 @@ })(); exports.CommentNode = (function() { CommentNode = function(_b) { - this.lines = _b; + this.comment = _b; CommentNode.__superClass__.constructor.call(this); return this; }; @@ -438,9 +438,7 @@ return this; }; CommentNode.prototype.compileNode = function(o) { - var sep; - sep = this.tab + '// '; - return sep + this.lines.join('\n' + sep); + return this.tab + '/*' + this.comment.replace(/\r?\n/g, '\n' + this.tab) + '*/'; }; return CommentNode; })(); diff --git a/src/lexer.coffee b/src/lexer.coffee index 7f77b6e7..eb01f23a 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -145,8 +145,7 @@ exports.Lexer = class Lexer @line += count match[1], "\n" @i += match[1].length if match[2] - comment = @sanitizeHeredoc match[2], herecomment: true - @token 'HERECOMMENT', comment.split MULTILINER + @token 'HERECOMMENT', @sanitizeHeredoc match[2], herecomment: true @token 'TERMINATOR', '\n' true @@ -521,7 +520,7 @@ NUMBER = /^(((\b0(x|X)[0-9a-fA-F]+)|((\b[0-9]+(\.[0-9]+)?|\.[0-9]+)(e[+\- HEREDOC = /^("{6}|'{6}|"{3}\n?([\s\S]*?)\n?([ \t]*)"{3}|'{3}\n?([\s\S]*?)\n?([ \t]*)'{3})/ OPERATOR = /^(-[\-=>]?|\+[+=]?|[*&|\/%=<>^:!?]+)([ \t]*)/ WHITESPACE = /^([ \t]+)/ -COMMENT = /^(\s*\#{3}(?!#)[ \t]*\n+([\s\S]*?)[ \t]*\n+[ \t]*\#{3}|(\s*#(?!##[^#])[^\n]*)+)/ +COMMENT = /^(\s*\#{3}(?!#)([\s\S]*?)\#{3}[ \t]*\n|(\s*#(?!##[^#])[^\n]*)+)/ CODE = /^((-|=)>)/ MULTI_DENT = /^((\n([ \t]*))+)(\.)?/ LAST_DENTS = /\n([ \t]*)/g diff --git a/src/nodes.coffee b/src/nodes.coffee index 00f3fb70..fa789d5e 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -392,15 +392,14 @@ exports.CommentNode = class CommentNode extends BaseNode class: 'CommentNode' isStatement: -> yes - constructor: (@lines) -> + constructor: (@comment) -> super() makeReturn: -> this compileNode: (o) -> - sep = @tab + '// ' - sep + @lines.join '\n' + sep + @tab + '/*' + @comment.replace(/\r?\n/g, '\n' + @tab) + '*/' #### CallNode