mirror of
https://github.com/less/less.js.git
synced 2026-05-01 03:00:22 -04:00
remove the quoted regex, simplify the comment parsing
This commit is contained in:
@@ -76,6 +76,34 @@ module.exports = function() {
|
||||
return tok;
|
||||
};
|
||||
|
||||
parserInput.$quoted = function() {
|
||||
|
||||
var startChar = input.charAt(parserInput.i);
|
||||
if (startChar !== "'" && startChar !== '"') {
|
||||
return;
|
||||
}
|
||||
var length = input.length,
|
||||
currentPosition = parserInput.i;
|
||||
|
||||
for (var i = 1; i + currentPosition < length; i++) {
|
||||
var nextChar = input.charAt(i + currentPosition);
|
||||
switch(nextChar) {
|
||||
case "\\":
|
||||
i++;
|
||||
continue;
|
||||
case "\r":
|
||||
case "\n":
|
||||
break;
|
||||
case startChar:
|
||||
var str = input.substr(currentPosition, i + 1);
|
||||
skipWhitespace(i + 1);
|
||||
return str;
|
||||
default:
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
var CHARCODE_SPACE = 32,
|
||||
CHARCODE_TAB = 9,
|
||||
CHARCODE_LF = 10,
|
||||
@@ -104,7 +132,7 @@ module.exports = function() {
|
||||
nextChar = inp.charAt(parserInput.i + 1);
|
||||
if (nextChar === '/') {
|
||||
comment = {index: parserInput.i, isLineComment: true};
|
||||
var nextNewLine = inp.indexOf("\n", parserInput.i + 1);
|
||||
var nextNewLine = inp.indexOf("\n", parserInput.i + 2);
|
||||
if (nextNewLine < 0) {
|
||||
nextNewLine = endIndex;
|
||||
}
|
||||
@@ -113,12 +141,11 @@ module.exports = function() {
|
||||
parserInput.commentStore.push(comment);
|
||||
continue;
|
||||
} else if (nextChar === '*') {
|
||||
var haystack = inp.substr(parserInput.i);
|
||||
var comment_search_result = haystack.match(/^\/\*(?:[^*]|\*+[^\/*])*\*+\//);
|
||||
if (comment_search_result) {
|
||||
var nextStarSlash = inp.indexOf("*/", parserInput.i + 2);
|
||||
if (nextStarSlash >= 0) {
|
||||
comment = {
|
||||
index: parserInput.i,
|
||||
text: comment_search_result[0],
|
||||
text: inp.substr(parserInput.i, nextStarSlash + 2 - parserInput.i),
|
||||
isLineComment: false
|
||||
};
|
||||
parserInput.i += comment.text.length - 1;
|
||||
|
||||
@@ -294,12 +294,20 @@ var Parser = function Parser(context, imports, fileInfo) {
|
||||
// "milky way" 'he\'s the one!'
|
||||
//
|
||||
quoted: function () {
|
||||
var str, index = parserInput.i;
|
||||
var str, index = parserInput.i, isEscaped = false;
|
||||
|
||||
str = parserInput.$re(/^(~)?("((?:[^"\\\r\n]|\\.)*)"|'((?:[^'\\\r\n]|\\.)*)')/);
|
||||
if (str) {
|
||||
return new(tree.Quoted)(str[2], str[3] || str[4], Boolean(str[1]), index, fileInfo);
|
||||
parserInput.save();
|
||||
if (parserInput.$char("~")) {
|
||||
isEscaped = true;
|
||||
}
|
||||
str = parserInput.$quoted();
|
||||
if (!str) {
|
||||
parserInput.restore();
|
||||
return;
|
||||
}
|
||||
parserInput.forget();
|
||||
|
||||
return new(tree.Quoted)(str.charAt(0), str.substr(1, str.length - 2), isEscaped, index, fileInfo);
|
||||
},
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user