eggtended-js
Version:
A extended version of the Egg programming language from the Eloquent Javascript book.
1,403 lines (1,402 loc) • 124 kB
JSON
{
"type": "File",
"start": 0,
"end": 529,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 30,
"column": 0
}
},
"program": {
"type": "Program",
"start": 0,
"end": 529,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 30,
"column": 0
}
},
"sourceType": "module",
"body": [
{
"type": "ImportDeclaration",
"start": 0,
"end": 50,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 50
}
},
"specifiers": [
{
"type": "ImportSpecifier",
"start": 9,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 21
}
},
"imported": {
"type": "Identifier",
"start": 9,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 21
},
"identifierName": "SpecialForms"
},
"name": "SpecialForms"
},
"local": {
"type": "Identifier",
"start": 9,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 21
},
"identifierName": "SpecialForms"
},
"name": "SpecialForms"
}
},
{
"type": "ImportSpecifier",
"start": 23,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 23
},
"end": {
"line": 1,
"column": 29
}
},
"imported": {
"type": "Identifier",
"start": 23,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 23
},
"end": {
"line": 1,
"column": 29
},
"identifierName": "TopEnv"
},
"name": "TopEnv"
},
"local": {
"type": "Identifier",
"start": 23,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 23
},
"end": {
"line": 1,
"column": 29
},
"identifierName": "TopEnv"
},
"name": "TopEnv"
}
}
],
"source": {
"type": "StringLiteral",
"start": 37,
"end": 49,
"loc": {
"start": {
"line": 1,
"column": 37
},
"end": {
"line": 1,
"column": 49
}
},
"extra": {
"rawValue": "./registry",
"raw": "\"./registry\""
},
"value": "./registry"
}
},
{
"type": "ExpressionStatement",
"start": 52,
"end": 484,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 25,
"column": 2
}
},
"expression": {
"type": "AssignmentExpression",
"start": 52,
"end": 483,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 25,
"column": 1
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 52,
"end": 71,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 19
}
},
"object": {
"type": "Identifier",
"start": 52,
"end": 64,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 12
},
"identifierName": "SpecialForms"
},
"name": "SpecialForms"
},
"property": {
"type": "StringLiteral",
"start": 65,
"end": 70,
"loc": {
"start": {
"line": 3,
"column": 13
},
"end": {
"line": 3,
"column": 18
}
},
"extra": {
"rawValue": "try",
"raw": "\"try\""
},
"value": "try"
},
"computed": true
},
"right": {
"type": "ArrowFunctionExpression",
"start": 74,
"end": 483,
"loc": {
"start": {
"line": 3,
"column": 22
},
"end": {
"line": 25,
"column": 1
}
},
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 75,
"end": 79,
"loc": {
"start": {
"line": 3,
"column": 23
},
"end": {
"line": 3,
"column": 27
},
"identifierName": "args"
},
"name": "args"
},
{
"type": "Identifier",
"start": 81,
"end": 84,
"loc": {
"start": {
"line": 3,
"column": 29
},
"end": {
"line": 3,
"column": 32
},
"identifierName": "env"
},
"name": "env"
}
],
"body": {
"type": "BlockStatement",
"start": 89,
"end": 483,
"loc": {
"start": {
"line": 3,
"column": 37
},
"end": {
"line": 25,
"column": 1
}
},
"body": [
{
"type": "IfStatement",
"start": 93,
"end": 176,
"loc": {
"start": {
"line": 4,
"column": 2
},
"end": {
"line": 6,
"column": 3
}
},
"test": {
"type": "BinaryExpression",
"start": 97,
"end": 112,
"loc": {
"start": {
"line": 4,
"column": 6
},
"end": {
"line": 4,
"column": 21
}
},
"left": {
"type": "MemberExpression",
"start": 97,
"end": 108,
"loc": {
"start": {
"line": 4,
"column": 6
},
"end": {
"line": 4,
"column": 17
}
},
"object": {
"type": "Identifier",
"start": 97,
"end": 101,
"loc": {
"start": {
"line": 4,
"column": 6
},
"end": {
"line": 4,
"column": 10
},
"identifierName": "args"
},
"name": "args"
},
"property": {
"type": "Identifier",
"start": 102,
"end": 108,
"loc": {
"start": {
"line": 4,
"column": 11
},
"end": {
"line": 4,
"column": 17
},
"identifierName": "length"
},
"name": "length"
},
"computed": false
},
"operator": "<",
"right": {
"type": "NumericLiteral",
"start": 111,
"end": 112,
"loc": {
"start": {
"line": 4,
"column": 20
},
"end": {
"line": 4,
"column": 21
}
},
"extra": {
"rawValue": 2,
"raw": "2"
},
"value": 2
}
},
"consequent": {
"type": "BlockStatement",
"start": 114,
"end": 176,
"loc": {
"start": {
"line": 4,
"column": 23
},
"end": {
"line": 6,
"column": 3
}
},
"body": [
{
"type": "ThrowStatement",
"start": 120,
"end": 172,
"loc": {
"start": {
"line": 5,
"column": 4
},
"end": {
"line": 5,
"column": 56
}
},
"argument": {
"type": "NewExpression",
"start": 126,
"end": 171,
"loc": {
"start": {
"line": 5,
"column": 10
},
"end": {
"line": 5,
"column": 55
}
},
"callee": {
"type": "Identifier",
"start": 130,
"end": 141,
"loc": {
"start": {
"line": 5,
"column": 14
},
"end": {
"line": 5,
"column": 25
},
"identifierName": "SyntaxError"
},
"name": "SyntaxError"
},
"arguments": [
{
"type": "StringLiteral",
"start": 142,
"end": 170,
"loc": {
"start": {
"line": 5,
"column": 26
},
"end": {
"line": 5,
"column": 54
}
},
"extra": {
"rawValue": "Bad use of try-catch block",
"raw": "\"Bad use of try-catch block\""
},
"value": "Bad use of try-catch block"
}
]
}
}
],
"directives": []
},
"alternate": null
},
{
"type": "VariableDeclaration",
"start": 180,
"end": 201,
"loc": {
"start": {
"line": 8,
"column": 2
},
"end": {
"line": 8,
"column": 23
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 186,
"end": 200,
"loc": {
"start": {
"line": 8,
"column": 8
},
"end": {
"line": 8,
"column": 22
}
},
"id": {
"type": "Identifier",
"start": 186,
"end": 190,
"loc": {
"start": {
"line": 8,
"column": 8
},
"end": {
"line": 8,
"column": 12
},
"identifierName": "body"
},
"name": "body"
},
"init": {
"type": "MemberExpression",
"start": 193,
"end": 200,
"loc": {
"start": {
"line": 8,
"column": 15
},
"end": {
"line": 8,
"column": 22
}
},
"object": {
"type": "Identifier",
"start": 193,
"end": 197,
"loc": {
"start": {
"line": 8,
"column": 15
},
"end": {
"line": 8,
"column": 19
},
"identifierName": "args"
},
"name": "args"
},
"property": {
"type": "NumericLiteral",
"start": 198,
"end": 199,
"loc": {
"start": {
"line": 8,
"column": 20
},
"end": {
"line": 8,
"column": 21
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
},
"computed": true
}
}
],
"kind": "const"
},
{
"type": "VariableDeclaration",
"start": 204,
"end": 231,
"loc": {
"start": {
"line": 9,
"column": 2
},
"end": {
"line": 9,
"column": 29
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 210,
"end": 230,
"loc": {
"start": {
"line": 9,
"column": 8
},
"end": {
"line": 9,
"column": 28
}
},
"id": {
"type": "Identifier",
"start": 210,
"end": 220,
"loc": {
"start": {
"line": 9,
"column": 8
},
"end": {
"line": 9,
"column": 18
},
"identifierName": "catch_body"
},
"name": "catch_body"
},
"init": {
"type": "MemberExpression",
"start": 223,
"end": 230,
"loc": {
"start": {
"line": 9,
"column": 21
},
"end": {
"line": 9,
"column": 28
}
},
"object": {
"type": "Identifier",
"start": 223,
"end": 227,
"loc": {
"start": {
"line": 9,
"column": 21
},
"end": {
"line": 9,
"column": 25
},
"identifierName": "args"
},
"name": "args"
},
"property": {
"type": "NumericLiteral",
"start": 228,
"end": 229,
"loc": {
"start": {
"line": 9,
"column": 26
},
"end": {
"line": 9,
"column": 27
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
},
"computed": true
}
}
],
"kind": "const"
},
{
"type": "TryStatement",
"start": 235,
"end": 464,
"loc": {
"start": {
"line": 11,
"column": 2
},
"end": {
"line": 22,
"column": 3
}
},
"block": {
"type": "BlockStatement",
"start": 239,
"end": 268,
"loc": {
"start": {
"line": 11,
"column": 6
},
"end": {
"line": 13,
"column": 3
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 245,
"end": 264,
"loc": {
"start": {
"line": 12,
"column": 4
},
"end": {
"line": 12,
"column": 23
}
},
"expression": {
"type": "CallExpression",
"start": 245,
"end": 263,
"loc": {
"start": {
"line": 12,
"column": 4
},
"end": {
"line": 12,
"column": 22
}
},
"callee": {
"type": "MemberExpression",
"start": 245,
"end": 258,
"loc": {
"start": {
"line": 12,
"column": 4
},
"end": {
"line": 12,
"column": 17
}
},
"object": {
"type": "Identifier",
"start": 245,
"end": 249,
"loc": {
"start": {
"line": 12,
"column": 4
},
"end": {
"line": 12,
"column": 8
},
"identifierName": "body"
},
"name": "body"
},
"property": {
"type": "Identifier",
"start": 250,
"end": 258,
"loc": {
"start": {
"line": 12,
"column": 9
},
"end": {
"line": 12,
"column": 17
},
"identifierName": "evaluate"
},
"name": "evaluate"
},
"computed": false
},
"arguments": [
{
"type": "Identifier",
"start": 259,
"end": 262,
"loc": {
"start": {
"line": 12,
"column": 18
},
"end": {
"line": 12,
"column": 21
},
"identifierName": "env"
},
"name": "env"
}
]
}
}
],
"directives": []
},
"handler": {
"type": "CatchClause",
"start": 269,
"end": 344,
"loc": {
"start": {
"line": 13,
"column": 4
},
"end": {
"line": 16,
"column": 3
}
},
"param": {
"type": "Identifier",
"start": 276,
"end": 279,
"loc": {
"start": {
"line": 13,
"column": 11
},
"end": {
"line": 13,
"column": 14
},
"identifierName": "err"
},
"name": "err"
},
"body": {
"type": "BlockStatement",
"start": 281,
"end": 344,
"loc": {
"start": {
"line": 13,
"column": 16
},
"end": {
"line": 16,
"column": 3
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 287,
"end": 310,
"loc": {
"start": {
"line": 14,
"column": 4
},
"end": {
"line": 14,
"column": 27
}
},
"expression": {
"type": "AssignmentExpression",
"start": 287,
"end": 309,
"loc": {
"start": {
"line": 14,
"column": 4
},
"end": {
"line": 14,
"column": 26
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 287,
"end": 303,
"loc": {
"start": {
"line": 14,
"column": 4
},
"end": {
"line": 14,
"column": 20
}
},
"object": {
"type": "Identifier",
"start": 287,
"end": 290,
"loc": {
"start": {
"line": 14,
"column": 4
},
"end": {
"line": 14,
"column": 7
},
"identifierName": "env"
},
"name": "env"
},
"property": {
"type": "StringLiteral",
"start": 291,
"end": 302,
"loc": {
"start": {
"line": 14,
"column": 8
},
"end": {
"line": 14,
"column": 19
}
},
"extra": {
"rawValue": "__error__",
"raw": "\"__error__\""
},
"value": "__error__"
},
"computed": true
},
"right": {
"type": "Identifier",
"start": 306,
"end": 309,
"loc": {
"start": {
"line": 14,
"column": 23
},
"end": {
"line": 14,
"column": 26
},
"identifierName": "err"
},
"name": "err"
}
}
},
{
"type": "ExpressionStatement",
"start": 315,
"end": 340,
"loc": {
"start": {
"line": 15,
"column": 4
},
"end": {
"line": 15,
"column": 29
}
},
"expression": {
"type": "CallExpression",
"start": 315,
"end": 339,
"loc": {
"start": {
"line": 15,
"column": 4
},
"end": {
"line": 15,
"column": 28
}
},
"callee": {
"type": "MemberExpression",
"start": 315,
"end": 334,
"loc": {
"start": {
"line": 15,
"column": 4
},
"end": {
"line": 15,
"column": 23
}
},
"object": {
"type": "Identifier",
"start": 315,
"end": 325,
"loc": {
"start": {
"line": 15,
"column": 4
},
"end": {
"line": 15,
"column": 14
},
"identifierName": "catch_body"
},
"name": "catch_body"
},
"property": {
"type": "Identifier",
"start": 326,
"end": 334,
"loc": {
"start": {
"line": 15,
"column": 15
},
"end": {
"line": 15,
"column": 23
},
"identifierName": "evaluate"
},
"name": "evaluate"
},
"computed": false
},
"arguments": [
{
"type": "Identifier",
"start": 335,
"end": 338,
"loc": {
"start": {
"line": 15,
"column": 24
},
"end": {
"line": 15,
"column": 27
},
"identifierName": "env"
},
"name": "env"
}
]
}
}
],
"directives": []
}
},
"guardedHandlers": [],
"finalizer": {
"type": "BlockStatement",
"start": 353,
"end": 464,
"loc": {
"start": {
"line": 16,
"column": 12
},
"end": {
"line": 22,
"column": 3
}
},
"body": [
{
"type": "IfStatement",
"start": 359,
"end": 460,
"loc": {
"start": {
"line": 17,
"column": 4
},
"end": {
"line": 21,
"column": 5
}
},
"test": {
"type": "BinaryExpression",
"start": 363,
"end": 380,
"loc": {
"start": {
"line": 17,
"column": 8
},
"end": {
"line": 17,
"column": 25
}
},
"left": {
"type": "MemberExpression",
"start": 363,
"end": 374,
"loc": {
"start": {
"line": 17,
"column": 8
},
"end": {
"line": 17,
"column": 19
}
},
"object": {
"type": "Identifier",
"start": 363,
"end": 367,
"loc": {
"start": {
"line": 17,
"column": 8
},
"end": {
"line": 17,
"column": 12
},
"identifierName": "args"
},
"name": "args"
},
"property": {
"type": "Identifier",
"start": 368,
"end": 374,
"loc": {
"start": {
"line": 17,
"column": 13
},
"end": {
"line": 17,
"column": 19
},
"identifierName": "length"
},
"name": "length"
},
"computed": false
},
"operator": "===",
"right": {
"type": "NumericLiteral",
"start": 379,
"end": 380,
"loc": {
"start": {
"line": 17,
"column": 24
},
"end": {
"line": 17,
"column": 25
}
},
"extra": {
"rawValue": 3,
"raw": "3"
},
"value": 3
}
},
"consequent": {
"type": "BlockStatement",
"start": 382,
"end": 460,
"loc": {
"start": {
"line": 17,
"column": 27
},
"end": {
"line": 21,
"column": 5
}
},
"body": [
{
"type": "VariableDeclaration",
"start": 390,
"end": 419,
"loc": {
"start": {
"line": 18,
"column": 6
},
"end": {
"line": 18,
"column": 35
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 396,
"end": 418,
"loc": {
"start": {
"line": 18,
"column": 12
},
"end": {
"line": 18,
"column": 34
}
},
"id": {
"type": "Identifier",
"start": 396,
"end": 408,
"loc": {
"start": {
"line": 18,
"column": 12
},
"end": {
"line": 18,
"column": 24
},
"identifierName": "finally_body"
},
"name": "finally_body"
},
"init": {
"type": "MemberExpression",
"start": 411,
"end": 418,
"loc": {
"start": {
"line": 18,
"column": 27
},
"end": {
"line": 18,
"column": 34
}
},
"object": {
"type": "Identifier",
"start": 411,
"end": 415,
"loc": {
"start": {
"line": 18,
"column": 27
},
"end": {
"line": 18,
"column": 31
},
"identifierName": "args"
},
"name": "args"
},
"property": {
"type": "NumericLiteral",
"start": 416,
"end": 417,
"loc": {
"start": {
"line": 18,
"column": 32
},
"end": {
"line": 18,
"column": 33
}
},
"extra": {
"rawValue": 2,
"raw": "2"
},
"value": 2
},
"computed": true
}
}
],
"kind": "const"
},
{
"type": "ExpressionStatement",
"start": 427,
"end": 454,
"loc": {
"start": {
"line": 20,
"column": 6
},
"end": {
"line": 20,
"column": 33
}
},
"expression": {
"type": "CallExpression",
"start": 427,
"end": 453,
"loc": {
"start": {
"line": 20,
"column": 6
},
"end": {
"line": 20,
"column": 32
}
},
"callee": {
"type": "MemberExpression",
"start": 427,
"end": 448,
"loc": {
"start": {
"line": 20,
"column": 6
},
"end": {
"line": 20,
"column": 27
}
},
"object": {
"type": "Identifier",
"start": 427,
"end": 439,
"loc": {
"start": {
"line": 20,
"column": 6
},
"end": {
"line": 20,
"column": 18
},
"identifierName": "finally_body"
},
"name": "finally_body"
},
"property": {
"type": "Identifier",
"start": 440,
"end": 448,
"loc": {
"start": {
"line": 20,
"column": 19
},
"end": {
"line": 20,
"column": 27
},
"identifierName": "evaluate"
},
"name": "evaluate"
},