Slightly better error messages (#150)

* Slightly better errors

Instead of "Unexpected token" we now print
"Unexpected token, expected <type.label>"
This commit is contained in:
Daniel Tschinder 2016-10-12 16:38:26 +02:00 committed by Henry Zhu
parent 4fc0a3839e
commit d4d6d05d25
71 changed files with 127 additions and 469 deletions

View File

@ -74,7 +74,7 @@ pp.semicolon = function () {
// raise an unexpected token error at given pos.
pp.expect = function (type, pos) {
return this.eat(type) || this.unexpected(pos);
return this.eat(type) || this.unexpected(pos, `Unexpected token, expected ${type.label}`);
};
// Raise an unexpected token error.

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:9)"
"throws": "Unexpected token, expected , (1:9)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:12)"
}
"throws": "Unexpected token, expected , (1:12)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:16)"
}
"throws": "Unexpected token, expected , (1:16)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:13)"
}
"throws": "Unexpected token, expected , (1:13)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:18)"
}
"throws": "Unexpected token, expected ) (1:18)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:2)"
}
"throws": "Unexpected token, expected ( (1:2)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:15)"
}
"throws": "Unexpected token, expected ; (1:15)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:14)"
}
"throws": "Unexpected token, expected ; (1:14)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:9)"
}
"throws": "Unexpected token, expected while (1:9)"
}

View File

@ -1,196 +0,0 @@
{
"type": "File",
"start": 0,
"end": 36,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 36
}
},
"program": {
"type": "Program",
"start": 0,
"end": 36,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 36
}
},
"sourceType": "script",
"body": [
{
"type": "ForOfStatement",
"start": 0,
"end": 36,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 36
}
},
"left": {
"type": "VariableDeclaration",
"start": 5,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 15
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 9,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 15
}
},
"id": {
"type": "Identifier",
"start": 9,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
}
},
"name": "x"
},
"init": {
"type": "Literal",
"start": 13,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 15
}
},
"value": 42,
"rawValue": 42,
"raw": "42"
}
}
],
"kind": "var"
},
"right": {
"type": "Identifier",
"start": 19,
"end": 23,
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 1,
"column": 23
}
},
"name": "list"
},
"body": {
"type": "ExpressionStatement",
"start": 25,
"end": 36,
"loc": {
"start": {
"line": 1,
"column": 25
},
"end": {
"line": 1,
"column": 36
}
},
"expression": {
"type": "CallExpression",
"start": 25,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 25
},
"end": {
"line": 1,
"column": 35
}
},
"callee": {
"type": "Identifier",
"start": 25,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 25
},
"end": {
"line": 1,
"column": 32
}
},
"name": "process"
},
"arguments": [
{
"type": "Identifier",
"start": 33,
"end": 34,
"loc": {
"start": {
"line": 1,
"column": 33
},
"end": {
"line": 1,
"column": 34
}
},
"name": "x"
}
]
}
}
}
]
},
"comments": []
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:16)"
"throws": "Unexpected token, expected ; (1:16)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:16)"
}
"throws": "Unexpected token, expected ; (1:16)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:16)"
}
"throws": "Unexpected token, expected ; (1:16)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:9)"
}
"throws": "Unexpected token, expected ] (1:9)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:17)"
}
"throws": "Unexpected token, expected ( (1:17)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:22)"
}
"throws": "Unexpected token, expected { (1:22)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:7)"
}
"throws": "Unexpected token, expected ( (1:7)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:18)"
}
"throws": "Unexpected token, expected } (1:18)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:11)"
}
"throws": "Unexpected token, expected } (1:11)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:13)"
}
"throws": "Unexpected token, expected { (1:13)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:18)"
}
"throws": "Unexpected token, expected ) (1:18)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:19)"
}
"throws": "Unexpected token, expected ) (1:19)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:5)"
}
"throws": "Unexpected token, expected ) (1:5)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:15)"
}
"throws": "Unexpected token, expected { (1:15)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:19)"
}
"throws": "Unexpected token, expected { (1:19)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:22)"
}
"throws": "Unexpected token, expected { (1:22)"
}

View File

