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,6 +16,9 @@ fs.stat(input, function (e, stats) {
fs.open(input, process.O_RDONLY, stats.mode, function (e, fd) { fs.open(input, process.O_RDONLY, stats.mode, function (e, fd) {
fs.read(fd, stats.size, 0, "utf8", function (e, data) { fs.read(fd, stats.size, 0, "utf8", function (e, data) {
tree = less.parser.parse(data); tree = less.parser.parse(data);
if (less.parser.error) {
process.stdio.writeError(less.parser.error.message);
} else {
css = tree.toCSS([], {frames: []}); css = tree.toCSS([], {frames: []});
if (output) { if (output) {
fd = fs.openSync(output, "w"); fd = fs.openSync(output, "w");
@ -23,6 +26,7 @@ fs.stat(input, function (e, stats) {
} else { } else {
sys.print(css); sys.print(css);
} }
}
}); });
}); });
}); });

View File

@ -169,9 +169,9 @@ less.parser = {
line = (input.slice(0, i).match(/\n/g) || "").length + 1; line = (input.slice(0, i).match(/\n/g) || "").length + 1;
end = input.slice(i).indexOf('\n') + i; end = input.slice(i).indexOf('\n') + i;
zone = stylize(input.slice(start, i), 'green') + 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; 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) { read(path.join('test/css', path.basename(file, '.less')) + '.css', function (e, css) {
sys.print("- " + file + ": ") sys.print("- " + file + ": ")
if (less === css) { sys.print('OK') } if (less === css) { sys.print('OK') }
else if (err && err.name == 'ParseError') { else if (err) {
sys.print("!\n " + err.message); sys.print("!\n " + (err && err.message));
} else { } else {
sys.print("=/="); sys.print("=/=");
} }
@ -24,12 +24,16 @@ fs.readdirSync('test/less').forEach(function (file) {
}); });
function toCSS(path, callback) { function toCSS(path, callback) {
var tree;
read(path, function (e, str) { read(path, function (e, str) {
if (e) { return callback(e) } if (e) { return callback(e) }
try {
callback(null, less.parser.parse(str).toCSS([], {frames: []})); tree = less.parser.parse(str);
} catch (e) {
callback(e); if (less.parser.error) {
callback(less.parser.error);
} else {
callback(null, tree.toCSS([], {frames: []}));
} }
}); });
} }