fixing up block comment indentation boondoggle.

This commit is contained in:
Jeremy Ashkenas 2010-09-21 22:59:28 -04:00
parent 269f4e8da8
commit 07d9e9b71e
3 changed files with 13 additions and 13 deletions

View File

@ -162,10 +162,10 @@
}
this.line += count(match[1], "\n");
this.i += match[1].length;
if (match[4]) {
this.token('HERECOMMENT', this.sanitizeHeredoc(match[4], {
if (match[2]) {
this.token('HERECOMMENT', this.sanitizeHeredoc(match[2], {
herecomment: true,
indent: match[3]
indent: new Array(this.indent + 1).join(' ')
}));
this.token('TERMINATOR', '\n');
}
@ -614,7 +614,7 @@
HEREDOC = /^("{6}|'{6}|"{3}([\s\S]*?)\n?([ \t]*)"{3}|'{3}([\s\S]*?)\n?([ \t]*)'{3})/;
OPERATOR = /^(-[\-=>]?|\+[+=]?|[*&|\/%=<>^:!?]+)([ \t]*)/;
WHITESPACE = /^([ \t]+)/;
COMMENT = /^(([ \t]*\n)*([ \t]*)###([^#][\s\S]*?)(###[ \t]*\n|(###)?$)|(\s*#(?!##[^#])[^\n]*)+)/;
COMMENT = /^(###([^#][\s\S]*?)(###[ \t]*\n|(###)?$)|(\s*#(?!##[^#])[^\n]*)+)/;
CODE = /^((-|=)>)/;
MULTI_DENT = /^((\n([ \t]*))+)(\.)?/;
LAST_DENTS = /\n([ \t]*)/g;

View File

@ -138,8 +138,9 @@ exports.Lexer = class Lexer
return false unless match = @chunk.match(COMMENT)
@line += count match[1], "\n"
@i += match[1].length
if match[4]
@token 'HERECOMMENT', @sanitizeHeredoc match[4], herecomment: true, indent: match[3]
if match[2]
@token 'HERECOMMENT', @sanitizeHeredoc match[2],
herecomment: true, indent: new Array(@indent + 1).join(' ')
@token 'TERMINATOR', '\n'
true
@ -523,7 +524,7 @@ NUMBER = /^(((\b0(x|X)[0-9a-fA-F]+)|((\b[0-9]+(\.[0-9]+)?|\.[0-9]+)(e[+\-
HEREDOC = /^("{6}|'{6}|"{3}([\s\S]*?)\n?([ \t]*)"{3}|'{3}([\s\S]*?)\n?([ \t]*)'{3})/
OPERATOR = /^(-[\-=>]?|\+[+=]?|[*&|\/%=<>^:!?]+)([ \t]*)/
WHITESPACE = /^([ \t]+)/
COMMENT = /^(([ \t]*\n)*([ \t]*)###([^#][\s\S]*?)(###[ \t]*\n|(###)?$)|(\s*#(?!##[^#])[^\n]*)+)/
COMMENT = /^(###([^#][\s\S]*?)(###[ \t]*\n|(###)?$)|(\s*#(?!##[^#])[^\n]*)+)/
CODE = /^((-|=)>)/
MULTI_DENT = /^((\n([ \t]*))+)(\.)?/
LAST_DENTS = /\n([ \t]*)/g

View File

@ -67,12 +67,11 @@ ok test is 'test test test'
Kind of like a heredoc.
###
# FIXME:
# func = ->
# ###
# Another block comment.
# ###
# code
func = ->
###
Another block comment.
###
code
func = ->
one = ->