Skip to content

Commit a39b2c0

Browse files
committed
Add a msg argument to parseerror(), fill in messages for all the calls.
1 parent 84708b4 commit a39b2c0

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

parser.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ function parse(tokens) {
5151
decl = undefined;
5252
return true;
5353
}
54-
var parseerror = function() {
55-
console.log("Parse error at token " + i + ": " + token);
54+
var parseerror = function(msg) {
55+
console.log("Parse error at token " + i + ": " + token + ".\n" + msg);
5656
return true;
5757
}
5858
var pop = function() {
@@ -82,7 +82,7 @@ function parse(tokens) {
8282
case "CDC":
8383
case "WHITESPACE": break;
8484
case "AT-KEYWORD": push(new AtRule(token.value)) && switchto('at-rule'); break;
85-
case "{": parseerror() && consumeASimpleBlock(token); break;
85+
case "{": parseerror("Attempt to open a curly-block at top-level.") && consumeASimpleBlock(token); break;
8686
default: push(new SelectorRule) && switchto('selector') && reprocess();
8787
}
8888
break;
@@ -92,7 +92,7 @@ function parse(tokens) {
9292
case ";": pop() && switchto(); break;
9393
case "{":
9494
if(rule.fillType !== '') switchto(rule.fillType);
95-
else parseerror() && switchto('next-block') && reprocess();
95+
else parseerror("Attempt to open a curly-block in a statement-type at-rule.") && switchto('next-block') && reprocess();
9696
break;
9797
case "[":
9898
case "(": rule.appendPrelude(consumeASimpleBlock(token)); break;
@@ -105,7 +105,7 @@ function parse(tokens) {
105105
switch(token.tokenType) {
106106
case "WHITESPACE": break;
107107
case "BADSTRING":
108-
case "BADURL": parseerror() && switchto('next-block'); break;
108+
case "BADURL": parseerror("Use of BADSTRING or BADURL token in selector.") && switchto('next-block'); break;
109109
case "}": pop() && switchto(); break;
110110
case "AT-KEYWORD": push(new AtRule(token.value)) && switchto('at-rule'); break;
111111
default: push(new SelectorRule) && switchto('selector') && reprocess();
@@ -137,8 +137,8 @@ function parse(tokens) {
137137
switch(token.tokenType) {
138138
case "WHITESPACE": break;
139139
case ":": switchto('declaration-value'); break;
140-
case ";": parseerror() && discarddecl() && switchto(); break;
141-
default: parseerror() && discarddecl() && switchto('next-declaration');
140+
case ";": parseerror("Incomplete declaration - semicolon after property name.") && discarddecl() && switchto(); break;
141+
default: parseerror("Invalid declaration - additional token after property name") && discarddecl() && switchto('next-declaration');
142142
}
143143
break;
144144

@@ -168,7 +168,7 @@ function parse(tokens) {
168168
case "WHITESPACE": break;
169169
case ";": rule.append(decl) && discarddecl() && switchto(); break;
170170
case "}": rule.append(decl) && discarddecl() && pop() && switchto(); break;
171-
default: parseerror() && discarddecl() && switchto('next-declaration');
171+
default: parseerror("Invalid declaration - additional token after !important.") && discarddecl() && switchto('next-declaration');
172172
}
173173
break;
174174

0 commit comments

Comments
 (0)