UNPKG

eggtended-js

Version:

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

1,651 lines (1,650 loc) 842 kB
{ "type": "File", "start": 0, "end": 3089, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 136, "column": 0 } }, "program": { "type": "Program", "start": 0, "end": 3089, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 136, "column": 0 } }, "sourceType": "module", "body": [ { "type": "ImportDeclaration", "start": 0, "end": 30, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 30 } }, "specifiers": [ { "type": "ImportDefaultSpecifier", "start": 7, "end": 14, "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 14 } }, "local": { "type": "Identifier", "start": 7, "end": 14, "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 14 }, "identifierName": "process" }, "name": "process" } } ], "source": { "type": "StringLiteral", "start": 20, "end": 29, "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 29 } }, "extra": { "rawValue": "process", "raw": "\"process\"" }, "value": "process" } }, { "type": "ImportDeclaration", "start": 31, "end": 51, "loc": { "start": { "line": 2, "column": 0 }, "end": { "line": 2, "column": 20 } }, "specifiers": [ { "type": "ImportDefaultSpecifier", "start": 38, "end": 40, "loc": { "start": { "line": 2, "column": 7 }, "end": { "line": 2, "column": 9 } }, "local": { "type": "Identifier", "start": 38, "end": 40, "loc": { "start": { "line": 2, "column": 7 }, "end": { "line": 2, "column": 9 }, "identifierName": "fs" }, "name": "fs" } } ], "source": { "type": "StringLiteral", "start": 46, "end": 50, "loc": { "start": { "line": 2, "column": 15 }, "end": { "line": 2, "column": 19 } }, "extra": { "rawValue": "fs", "raw": "\"fs\"" }, "value": "fs" } }, { "type": "ImportDeclaration", "start": 53, "end": 106, "loc": { "start": { "line": 4, "column": 0 }, "end": { "line": 4, "column": 53 } }, "specifiers": [ { "type": "ImportSpecifier", "start": 62, "end": 74, "loc": { "start": { "line": 4, "column": 9 }, "end": { "line": 4, "column": 21 } }, "imported": { "type": "Identifier", "start": 62, "end": 74, "loc": { "start": { "line": 4, "column": 9 }, "end": { "line": 4, "column": 21 }, "identifierName": "SpecialForms" }, "name": "SpecialForms" }, "local": { "type": "Identifier", "start": 62, "end": 74, "loc": { "start": { "line": 4, "column": 9 }, "end": { "line": 4, "column": 21 }, "identifierName": "SpecialForms" }, "name": "SpecialForms" } } ], "source": { "type": "StringLiteral", "start": 82, "end": 105, "loc": { "start": { "line": 4, "column": 29 }, "end": { "line": 4, "column": 52 } }, "extra": { "rawValue": "../interp/registry.js", "raw": "\"../interp/registry.js\"" }, "value": "../interp/registry.js" } }, { "type": "ImportDeclaration", "start": 107, "end": 157, "loc": { "start": { "line": 5, "column": 0 }, "end": { "line": 5, "column": 50 } }, "specifiers": [ { "type": "ImportSpecifier", "start": 116, "end": 122, "loc": { "start": { "line": 5, "column": 9 }, "end": { "line": 5, "column": 15 } }, "imported": { "type": "Identifier", "start": 116, "end": 122, "loc": { "start": { "line": 5, "column": 9 }, "end": { "line": 5, "column": 15 }, "identifierName": "TopEnv" }, "name": "TopEnv" }, "local": { "type": "Identifier", "start": 116, "end": 122, "loc": { "start": { "line": 5, "column": 9 }, "end": { "line": 5, "column": 15 }, "identifierName": "TopEnv" }, "name": "TopEnv" } } ], "source": { "type": "StringLiteral", "start": 130, "end": 156, "loc": { "start": { "line": 5, "column": 23 }, "end": { "line": 5, "column": 49 } }, "extra": { "rawValue": "../interp/environment.js", "raw": "\"../interp/environment.js\"" }, "value": "../interp/environment.js" } }, { "type": "ImportDeclaration", "start": 158, "end": 201, "loc": { "start": { "line": 6, "column": 0 }, "end": { "line": 6, "column": 43 } }, "specifiers": [ { "type": "ImportSpecifier", "start": 167, "end": 172, "loc": { "start": { "line": 6, "column": 9 }, "end": { "line": 6, "column": 14 } }, "imported": { "type": "Identifier", "start": 167, "end": 172, "loc": { "start": { "line": 6, "column": 9 }, "end": { "line": 6, "column": 14 }, "identifierName": "Eggvm" }, "name": "Eggvm" }, "local": { "type": "Identifier", "start": 167, "end": 172, "loc": { "start": { "line": 6, "column": 9 }, "end": { "line": 6, "column": 14 }, "identifierName": "Eggvm" }, "name": "Eggvm" } } ], "source": { "type": "StringLiteral", "start": 180, "end": 200, "loc": { "start": { "line": 6, "column": 22 }, "end": { "line": 6, "column": 42 } }, "extra": { "rawValue": "../interp/eggvm.js", "raw": "\"../interp/eggvm.js\"" }, "value": "../interp/eggvm.js" } }, { "type": "ImportDeclaration", "start": 203, "end": 236, "loc": { "start": { "line": 8, "column": 0 }, "end": { "line": 8, "column": 33 } }, "specifiers": [ { "type": "ImportDefaultSpecifier", "start": 210, "end": 216, "loc": { "start": { "line": 8, "column": 7 }, "end": { "line": 8, "column": 13 } }, "local": { "type": "Identifier", "start": 210, "end": 216, "loc": { "start": { "line": 8, "column": 7 }, "end": { "line": 8, "column": 13 }, "identifierName": "colors" }, "name": "colors" } } ], "source": { "type": "StringLiteral", "start": 222, "end": 235, "loc": { "start": { "line": 8, "column": 19 }, "end": { "line": 8, "column": 32 } }, "extra": { "rawValue": "./colors.js", "raw": "\"./colors.js\"" }, "value": "./colors.js" }, "trailingComments": [ { "type": "CommentLine", "value": " PROMPT", "start": 238, "end": 247, "loc": { "start": { "line": 10, "column": 0 }, "end": { "line": 10, "column": 9 } } } ] }, { "type": "ExpressionStatement", "start": 249, "end": 277, "loc": { "start": { "line": 12, "column": 0 }, "end": { "line": 12, "column": 28 } }, "expression": { "type": "AssignmentExpression", "start": 249, "end": 276, "loc": { "start": { "line": 12, "column": 0 }, "end": { "line": 12, "column": 27 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 249, "end": 269, "loc": { "start": { "line": 12, "column": 0 }, "end": { "line": 12, "column": 20 } }, "object": { "type": "Identifier", "start": 249, "end": 255, "loc": { "start": { "line": 12, "column": 0 }, "end": { "line": 12, "column": 6 }, "identifierName": "TopEnv" }, "name": "TopEnv", "leadingComments": null }, "property": { "type": "StringLiteral", "start": 256, "end": 268, "loc": { "start": { "line": 12, "column": 7 }, "end": { "line": 12, "column": 19 } }, "extra": { "rawValue": "__PROMPT__", "raw": "\"__PROMPT__\"" }, "value": "__PROMPT__" }, "computed": true, "leadingComments": null }, "right": { "type": "StringLiteral", "start": 272, "end": 276, "loc": { "start": { "line": 12, "column": 23 }, "end": { "line": 12, "column": 27 } }, "extra": { "rawValue": "> ", "raw": "\"> \"" }, "value": "> " }, "leadingComments": null }, "leadingComments": [ { "type": "CommentLine", "value": " PROMPT", "start": 238, "end": 247, "loc": { "start": { "line": 10, "column": 0 }, "end": { "line": 10, "column": 9 } } } ] }, { "type": "Identifier", "start": 279, "end": 382, "loc": { "start": { "line": 14, "column": 0 }, "end": { "line": 16, "column": 2 } }, "declarations": [ { "type": "VariableDeclarator", "start": 285, "end": 381, "loc": { "start": { "line": 14, "column": 6 }, "end": { "line": 16, "column": 1 } }, "id": { "type": "Identifier", "start": 285, "end": 298, "loc": { "start": { "line": 14, "column": 6 }, "end": { "line": 14, "column": 19 }, "identifierName": "getPromptLine" }, "name": "getPromptLine" }, "init": { "type": "ArrowFunctionExpression", "start": 301, "end": 381, "loc": { "start": { "line": 14, "column": 22 }, "end": { "line": 16, "column": 1 } }, "id": null, "generator": false, "expression": false, "async": false, "params": [], "body": { "type": "BlockStatement", "start": 307, "end": 381, "loc": { "start": { "line": 14, "column": 28 }, "end": { "line": 16, "column": 1 } }, "body": [ { "type": "ReturnStatement", "start": 311, "end": 379, "loc": { "start": { "line": 15, "column": 2 }, "end": { "line": 15, "column": 70 } }, "argument": { "type": "TemplateLiteral", "start": 318, "end": 378, "loc": { "start": { "line": 15, "column": 9 }, "end": { "line": 15, "column": 69 } }, "expressions": [ { "type": "MemberExpression", "start": 321, "end": 334, "loc": { "start": { "line": 15, "column": 12 }, "end": { "line": 15, "column": 25 } }, "object": { "type": "Identifier", "start": 321, "end": 327, "loc": { "start": { "line": 15, "column": 12 }, "end": { "line": 15, "column": 18 }, "identifierName": "colors" }, "name": "colors" }, "property": { "type": "Identifier", "start": 328, "end": 334, "loc": { "start": { "line": 15, "column": 19 }, "end": { "line": 15, "column": 25 }, "identifierName": "YELLOW" }, "name": "YELLOW" }, "computed": false }, { "type": "MemberExpression", "start": 338, "end": 358, "loc": { "start": { "line": 15, "column": 29 }, "end": { "line": 15, "column": 49 } }, "object": { "type": "Identifier", "start": 338, "end": 344, "loc": { "start": { "line": 15, "column": 29 }, "end": { "line": 15, "column": 35 }, "identifierName": "TopEnv" }, "name": "TopEnv" }, "property": { "type": "StringLiteral", "start": 345, "end": 357, "loc": { "start": { "line": 15, "column": 36 }, "end": { "line": 15, "column": 48 } }, "extra": { "rawValue": "__PROMPT__", "raw": "\"__PROMPT__\"" }, "value": "__PROMPT__" }, "computed": true }, { "type": "MemberExpression", "start": 362, "end": 376, "loc": { "start": { "line": 15, "column": 53 }, "end": { "line": 15, "column": 67 } }, "object": { "type": "Identifier", "start": 362, "end": 368, "loc": { "start": { "line": 15, "column": 53 }, "end": { "line": 15, "column": 59 }, "identifierName": "colors" }, "name": "colors" }, "property": { "type": "Identifier", "start": 369, "end": 376, "loc": { "start": { "line": 15, "column": 60 }, "end": { "line": 15, "column": 67 }, "identifierName": "DEFAULT" }, "name": "DEFAULT" }, "computed": false } ], "quasis": [ { "type": "TemplateElement", "start": 319, "end": 319, "loc": { "start": { "line": 15, "column": 10 }, "end": { "line": 15, "column": 10 } }, "value": { "raw": "", "cooked": "" }, "tail": false }, { "type": "TemplateElement", "start": 335, "end": 336, "loc": { "start": { "line": 15, "column": 26 }, "end": { "line": 15, "column": 27 } }, "value": { "raw": " ", "cooked": " " }, "tail": false }, { "type": "TemplateElement", "start": 359, "end": 360, "loc": { "start": { "line": 15, "column": 50 }, "end": { "line": 15, "column": 51 } }, "value": { "raw": " ", "cooked": " " }, "tail": false }, { "type": "TemplateElement", "start": 377, "end": 377, "loc": { "start": { "line": 15, "column": 68 }, "end": { "line": 15, "column": 68 } }, "value": { "raw": "", "cooked": "" }, "tail": true } ] } } ], "directives": [] } } } ], "kind": "const", "trailingComments": [], "name": "_", "leadingComments": [] }, { "type": "Identifier", "start": 402, "end": 540, "loc": { "start": { "line": 20, "column": 0 }, "end": { "line": 23, "column": 3 } }, "declarations": [ { "type": "VariableDeclarator", "start": 408, "end": 539, "loc": { "start": { "line": 20, "column": 6 }, "end": { "line": 23, "column": 2 } }, "id": { "type": "Identifier", "start": 408, "end": 415, "loc": { "start": { "line": 20, "column": 6 }, "end": { "line": 20, "column": 13 }, "identifierName": "eggExit" }, "name": "eggExit", "leadingComments": null }, "init": { "type": "AssignmentExpression", "start": 419, "end": 538, "loc": { "start": { "line": 20, "column": 17 }, "end": { "line": 23, "column": 1 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 419, "end": 433, "loc": { "start": { "line": 20, "column": 17 }, "end": { "line": 20, "column": 31 } }, "object": { "type": "Identifier", "start": 419, "end": 425, "loc": { "start": { "line": 20, "column": 17 }, "end": { "line": 20, "column": 23 }, "identifierName": "TopEnv" }, "name": "TopEnv" }, "property": { "type": "StringLiteral", "start": 426, "end": 432, "loc": { "start": { "line": 20, "column": 24 }, "end": { "line": 20, "column": 30 } }, "extra": { "rawValue": "exit", "raw": "\"exit\"" }, "value": "exit" }, "computed": true }, "right": { "type": "ArrowFunctionExpression", "start": 436, "end": 538, "loc": { "start": { "line": 20, "column": 34 }, "end": { "line": 23, "column": 1 } }, "id": null, "generator": false, "expression": false, "async": false, "params": [], "body": { "type": "BlockStatement", "start": 442, "end": 538, "loc": { "start": { "line": 20, "column": 40 }, "end": { "line": 23, "column": 1 } }, "body": [ { "type": "ExpressionStatement", "start": 446, "end": 517, "loc": { "start": { "line": 21, "column": 2 }, "end": { "line": 21, "column": 73 } }, "expression": { "type": "CallExpression", "start": 446, "end": 516, "loc": { "start": { "line": 21, "column": 2 }, "end": { "line": 21, "column": 72 } }, "callee": { "type": "MemberExpression", "start": 446, "end": 457, "loc": { "start": { "line": 21, "column": 2 }, "end": { "line": 21, "column": 13 } }, "object": { "type": "Identifier", "start": 446, "end": 453, "loc": { "start": { "line": 21, "column": 2 }, "end": { "line": 21, "column": 9 }, "identifierName": "console" }, "name": "console" }, "property": { "type": "Identifier", "start": 454, "end": 457, "loc": { "start": { "line": 21, "column": 10 }, "end": { "line": 21, "column": 13 }, "identifierName": "log" }, "name": "log" }, "computed": false }, "arguments": [ { "type": "BinaryExpression", "start": 458, "end": 515, "loc": { "start": { "line": 21, "column": 14 }, "end": { "line": 21, "column": 71 } }, "left": { "type": "BinaryExpression", "start": 458, "end": 498, "loc": { "start": { "line": 21, "column": 14 }, "end": { "line": 21, "column": 54 } }, "left": { "type": "MemberExpression", "start": 458, "end": 469, "loc": { "start": { "line": 21, "column": 14 }, "end": { "line": 21, "column": 25 } }, "object": { "type": "Identifier", "start": 458, "end": 464, "loc": { "start": { "line": 21, "column": 14 }, "end": { "line": 21, "column": 20 }, "identifierName": "colors" }, "name": "colors" }, "property": { "type": "Identifier", "start": 465, "end": 469, "loc": { "start": { "line": 21, "column": 21 }, "end": { "line": 21, "column": 25 }, "identifierName": "BLUE" }, "name": "BLUE" }, "computed": false }, "operator": "+", "right": { "type": "StringLiteral", "start": 472, "end": 498, "loc": { "start": { "line": 21, "column": 28 }, "end": { "line": 21, "column": 54 } }, "extra": { "rawValue": "Closing the REPL... Bye!", "raw": "\"Closing the REPL... Bye!\"" }, "value": "Closing the REPL... Bye!" } }, "operator": "+", "right": { "type": "MemberExpression", "start": 501, "end": 515, "loc": { "start": { "line": 21, "column": 57 }, "end": { "line": 21, "column": 71 } }, "object": { "type": "Identifier", "start": 501, "end": 507, "loc": { "start": { "line": 21, "column": 57 }, "end": { "line": 21, "column": 63 }, "identifierName": "colors" }, "name": "colors" }, "property": { "type": "Identifier", "start": 508, "end": 515, "loc": { "start": { "line": 21, "column": 64 }, "end": { "line": 21, "column": 71 }, "identifierName": "DEFAULT" }, "name": "DEFAULT" }, "computed": false } } ] } }, { "type": "ExpressionStatement", "start": 520, "end": 536, "loc": { "start": { "line": 22, "column": 2 }, "end": { "line": 22, "column": 18 } }, "expression": { "type": "CallExpression", "start": 520, "end": 535, "loc": { "start": { "line": 22, "column": 2 }, "end": { "line": 22, "column": 17 } }, "callee": { "type": "MemberExpression", "start": 520, "end": 532, "loc": { "start": { "line": 22, "column": 2 }, "end": { "line": 22, "column": 14 } }, "object": { "type": "Identifier", "start": 520, "end": 527, "loc": { "start": { "line": 22, "column": 2 }, "end": { "line": 22, "column": 9 }, "identifierName": "process" }, "name": "process" }, "property": { "type": "Identifier", "start": 528, "end": 532, "loc": { "start": { "line": 22, "column": 10 }, "end": { "line": 22, "column": 14 }, "identifierName": "exit" }, "name": "exit" }, "computed": false }, "arguments": [ { "type": "NumericLiteral", "start": 533, "end": 534, "loc": { "start": { "line": 22, "column": 15 }, "end": { "line": 22, "column": 16 } }, "extra": { "rawValue": 0, "raw": "0" }, "value": 0 } ] } } ], "directives": [] } }, "extra": { "parenthesized": true, "parenStart": 418 } }, "leadingComments": null } ], "kind": "const", "leadingComments": [], "name": "_", "trailingComments": [] }, { "type": "VariableDeclaration", "start": 542, "end": 822, "loc": { "start": { "line": 25, "column": 0 }, "end": { "line": 30, "column": 2 } }, "declarations": [ { "type": "VariableDeclarator", "start": 548, "end": 821, "loc": { "start": { "line": 25, "column": 6 }, "end": { "line": 30, "column": 1 } }, "id": { "type": "Identifier", "start": 548, "end": 552, "loc": { "start": { "line": 25, "column": 6 }, "end": { "line": 25, "column": 10 }, "identifierName": "HELP" }, "name": "HELP" }, "init": { "type": "ArrayExpression", "start": 555, "end": 821, "loc": { "start": { "line": 25, "column": 13 }, "end": { "line": 30, "column": 1 } }, "elements": [ { "type": "TemplateLiteral", "start": 559, "end": 620, "loc": { "start": { "line": 26, "column": 2 }, "end": { "line": 26, "column": 63 } }, "expressions": [ { "type": "MemberExpression", "start": 562, "end": 573, "loc": { "start": { "line": 26, "column": 5 }, "end": { "line": 26, "column": 16 } }, "object": { "type": "Identifier", "start": 562, "end": 568, "loc": { "start": { "line": 26, "column": 5 }, "end": { "line": 26, "column": 11 }, "identifierName": "colors" }, "name": "colors" }, "property": { "type": "Identifier", "start": 569, "end": 573, "loc": { "start": { "line": 26, "column": 12 }, "end": { "line": 26, "column": 16 }, "identifierName": "BLUE" }, "name": "BLUE" }, "computed": false }, { "type": "MemberExpression", "start": 584, "end": 598, "loc": { "start": { "line": 26, "column": 27 }, "end": { "line": 26, "column": 41 } }, "object": { "type": "Identifier", "start": 584, "end": 590, "loc": { "start": { "line": 26, "column": 27 }, "end": { "line": 26, "column": 33