more tweaks and futzes to block comments.
This commit is contained in:
parent
b4de17d504
commit
1b88d18d61
15
lib/lexer.js
15
lib/lexer.js
|
@ -169,9 +169,10 @@
|
|||
}
|
||||
this.line += count(match[1], "\n");
|
||||
this.i += match[1].length;
|
||||
if (match[2]) {
|
||||
this.token('HERECOMMENT', this.sanitizeHeredoc(match[2], {
|
||||
herecomment: true
|
||||
if (match[4]) {
|
||||
this.token('HERECOMMENT', this.sanitizeHeredoc(match[4], {
|
||||
herecomment: true,
|
||||
indent: match[3]
|
||||
}));
|
||||
this.token('TERMINATOR', '\n');
|
||||
}
|
||||
|
@ -389,12 +390,18 @@
|
|||
};
|
||||
Lexer.prototype.sanitizeHeredoc = function(doc, options) {
|
||||
var _d, attempt, indent, match;
|
||||
indent = options.indent || '';
|
||||
if (options.herecomment && !include(doc, '\n')) {
|
||||
return doc;
|
||||
}
|
||||
if (!(options.herecomment)) {
|
||||
while (match = HEREDOC_INDENT.exec(doc)) {
|
||||
attempt = (typeof (_d = match[2]) !== "undefined" && _d !== null) ? match[2] : match[3];
|
||||
if (!indent || attempt.length < indent.length) {
|
||||
indent = attempt;
|
||||
}
|
||||
}
|
||||
}
|
||||
doc = doc.replace(new RegExp("^" + indent, 'gm'), '');
|
||||
if (options.herecomment) {
|
||||
return doc;
|
||||
|
@ -603,7 +610,7 @@
|
|||
HEREDOC = /^("{6}|'{6}|"{3}\n?([\s\S]*?)\n?([ \t]*)"{3}|'{3}\n?([\s\S]*?)\n?([ \t]*)'{3})/;
|
||||
OPERATOR = /^(-[\-=>]?|\+[+=]?|[*&|\/%=<>^:!?]+)([ \t]*)/;
|
||||
WHITESPACE = /^([ \t]+)/;
|
||||
COMMENT = /^(\s*###(?!#)([\s\S]*?)(###[ \t]*\n|(###)?$)|(\s*#(?!##[^#])[^\n]*)+)/;
|
||||
COMMENT = /^(([ \t]*\n)*([ \t]*)###([^#][\s\S]*?)(###[ \t]*\n|(###)?$)|(\s*#(?!##[^#])[^\n]*)+)/;
|
||||
CODE = /^((-|=)>)/;
|
||||
MULTI_DENT = /^((\n([ \t]*))+)(\.)?/;
|
||||
LAST_DENTS = /\n([ \t]*)/g;
|
||||
|
|
|
@ -144,8 +144,8 @@ exports.Lexer = class Lexer
|
|||
return false unless match = @chunk.match(COMMENT)
|
||||
@line += count match[1], "\n"
|
||||
@i += match[1].length
|
||||
if match[2]
|
||||
@token 'HERECOMMENT', @sanitizeHeredoc match[2], herecomment: true
|
||||
if match[4]
|
||||
@token 'HERECOMMENT', @sanitizeHeredoc match[4], herecomment: true, indent: match[3]
|
||||
@token 'TERMINATOR', '\n'
|
||||
true
|
||||
|
||||
|
@ -319,6 +319,9 @@ exports.Lexer = class Lexer
|
|||
# Sanitize a heredoc or herecomment by escaping internal double quotes and
|
||||
# erasing all external indentation on the left-hand side.
|
||||
sanitizeHeredoc: (doc, options) ->
|
||||
indent = options.indent or ''
|
||||
return doc if options.herecomment and not include doc, '\n'
|
||||
unless options.herecomment
|
||||
while match = HEREDOC_INDENT.exec(doc)
|
||||
attempt = if match[2]? then match[2] else match[3]
|
||||
indent = attempt if not indent or attempt.length < indent.length
|
||||
|
@ -520,7 +523,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*###(?!#)([\s\S]*?)(###[ \t]*\n|(###)?$)|(\s*#(?!##[^#])[^\n]*)+)/
|
||||
COMMENT = /^(([ \t]*\n)*([ \t]*)###([^#][\s\S]*?)(###[ \t]*\n|(###)?$)|(\s*#(?!##[^#])[^\n]*)+)/
|
||||
CODE = /^((-|=)>)/
|
||||
MULTI_DENT = /^((\n([ \t]*))+)(\.)?/
|
||||
LAST_DENTS = /\n([ \t]*)/g
|
||||
|
|
Loading…
Reference in New Issue