@ -1,4 +1,4 @@
{
"sourceType": "module",
"throws": "Unexpected token (1:7)"
}
"throws": "Unexpected token, expected { (1:7)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:11)"
"throws": "Unexpected token, expected ( (1:11)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:10)"
"throws": "Unexpected token, expected ( (1:10)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:19)"
}
"throws": "Unexpected token, expected ) (1:19)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:3)"
}
"throws": "Unexpected token, expected , (1:3)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:5)"
}
"throws": "Unexpected token, expected ) (1:5)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:17)"
}
"throws": "Unexpected token, expected ; (1:17)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:15)"
}
"throws": "Unexpected token, expected ; (1:15)"
}

View File

@ -1,146 +0,0 @@
{
"type": "File",
"start": 0,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 21
}
},
"program": {
"type": "Program",
"start": 0,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 21
}
},
"sourceType": "script",
"body": [
{
"type": "ForOfStatement",
"start": 0,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 21
}
},
"left": {
"type": "VariableDeclaration",
"start": 5,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 14
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 9,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 14
}
},
"id": {
"type": "Identifier",
"start": 9,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 10
}
},
"name": "x"
},
"init": {
"type": "Literal",
"start": 13,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 14
}
},
"value": 1,
"rawValue": 1,
"raw": "1"
}
}
],
"kind": "var"
},
"right": {
"type": "Identifier",
"start": 18,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 18
},
"end": {
"line": 1,
"column": 19
}
},
"name": "y"
},
"body": {
"type": "EmptyStatement",
"start": 20,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 20
},
"end": {
"line": 1,
"column": 21
}
}
}
}
]
}
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:15)"
"throws": "Unexpected token, expected ; (1:15)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:11)"
}
"throws": "Unexpected token, expected ] (1:11)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:7)"
}
"throws": "Unexpected token, expected { (1:7)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:12)"
}
"throws": "Unexpected token, expected { (1:12)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:17)"
}
"throws": "Unexpected token, expected ; (1:17)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:15)"
}
"throws": "Unexpected token, expected ; (1:15)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:7)"
}
"throws": "Unexpected token, expected ( (1:7)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:11)"
}
"throws": "Unexpected token, expected } (1:11)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:18)"
}
"throws": "Unexpected token, expected } (1:18)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:18)"
}
"throws": "Unexpected token, expected , (1:18)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:9)"
}
"throws": "Unexpected token, expected , (1:9)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:12)"
}
"throws": "Unexpected token, expected , (1:12)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:16)"
}
"throws": "Unexpected token, expected , (1:16)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:13)"
}
"throws": "Unexpected token, expected , (1:13)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:4)"
}
"throws": "Unexpected token, expected ] (1:4)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:7)"
}
"throws": "Unexpected token, expected ] (1:7)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:7)"
}
"throws": "Unexpected token, expected , (1:7)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:2)"
}
"throws": "Unexpected token, expected ( (1:2)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:15)"
}
"throws": "Unexpected token, expected ; (1:15)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:14)"
}
"throws": "Unexpected token, expected ; (1:14)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:20)"
}
"throws": "Unexpected token, expected ) (1:20)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:9)"
}
"throws": "Unexpected token, expected while (1:9)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:18)"
}
"throws": "Unexpected token, expected ) (1:18)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:16)"
}
"throws": "Unexpected token, expected ) (1:16)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:18)"
}
"throws": "Unexpected token, expected { (1:18)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:7)"
}
"throws": "Unexpected token, expected { (1:7)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:7)"
}
"throws": "Unexpected token, expected { (1:7)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:10)"
}
"throws": "Unexpected token, expected ( (1:10)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:11)"
}
"throws": "Unexpected token, expected ( (1:11)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:23)"
}
"throws": "Unexpected token, expected ( (1:23)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (2:6)"
"throws": "Unexpected token, expected ( (2:6)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (2:8)"
"throws": "Unexpected token, expected ( (2:8)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (2:7)"
"throws": "Unexpected token, expected ( (2:7)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (2:17)"
"throws": "Unexpected token, expected ( (2:17)"
}

View File

@ -1,3 +1,3 @@
{
"throws": "Unexpected token (1:65)"
"throws": "Unexpected token, expected , (1:65)"
}