From d54b36729bab93944da7216b16172d6f601966f1 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Mon, 24 Jan 2011 18:32:18 -0500 Subject: [PATCH] Catch syntax errors. Also, don't let comment regex make weird behavior. Also, only let error() record, never let it throw. --- files/demo.mss | 21 ++++++--------------- lib/mess/parser.js | 10 ++++++++-- lib/mess/tree/definition.js | 11 ----------- lib/mess/tree/invalid.js | 10 +--------- lib/mess/tree/ruleset.js | 2 ++ 5 files changed, 17 insertions(+), 37 deletions(-) diff --git a/files/demo.mss b/files/demo.mss index 96680ed..8ca6794 100644 --- a/files/demo.mss +++ b/files/demo.mss @@ -1,19 +1,10 @@ +@red: #fff; + #world { - polygon-fill:#CCC; + polygon-fill: @red; + text-face-name: 'Arial', 'Verdana'; } -#world[NAME='United States'] { - polygon-fill:#F00; +#countries { + text-face-name: 'Arial', 'Verdana', 'Helvetica'; } - -#countries .countries .two { - polygon-fill:#0FF; -} - -#countries, #world { - polygon-fill:#F0F; - polygon-opacity: 0.5; -} - - -#countries, #countries.foo.bar.baz {} diff --git a/lib/mess/parser.js b/lib/mess/parser.js index c205130..788e562 100644 --- a/lib/mess/parser.js +++ b/lib/mess/parser.js @@ -220,7 +220,8 @@ mess.Parser = function Parser(env) { chunks = (function(chunks) { var j = 0, skip = /[^"'`\{\}\/]+/g, - comment = /\/\*(?:[^*]|\*+[^\/*])*(?:\*+\/\n?|\**$)|\/\/.*/g, + // comment = /\/\*(?:[^*]|\*+[^\/*])*(?:\*+\/\n?|\**$)|\/\/.*/g, + comment = /\/\*(?:[^*]|\*+[^\/*])*\*+\/|\/\/.*/g, level = 0, match, chunk = chunks[0], @@ -293,6 +294,10 @@ mess.Parser = function Parser(env) { // return function(options, variables) { return function(env) { + env.error = function(e) { + if (!env.errors) env.errors = []; + env.errors.push(e); + }; env.errors = []; env.frames = env.frames || []; @@ -446,7 +451,8 @@ mess.Parser = function Parser(env) { if (input.charAt(i + 1) === '/') { return new tree.Comment($(/^\/\/.*/), true); - } else if (comment = $(/^\/\*(?:[^*]|\*+[^\/*])*(?:\*+\/\n?|\**$)/)) { + } else if (comment = $(/^\/\*(?:[^*]|\*+[^\/*])*\*+\/\n?/)) { + // } else if (comment = $(/^\/\*(?:[^*]|\*+[^\/*])*(?:\*+\/\n?|\**$)/)) { return new tree.Comment(comment); } }, diff --git a/lib/mess/tree/definition.js b/lib/mess/tree/definition.js index 91161f9..2a3d418 100644 --- a/lib/mess/tree/definition.js +++ b/lib/mess/tree/definition.js @@ -78,17 +78,6 @@ tree.Definition.prototype.toXML = function(env) { sym = sym[0]; } - if (env.returnErrors) { - env.error = function(e) { - if (env.errors) { - env.errors.push(e); - } - else { - throw e; - } - }; - } - var symname = sym.charAt(0).toUpperCase() + sym.slice(1).replace(/\-./, function(str) { return str[1].toUpperCase(); diff --git a/lib/mess/tree/invalid.js b/lib/mess/tree/invalid.js index f4c6e24..5ec581d 100644 --- a/lib/mess/tree/invalid.js +++ b/lib/mess/tree/invalid.js @@ -5,14 +5,6 @@ var sys = require('sys'); tree.Invalid = function (chunk, index) { this.chunk = chunk; this.index = index; + this.message = "Invalid code: " + this.chunk; }; -tree.Invalid.prototype = { - toCSS: function (env) { - return env.error({ - message: "Invalid code: " + sys.inspect(this.chunk), - index: this.index - }); - } -}; - })(require('mess/tree')); diff --git a/lib/mess/tree/ruleset.js b/lib/mess/tree/ruleset.js index ff04ef9..1e1aa5d 100644 --- a/lib/mess/tree/ruleset.js +++ b/lib/mess/tree/ruleset.js @@ -147,6 +147,8 @@ tree.Ruleset.prototype = { rule.flatten(result, selectors, env); } else if (rule instanceof tree.Rule) { rules.push(rule); + } else if (rule instanceof tree.Invalid) { + env.errors.push(rule); } }