UNPKG

eggtended-js

Version:

A extended version of the Egg programming language from the Eloquent Javascript book.

1,607 lines (1,606 loc) 233 kB
{ "type": "File", "start": 0, "end": 1034, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 40, "column": 0 } }, "program": { "type": "Program", "start": 0, "end": 1034, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 40, "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": 405, "loc": { "start": { "line": 3, "column": 0 }, "end": { "line": 17, "column": 2 } }, "expression": { "type": "AssignmentExpression", "start": 52, "end": 404, "loc": { "start": { "line": 3, "column": 0 }, "end": { "line": 17, "column": 1 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 52, "end": 73, "loc": { "start": { "line": 3, "column": 0 }, "end": { "line": 3, "column": 21 } }, "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": 72, "loc": { "start": { "line": 3, "column": 13 }, "end": { "line": 3, "column": 20 } }, "extra": { "rawValue": "const", "raw": "\"const\"" }, "value": "const" }, "computed": true }, "right": { "type": "ArrowFunctionExpression", "start": 76, "end": 404, "loc": { "start": { "line": 3, "column": 24 }, "end": { "line": 17, "column": 1 } }, "id": null, "generator": false, "expression": false, "async": false, "params": [ { "type": "Identifier", "start": 77, "end": 81, "loc": { "start": { "line": 3, "column": 25 }, "end": { "line": 3, "column": 29 }, "identifierName": "args" }, "name": "args" }, { "type": "Identifier", "start": 83, "end": 86, "loc": { "start": { "line": 3, "column": 31 }, "end": { "line": 3, "column": 34 }, "identifierName": "env" }, "name": "env" } ], "body": { "type": "BlockStatement", "start": 91, "end": 404, "loc": { "start": { "line": 3, "column": 39 }, "end": { "line": 17, "column": 1 } }, "body": [ { "type": "IfStatement", "start": 95, "end": 183, "loc": { "start": { "line": 4, "column": 2 }, "end": { "line": 6, "column": 3 } }, "test": { "type": "BinaryExpression", "start": 99, "end": 122, "loc": { "start": { "line": 4, "column": 6 }, "end": { "line": 4, "column": 29 } }, "left": { "type": "MemberExpression", "start": 99, "end": 111, "loc": { "start": { "line": 4, "column": 6 }, "end": { "line": 4, "column": 18 } }, "object": { "type": "MemberExpression", "start": 99, "end": 106, "loc": { "start": { "line": 4, "column": 6 }, "end": { "line": 4, "column": 13 } }, "object": { "type": "Identifier", "start": 99, "end": 103, "loc": { "start": { "line": 4, "column": 6 }, "end": { "line": 4, "column": 10 }, "identifierName": "args" }, "name": "args" }, "property": { "type": "NumericLiteral", "start": 104, "end": 105, "loc": { "start": { "line": 4, "column": 11 }, "end": { "line": 4, "column": 12 } }, "extra": { "rawValue": 0, "raw": "0" }, "value": 0 }, "computed": true }, "property": { "type": "Identifier", "start": 107, "end": 111, "loc": { "start": { "line": 4, "column": 14 }, "end": { "line": 4, "column": 18 }, "identifierName": "type" }, "name": "type" }, "computed": false }, "operator": "!==", "right": { "type": "StringLiteral", "start": 116, "end": 122, "loc": { "start": { "line": 4, "column": 23 }, "end": { "line": 4, "column": 29 } }, "extra": { "rawValue": "word", "raw": "\"word\"" }, "value": "word" } }, "consequent": { "type": "BlockStatement", "start": 124, "end": 183, "loc": { "start": { "line": 4, "column": 31 }, "end": { "line": 6, "column": 3 } }, "body": [ { "type": "ThrowStatement", "start": 130, "end": 179, "loc": { "start": { "line": 5, "column": 4 }, "end": { "line": 5, "column": 53 } }, "argument": { "type": "NewExpression", "start": 136, "end": 178, "loc": { "start": { "line": 5, "column": 10 }, "end": { "line": 5, "column": 52 } }, "callee": { "type": "Identifier", "start": 140, "end": 151, "loc": { "start": { "line": 5, "column": 14 }, "end": { "line": 5, "column": 25 }, "identifierName": "SyntaxError" }, "name": "SyntaxError" }, "arguments": [ { "type": "StringLiteral", "start": 152, "end": 177, "loc": { "start": { "line": 5, "column": 26 }, "end": { "line": 5, "column": 51 } }, "extra": { "rawValue": "Bad number of arguments", "raw": "\"Bad number of arguments\"" }, "value": "Bad number of arguments" } ] } } ], "directives": [] }, "alternate": null }, { "type": "VariableDeclaration", "start": 187, "end": 235, "loc": { "start": { "line": 8, "column": 2 }, "end": { "line": 8, "column": 50 } }, "declarations": [ { "type": "VariableDeclarator", "start": 193, "end": 234, "loc": { "start": { "line": 8, "column": 8 }, "end": { "line": 8, "column": 49 } }, "id": { "type": "Identifier", "start": 193, "end": 198, "loc": { "start": { "line": 8, "column": 8 }, "end": { "line": 8, "column": 13 }, "identifierName": "value" }, "name": "value" }, "init": { "type": "CallExpression", "start": 201, "end": 234, "loc": { "start": { "line": 8, "column": 16 }, "end": { "line": 8, "column": 49 } }, "callee": { "type": "MemberExpression", "start": 201, "end": 223, "loc": { "start": { "line": 8, "column": 16 }, "end": { "line": 8, "column": 38 } }, "object": { "type": "Identifier", "start": 201, "end": 213, "loc": { "start": { "line": 8, "column": 16 }, "end": { "line": 8, "column": 28 }, "identifierName": "SpecialForms" }, "name": "SpecialForms" }, "property": { "type": "StringLiteral", "start": 214, "end": 222, "loc": { "start": { "line": 8, "column": 29 }, "end": { "line": 8, "column": 37 } }, "extra": { "rawValue": "define", "raw": "\"define\"" }, "value": "define" }, "computed": true }, "arguments": [ { "type": "Identifier", "start": 224, "end": 228, "loc": { "start": { "line": 8, "column": 39 }, "end": { "line": 8, "column": 43 }, "identifierName": "args" }, "name": "args" }, { "type": "Identifier", "start": 230, "end": 233, "loc": { "start": { "line": 8, "column": 45 }, "end": { "line": 8, "column": 48 }, "identifierName": "env" }, "name": "env" } ] } } ], "kind": "const", "trailingComments": [ { "type": "CommentLine", "value": " Variable name", "start": 239, "end": 255, "loc": { "start": { "line": 10, "column": 2 }, "end": { "line": 10, "column": 18 } } } ] }, { "type": "VariableDeclaration", "start": 258, "end": 284, "loc": { "start": { "line": 11, "column": 2 }, "end": { "line": 11, "column": 28 } }, "declarations": [ { "type": "VariableDeclarator", "start": 264, "end": 283, "loc": { "start": { "line": 11, "column": 8 }, "end": { "line": 11, "column": 27 } }, "id": { "type": "Identifier", "start": 264, "end": 268, "loc": { "start": { "line": 11, "column": 8 }, "end": { "line": 11, "column": 12 }, "identifierName": "name" }, "name": "name", "leadingComments": null }, "init": { "type": "MemberExpression", "start": 271, "end": 283, "loc": { "start": { "line": 11, "column": 15 }, "end": { "line": 11, "column": 27 } }, "object": { "type": "MemberExpression", "start": 271, "end": 278, "loc": { "start": { "line": 11, "column": 15 }, "end": { "line": 11, "column": 22 } }, "object": { "type": "Identifier", "start": 271, "end": 275, "loc": { "start": { "line": 11, "column": 15 }, "end": { "line": 11, "column": 19 }, "identifierName": "args" }, "name": "args" }, "property": { "type": "NumericLiteral", "start": 276, "end": 277, "loc": { "start": { "line": 11, "column": 20 }, "end": { "line": 11, "column": 21 } }, "extra": { "rawValue": 0, "raw": "0" }, "value": 0 }, "computed": true }, "property": { "type": "Identifier", "start": 279, "end": 283, "loc": { "start": { "line": 11, "column": 23 }, "end": { "line": 11, "column": 27 }, "identifierName": "name" }, "name": "name" }, "computed": false }, "leadingComments": null } ], "kind": "const", "leadingComments": [ { "type": "CommentLine", "value": " Variable name", "start": 239, "end": 255, "loc": { "start": { "line": 10, "column": 2 }, "end": { "line": 10, "column": 18 } } } ], "trailingComments": [ { "type": "CommentLine", "value": " Add const attribute to the symbol table", "start": 288, "end": 330, "loc": { "start": { "line": 13, "column": 2 }, "end": { "line": 13, "column": 44 } } } ] }, { "type": "ExpressionStatement", "start": 333, "end": 385, "loc": { "start": { "line": 14, "column": 2 }, "end": { "line": 14, "column": 54 } }, "expression": { "type": "CallExpression", "start": 333, "end": 384, "loc": { "start": { "line": 14, "column": 2 }, "end": { "line": 14, "column": 53 } }, "callee": { "type": "MemberExpression", "start": 333, "end": 363, "loc": { "start": { "line": 14, "column": 2 }, "end": { "line": 14, "column": 32 } }, "object": { "type": "MemberExpression", "start": 333, "end": 350, "loc": { "start": { "line": 14, "column": 2 }, "end": { "line": 14, "column": 19 } }, "object": { "type": "Identifier", "start": 333, "end": 336, "loc": { "start": { "line": 14, "column": 2 }, "end": { "line": 14, "column": 5 }, "identifierName": "env" }, "name": "env", "leadingComments": null }, "property": { "type": "StringLiteral", "start": 337, "end": 349, "loc": { "start": { "line": 14, "column": 6 }, "end": { "line": 14, "column": 18 } }, "extra": { "rawValue": "__symbol__", "raw": "\"__symbol__\"" }, "value": "__symbol__" }, "computed": true, "leadingComments": null }, "property": { "type": "Identifier", "start": 351, "end": 363, "loc": { "start": { "line": 14, "column": 20 }, "end": { "line": 14, "column": 32 }, "identifierName": "addAttribute" }, "name": "addAttribute" }, "computed": false, "leadingComments": null }, "arguments": [ { "type": "StringLiteral", "start": 364, "end": 371, "loc": { "start": { "line": 14, "column": 33 }, "end": { "line": 14, "column": 40 } }, "extra": { "rawValue": "const", "raw": "\"const\"" }, "value": "const" }, { "type": "BooleanLiteral", "start": 373, "end": 377, "loc": { "start": { "line": 14, "column": 42 }, "end": { "line": 14, "column": 46 } }, "value": true }, { "type": "Identifier", "start": 379, "end": 383, "loc": { "start": { "line": 14, "column": 48 }, "end": { "line": 14, "column": 52 }, "identifierName": "name" }, "name": "name" } ], "leadingComments": null }, "leadingComments": [ { "type": "CommentLine", "value": " Add const attribute to the symbol table", "start": 288, "end": 330, "loc": { "start": { "line": 13, "column": 2 }, "end": { "line": 13, "column": 44 } } } ] }, { "type": "ReturnStatement", "start": 389, "end": 402, "loc": { "start": { "line": 16, "column": 2 }, "end": { "line": 16, "column": 15 } }, "argument": { "type": "Identifier", "start": 396, "end": 401, "loc": { "start": { "line": 16, "column": 9 }, "end": { "line": 16, "column": 14 }, "identifierName": "value" }, "name": "value" } } ], "directives": [] } } } }, { "type": "ExpressionStatement", "start": 407, "end": 463, "loc": { "start": { "line": 19, "column": 0 }, "end": { "line": 19, "column": 56 } }, "expression": { "type": "AssignmentExpression", "start": 407, "end": 462, "loc": { "start": { "line": 19, "column": 0 }, "end": { "line": 19, "column": 55 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 407, "end": 437, "loc": { "start": { "line": 19, "column": 0 }, "end": { "line": 19, "column": 30 } }, "object": { "type": "Identifier", "start": 407, "end": 419, "loc": { "start": { "line": 19, "column": 0 }, "end": { "line": 19, "column": 12 }, "identifierName": "SpecialForms" }, "name": "SpecialForms" }, "property": { "type": "StringLiteral", "start": 420, "end": 436, "loc": { "start": { "line": 19, "column": 13 }, "end": { "line": 19, "column": 29 } }, "extra": { "rawValue": "define_wrapped", "raw": "\"define_wrapped\"" }, "value": "define_wrapped" }, "computed": true }, "right": { "type": "MemberExpression", "start": 440, "end": 462, "loc": { "start": { "line": 19, "column": 33 }, "end": { "line": 19, "column": 55 } }, "object": { "type": "Identifier", "start": 440, "end": 452, "loc": { "start": { "line": 19, "column": 33 }, "end": { "line": 19, "column": 45 }, "identifierName": "SpecialForms" }, "name": "SpecialForms" }, "property": { "type": "StringLiteral", "start": 453, "end": 461, "loc": { "start": { "line": 19, "column": 46 }, "end": { "line": 19, "column": 54 } }, "extra": { "rawValue": "define", "raw": "\"define\"" }, "value": "define" }, "computed": true } } }, { "type": "ExpressionStatement", "start": 464, "end": 908, "loc": { "start": { "line": 20, "column": 0 }, "end": { "line": 33, "column": 2 } }, "expression": { "type": "AssignmentExpression", "start": 464, "end": 907, "loc": { "start": { "line": 20, "column": 0 }, "end": { "line": 33, "column": 1 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 464, "end": 483, "loc": { "start": { "line": 20, "column": 0 }, "end": { "line": 20, "column": 19 } }, "object": { "type": "Identifier", "start": 464, "end": 476, "loc": { "start": { "line": 20, "column": 0 }, "end": { "line": 20, "column": 12 }, "identifierName": "SpecialForms" }, "name": "SpecialForms" }, "property": { "type": "StringLiteral", "start": 477, "end": 482, "loc": { "start": { "line": 20, "column": 13 }, "end": { "line": 20, "column": 18 } }, "extra": { "rawValue": "def", "raw": "\"def\"" }, "value": "def" }, "computed": true }, "right": { "type": "AssignmentExpression", "start": 486, "end": 907, "loc": { "start": { "line": 20, "column": 22 }, "end": { "line": 33, "column": 1 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 486, "end": 508, "loc": { "start": { "line": 20, "column": 22 }, "end": { "line": 20, "column": 44 } }, "object": { "type": "Identifier", "start": 486, "end": 498, "loc": { "start": { "line": 20, "column": 22 }, "end": { "line": 20, "column": 34 }, "identifierName": "SpecialForms" }, "name": "SpecialForms" }, "property": { "type": "StringLiteral", "start": 499, "end": 507, "loc": { "start": { "line": 20, "column": 35 }, "end": { "line": 20, "column": 43 } }, "extra": { "rawValue": "define", "raw": "\"define\"" }, "value": "define" }, "computed": true }, "right": { "type": "AssignmentExpression", "start": 511, "end": 907, "loc": { "start": { "line": 20, "column": 47 }, "end": { "line": 33, "column": 1 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 511, "end": 529, "loc": { "start": { "line": 20, "column": 47 }, "end": { "line": 20, "column": 65 } }, "object": { "type": "Identifier", "start": 511, "end": 523, "loc": { "start": { "line": 20, "column": 47 }, "end": { "line": 20, "column": 59 }, "identifierName": "SpecialForms" }, "name": "SpecialForms" }, "property": { "type": "StringLiteral", "start": 524, "end": 528, "loc": { "start": { "line": 20, "column": 60 }, "end": { "line": 20, "column": 64 } }, "extra": { "rawValue": ":=", "raw": "\":=\"" }, "value": ":=" }, "computed": true }, "right": { "type": "ArrowFunctionExpression", "start": 532, "end": 907, "loc": { "start": { "line": 20, "column": 68 }, "end": { "line": 33, "column": 1 } }, "id": null, "generator": false, "expression": false, "async": false, "params": [ { "type": "Identifier", "start": 533, "end": 537, "loc": { "start": { "line": 20, "column": 69 }, "end": { "line": 20, "column": 73 }, "identifierName": "args" }, "name": "args" }, { "type": "Identifier", "start": 539, "end": 542, "loc": { "start": { "line": 20, "column": 75 }, "end": { "line": 20, "column": 78 }, "identifierName": "env" }, "name": "env" } ], "body": { "type": "BlockStatement", "start": 547, "end": 907, "loc": { "start": { "line": 20, "column": 83 }, "end": { "line": 33, "column": 1 } }, "body": [ { "type": "IfStatement", "start": 551, "end": 654, "loc": { "start": { "line": 21, "column": 2 }, "end": { "line": 23, "column": 3 } }, "test": { "type": "LogicalExpression", "start": 555, "end": 599, "loc": { "start": { "line": 21, "column": 6 }, "end": { "line": 21, "column": 50 } }, "left": { "type": "BinaryExpression", "start": 555, "end": 572, "loc": { "start": { "line": 21, "column": 6 }, "end": { "line": 21, "column": 23 } }, "left": { "type": "MemberExpression", "start": 555, "end": 566, "loc": { "start": { "line": 21, "column": 6 }, "end": { "line": 21, "column": 17 } }, "object": { "type": "Identifier", "start": 555, "end": 559, "loc": { "start": { "line": 21, "column": 6