UNPKG

eggtended-js

Version:

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

1,632 lines 1.35 MB
{ "type": "File", "start": 0, "end": 6204, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 270, "column": 0 } }, "program": { "type": "Program", "start": 0, "end": 6204, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 270, "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": "xRegExp" }, "name": "xRegExp" } } ], "source": { "type": "StringLiteral", "start": 20, "end": 29, "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 29 } }, "extra": { "rawValue": "xregexp", "raw": "\"xregexp\"" }, "value": "xregexp" } }, { "type": "ImportDeclaration", "start": 32, "end": 64, "loc": { "start": { "line": 3, "column": 0 }, "end": { "line": 3, "column": 32 } }, "specifiers": [ { "type": "ImportDefaultSpecifier", "start": 39, "end": 44, "loc": { "start": { "line": 3, "column": 7 }, "end": { "line": 3, "column": 12 } }, "local": { "type": "Identifier", "start": 39, "end": 44, "loc": { "start": { "line": 3, "column": 7 }, "end": { "line": 3, "column": 12 }, "identifierName": "utils" }, "name": "utils" } } ], "source": { "type": "StringLiteral", "start": 50, "end": 63, "loc": { "start": { "line": 3, "column": 18 }, "end": { "line": 3, "column": 31 } }, "extra": { "rawValue": "../utils.js", "raw": "\"../utils.js\"" }, "value": "../utils.js" } }, { "type": "ImportDeclaration", "start": 66, "end": 113, "loc": { "start": { "line": 5, "column": 0 }, "end": { "line": 5, "column": 47 } }, "specifiers": [ { "type": "ImportSpecifier", "start": 75, "end": 86, "loc": { "start": { "line": 5, "column": 9 }, "end": { "line": 5, "column": 20 } }, "imported": { "type": "Identifier", "start": 75, "end": 86, "loc": { "start": { "line": 5, "column": 9 }, "end": { "line": 5, "column": 20 }, "identifierName": "SymbolTable" }, "name": "SymbolTable" }, "local": { "type": "Identifier", "start": 75, "end": 86, "loc": { "start": { "line": 5, "column": 9 }, "end": { "line": 5, "column": 20 }, "identifierName": "SymbolTable" }, "name": "SymbolTable" } } ], "source": { "type": "StringLiteral", "start": 94, "end": 112, "loc": { "start": { "line": 5, "column": 28 }, "end": { "line": 5, "column": 46 } }, "extra": { "rawValue": "./symboltable.js", "raw": "\"./symboltable.js\"" }, "value": "./symboltable.js" }, "trailingComments": [ { "type": "CommentLine", "value": " specialForms and topEnv maps", "start": 115, "end": 146, "loc": { "start": { "line": 7, "column": 0 }, "end": { "line": 7, "column": 31 } } } ] }, { "type": "Identifier", "start": 147, "end": 188, "loc": { "start": { "line": 8, "column": 0 }, "end": { "line": 8, "column": 41 } }, "declarations": [ { "type": "VariableDeclarator", "start": 153, "end": 187, "loc": { "start": { "line": 8, "column": 6 }, "end": { "line": 8, "column": 40 } }, "id": { "type": "Identifier", "start": 153, "end": 165, "loc": { "start": { "line": 8, "column": 6 }, "end": { "line": 8, "column": 18 }, "identifierName": "SpecialForms" }, "name": "SpecialForms", "leadingComments": null }, "init": { "type": "CallExpression", "start": 168, "end": 187, "loc": { "start": { "line": 8, "column": 21 }, "end": { "line": 8, "column": 40 } }, "callee": { "type": "MemberExpression", "start": 168, "end": 181, "loc": { "start": { "line": 8, "column": 21 }, "end": { "line": 8, "column": 34 } }, "object": { "type": "Identifier", "start": 168, "end": 174, "loc": { "start": { "line": 8, "column": 21 }, "end": { "line": 8, "column": 27 }, "identifierName": "Object" }, "name": "Object" }, "property": { "type": "Identifier", "start": 175, "end": 181, "loc": { "start": { "line": 8, "column": 28 }, "end": { "line": 8, "column": 34 }, "identifierName": "create" }, "name": "create" }, "computed": false }, "arguments": [ { "type": "NullLiteral", "start": 182, "end": 186, "loc": { "start": { "line": 8, "column": 35 }, "end": { "line": 8, "column": 39 } } } ] }, "leadingComments": null } ], "kind": "const", "leadingComments": [], "name": "_", "trailingComments": [] }, { "type": "Identifier", "start": 189, "end": 224, "loc": { "start": { "line": 9, "column": 0 }, "end": { "line": 9, "column": 35 } }, "declarations": [ { "type": "VariableDeclarator", "start": 195, "end": 223, "loc": { "start": { "line": 9, "column": 6 }, "end": { "line": 9, "column": 34 } }, "id": { "type": "Identifier", "start": 195, "end": 201, "loc": { "start": { "line": 9, "column": 6 }, "end": { "line": 9, "column": 12 }, "identifierName": "TopEnv" }, "name": "TopEnv" }, "init": { "type": "CallExpression", "start": 204, "end": 223, "loc": { "start": { "line": 9, "column": 15 }, "end": { "line": 9, "column": 34 } }, "callee": { "type": "MemberExpression", "start": 204, "end": 217, "loc": { "start": { "line": 9, "column": 15 }, "end": { "line": 9, "column": 28 } }, "object": { "type": "Identifier", "start": 204, "end": 210, "loc": { "start": { "line": 9, "column": 15 }, "end": { "line": 9, "column": 21 }, "identifierName": "Object" }, "name": "Object" }, "property": { "type": "Identifier", "start": 211, "end": 217, "loc": { "start": { "line": 9, "column": 22 }, "end": { "line": 9, "column": 28 }, "identifierName": "create" }, "name": "create" }, "computed": false }, "arguments": [ { "type": "NullLiteral", "start": 218, "end": 222, "loc": { "start": { "line": 9, "column": 29 }, "end": { "line": 9, "column": 33 } } } ] } } ], "kind": "const", "name": "_", "leadingComments": [], "trailingComments": [] }, { "type": "ExpressionStatement", "start": 226, "end": 483, "loc": { "start": { "line": 11, "column": 0 }, "end": { "line": 21, "column": 2 } }, "expression": { "type": "AssignmentExpression", "start": 226, "end": 482, "loc": { "start": { "line": 11, "column": 0 }, "end": { "line": 21, "column": 1 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 226, "end": 244, "loc": { "start": { "line": 11, "column": 0 }, "end": { "line": 11, "column": 18 } }, "object": { "type": "Identifier", "start": 226, "end": 238, "loc": { "start": { "line": 11, "column": 0 }, "end": { "line": 11, "column": 12 }, "identifierName": "SpecialForms" }, "name": "SpecialForms" }, "property": { "type": "StringLiteral", "start": 239, "end": 243, "loc": { "start": { "line": 11, "column": 13 }, "end": { "line": 11, "column": 17 } }, "extra": { "rawValue": "if", "raw": "\"if\"" }, "value": "if" }, "computed": true }, "right": { "type": "ArrowFunctionExpression", "start": 247, "end": 482, "loc": { "start": { "line": 11, "column": 21 }, "end": { "line": 21, "column": 1 } }, "id": null, "generator": false, "expression": false, "async": false, "params": [ { "type": "Identifier", "start": 248, "end": 252, "loc": { "start": { "line": 11, "column": 22 }, "end": { "line": 11, "column": 26 }, "identifierName": "args" }, "name": "args" }, { "type": "Identifier", "start": 254, "end": 257, "loc": { "start": { "line": 11, "column": 28 }, "end": { "line": 11, "column": 31 }, "identifierName": "env" }, "name": "env" } ], "body": { "type": "BlockStatement", "start": 262, "end": 482, "loc": { "start": { "line": 11, "column": 36 }, "end": { "line": 21, "column": 1 } }, "body": [ { "type": "IfStatement", "start": 266, "end": 356, "loc": { "start": { "line": 12, "column": 2 }, "end": { "line": 14, "column": 3 } }, "test": { "type": "BinaryExpression", "start": 270, "end": 287, "loc": { "start": { "line": 12, "column": 6 }, "end": { "line": 12, "column": 23 } }, "left": { "type": "MemberExpression", "start": 270, "end": 281, "loc": { "start": { "line": 12, "column": 6 }, "end": { "line": 12, "column": 17 } }, "object": { "type": "Identifier", "start": 270, "end": 274, "loc": { "start": { "line": 12, "column": 6 }, "end": { "line": 12, "column": 10 }, "identifierName": "args" }, "name": "args" }, "property": { "type": "Identifier", "start": 275, "end": 281, "loc": { "start": { "line": 12, "column": 11 }, "end": { "line": 12, "column": 17 }, "identifierName": "length" }, "name": "length" }, "computed": false }, "operator": "!==", "right": { "type": "NumericLiteral", "start": 286, "end": 287, "loc": { "start": { "line": 12, "column": 22 }, "end": { "line": 12, "column": 23 } }, "extra": { "rawValue": 3, "raw": "3" }, "value": 3 } }, "consequent": { "type": "BlockStatement", "start": 289, "end": 356, "loc": { "start": { "line": 12, "column": 25 }, "end": { "line": 14, "column": 3 } }, "body": [ { "type": "ThrowStatement", "start": 295, "end": 352, "loc": { "start": { "line": 13, "column": 4 }, "end": { "line": 13, "column": 61 } }, "argument": { "type": "NewExpression", "start": 301, "end": 351, "loc": { "start": { "line": 13, "column": 10 }, "end": { "line": 13, "column": 60 } }, "callee": { "type": "Identifier", "start": 305, "end": 316, "loc": { "start": { "line": 13, "column": 14 }, "end": { "line": 13, "column": 25 }, "identifierName": "SyntaxError" }, "name": "SyntaxError" }, "arguments": [ { "type": "StringLiteral", "start": 317, "end": 350, "loc": { "start": { "line": 13, "column": 26 }, "end": { "line": 13, "column": 59 } }, "extra": { "rawValue": "Bad number of args passed to if", "raw": "\"Bad number of args passed to if\"" }, "value": "Bad number of args passed to if" } ] } } ], "directives": [] }, "alternate": null }, { "type": "IfStatement", "start": 360, "end": 480, "loc": { "start": { "line": 16, "column": 2 }, "end": { "line": 20, "column": 3 } }, "test": { "type": "BinaryExpression", "start": 364, "end": 394, "loc": { "start": { "line": 16, "column": 6 }, "end": { "line": 16, "column": 36 } }, "left": { "type": "CallExpression", "start": 364, "end": 385, "loc": { "start": { "line": 16, "column": 6 }, "end": { "line": 16, "column": 27 } }, "callee": { "type": "MemberExpression", "start": 364, "end": 380, "loc": { "start": { "line": 16, "column": 6 }, "end": { "line": 16, "column": 22 } }, "object": { "type": "MemberExpression", "start": 364, "end": 371, "loc": { "start": { "line": 16, "column": 6 }, "end": { "line": 16, "column": 13 } }, "object": { "type": "Identifier", "start": 364, "end": 368, "loc": { "start": { "line": 16, "column": 6 }, "end": { "line": 16, "column": 10 }, "identifierName": "args" }, "name": "args" }, "property": { "type": "NumericLiteral", "start": 369, "end": 370, "loc": { "start": { "line": 16, "column": 11 }, "end": { "line": 16, "column": 12 } }, "extra": { "rawValue": 0, "raw": "0" }, "value": 0 }, "computed": true }, "property": { "type": "Identifier", "start": 372, "end": 380, "loc": { "start": { "line": 16, "column": 14 }, "end": { "line": 16, "column": 22 }, "identifierName": "evaluate" }, "name": "evaluate" }, "computed": false }, "arguments": [ { "type": "Identifier", "start": 381, "end": 384, "loc": { "start": { "line": 16, "column": 23 }, "end": { "line": 16, "column": 26 }, "identifierName": "env" }, "name": "env" } ] }, "operator": "===", "right": { "type": "BooleanLiteral", "start": 390, "end": 394, "loc": { "start": { "line": 16, "column": 32 }, "end": { "line": 16, "column": 36 } }, "value": true } }, "consequent": { "type": "BlockStatement", "start": 396, "end": 435, "loc": { "start": { "line": 16, "column": 38 }, "end": { "line": 18, "column": 3 } }, "body": [ { "type": "ReturnStatement", "start": 402, "end": 431, "loc": { "start": { "line": 17, "column": 4 }, "end": { "line": 17, "column": 33 } }, "argument": { "type": "CallExpression", "start": 409, "end": 430, "loc": { "start": { "line": 17, "column": 11 }, "end": { "line": 17, "column": 32 } }, "callee": { "type": "MemberExpression", "start": 409, "end": 425, "loc": { "start": { "line": 17, "column": 11 }, "end": { "line": 17, "column": 27 } }, "object": { "type": "MemberExpression", "start": 409, "end": 416, "loc": { "start": { "line": 17, "column": 11 }, "end": { "line": 17, "column": 18 } }, "object": { "type": "Identifier", "start": 409, "end": 413, "loc": { "start": { "line": 17, "column": 11 }, "end": { "line": 17, "column": 15 }, "identifierName": "args" }, "name": "args" }, "property": { "type": "NumericLiteral", "start": 414, "end": 415, "loc": { "start": { "line": 17, "column": 16 }, "end": { "line": 17, "column": 17 } }, "extra": { "rawValue": 1, "raw": "1" }, "value": 1 }, "computed": true }, "property": { "type": "Identifier", "start": 417, "end": 425, "loc": { "start": { "line": 17, "column": 19 }, "end": { "line": 17, "column": 27 }, "identifierName": "evaluate" }, "name": "evaluate" }, "computed": false }, "arguments": [ { "type": "Identifier", "start": 426, "end": 429, "loc": { "start": { "line": 17, "column": 28 }, "end": { "line": 17, "column": 31 }, "identifierName": "env" }, "name": "env" } ] } } ], "directives": [] }, "alternate": { "type": "BlockStatement", "start": 441, "end": 480, "loc": { "start": { "line": 18, "column": 9 }, "end": { "line": 20, "column": 3 } }, "body": [ { "type": "ReturnStatement", "start": 447, "end": 476, "loc": { "start": { "line": 19, "column": 4 }, "end": { "line": 19, "column": 33 } }, "argument": { "type": "CallExpression", "start": 454, "end": 475, "loc": { "start": { "line": 19, "column": 11 }, "end": { "line": 19, "column": 32 } }, "callee": { "type": "MemberExpression", "start": 454, "end": 470, "loc": { "start": { "line": 19, "column": 11 }, "end": { "line": 19, "column": 27 } }, "object": { "type": "MemberExpression", "start": 454, "end": 461, "loc": { "start": { "line": 19, "column": 11 }, "end": { "line": 19, "column": 18 } }, "object": { "type": "Identifier", "start": 454, "end": 458, "loc": { "start": { "line": 19, "column": 11 }, "end": { "line": 19, "column": 15 }, "identifierName": "args" }, "name": "args" }, "property": { "type": "NumericLiteral", "start": 459, "end": 460, "loc": { "start": { "line": 19, "column": 16 }, "end": { "line": 19, "column": 17 } }, "extra": { "rawValue": 2, "raw": "2" }, "value": 2 }, "computed": true }, "property": { "type": "Identifier", "start": 462, "end": 470, "loc": { "start": { "line": 19, "column": 19 }, "end": { "line": 19, "column": 27 }, "identifierName": "evaluate" }, "name": "evaluate" }, "computed": false }, "arguments": [ { "type": "Identifier", "start": 471, "end": 474, "loc": { "start": { "line": 19, "column": 28 }, "end": { "line": 19, "column": 31 }, "identifierName": "env" }, "name": "env" } ] } } ], "directives": [] } } ], "directives": [] } } } }, { "type": "ExpressionStatement", "start": 485, "end": 795, "loc": { "start": { "line": 23, "column": 0 }, "end": { "line": 34, "column": 2 } }, "expression": { "type": "AssignmentExpression", "start": 485, "end": 794, "loc": { "start": { "line": 23, "column": 0 }, "end": { "line": 34, "column": 1 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 485, "end": 506, "loc": { "start": { "line": 23, "column": 0 }, "end": { "line": 23, "column": 21 } }, "object": { "type": "Identifier", "start": 485, "end": 497, "loc": { "start": { "line": 23, "column": 0 }, "end": { "line": 23, "column": 12 }, "identifierName": "SpecialForms" }, "name": "SpecialForms" }, "property": { "type": "StringLiteral", "start": 498, "end": 505, "loc": { "start": { "line": 23, "column": 13 }, "end": { "line": 23, "column": 20 } }, "extra": { "rawValue": "while", "raw": "\"while\"" }, "value": "while" }, "computed": true }, "right": { "type": "ArrowFunctionExpression", "start": 509, "end": 794, "loc": { "start": { "line": 23, "column": 24 }, "end": { "line": 34, "column": 1 } }, "id": null, "generator": false, "expression": false, "async": false, "params": [ { "type": "Identifier", "start": 510, "end": 514, "loc": { "start": { "line": 23, "column": 25 }, "end": { "line": 23, "column": 29 }, "identifierName": "args" }, "name": "args" }, { "type": "Identifier", "start": 516, "end": 519, "loc": { "start": { "line": 23, "column": 31 }, "end": { "line": 23, "column": 34 }, "identifierName": "env" }, "name": "env" } ], "body": { "type": "BlockStatement", "start": 524, "end": 794, "loc": { "start": { "line": 23, "column": 39 }, "end": { "line": 34, "column": 1 } }, "body": [ { "type": "IfStatement", "start": 528, "end": 621, "loc": { "start": { "line": 24, "column": 2 }, "end": { "line": 26, "column": 3 } }, "test": { "type": "BinaryExpression", "start": 532, "end": 549, "loc": { "start": { "line": 24, "column": 6 }, "end": { "line": 24, "column": 23 } }, "left": { "type": "MemberExpression", "start": 532, "end": 543, "loc": { "start": { "line": 24, "column": 6 }, "end": { "line": 24, "column": 17 } }, "object": { "type": "Identifier", "start": 532, "end": 536, "loc": { "start": { "line": 24, "column": 6 }, "end": { "line": 24, "column": 10 }, "identifierName": "args" }, "name": "args" }, "property": { "type": "Identifier", "start": 537, "end": 543, "loc": { "start": { "line": 24, "column": 11 }, "end": { "line": 24, "column": 17 }, "identifierName": "length" }, "name": "length" }, "computed": false }, "operator": "!==", "right": { "type": "NumericLiteral", "start": 548, "end": 549, "loc": { "start": { "line": 24, "column": 22 }, "end": { "line": 24, "column": 23 } }, "extra": { "rawValue": 2, "raw": "2" }, "value": 2 } }, "consequent": { "type": "BlockStatement", "start": 551, "end": 621, "loc": { "start": { "line": 24, "column": 25 }, "end": { "line": 26, "column": 3 } }, "body": [ { "type": "ThrowStatement", "star