ParseErrors dont raise an exception anymore, we just set parser.error to the value of the error

This commit is contained in:
cloudhead 2010-02-27 14:14:52 -05:00
parent c804ed2ef1
commit 1e16d0233c
3 changed files with 21 additions and 13 deletions

View File

@ -16,12 +16,16 @@ fs.stat(input, function (e, stats) {
fs.open(input, process.O_RDONLY, stats.mode, function (e, fd) {
fs.read(fd, stats.size, 0, "utf8", function (e, data) {
tree = less.parser.parse(data);
css = tree.toCSS([], {frames: []});
if (output) {
fd = fs.openSync(output, "w");
fs.writeSync(fd, css, 0, "utf8");
if (less.parser.error) {
process.stdio.writeError(less.parser.error.message);
} else {
sys.print(css);
css = tree.toCSS([], {frames: []});
if (output) {
fd = fs.openSync(output, "w");
fs.writeSync(fd, css, 0, "utf8");
} else {
sys.print(css);
}
}
});
});

View File

@ -169,9 +169,9 @@ less.parser = {
line = (input.slice(0, i).match(/\n/g) || "").length + 1;
end = input.slice(i).indexOf('\n') + i;
zone = stylize(input.slice(start, i), 'green') +
stylize(input.slice(i, end), 'yellow');
stylize(input.slice(i, end), 'yellow') + '\033[0m\n';
throw { name: "ParseError", message: "Parse Error on line " + line + ":\n" + zone };
this.error = { name: "ParseError", message: "Parse Error on line " + line + ":\n" + zone };
}
return tree;
},

View File

@ -13,8 +13,8 @@ fs.readdirSync('test/less').forEach(function (file) {
read(path.join('test/css', path.basename(file, '.less')) + '.css', function (e, css) {
sys.print("- " + file + ": ")
if (less === css) { sys.print('OK') }
else if (err && err.name == 'ParseError') {
sys.print("!\n " + err.message);
else if (err) {
sys.print("!\n " + (err && err.message));
} else {
sys.print("=/=");
}
@ -24,12 +24,16 @@ fs.readdirSync('test/less').forEach(function (file) {
});
function toCSS(path, callback) {
var tree;
read(path, function (e, str) {
if (e) { return callback(e) }
try {
callback(null, less.parser.parse(str).toCSS([], {frames: []}));
} catch (e) {
callback(e);
tree = less.parser.parse(str);
if (less.parser.error) {
callback(less.parser.error);
} else {
callback(null, tree.toCSS([], {frames: []}));
}
});
}