eggtended-js
Version:
A extended version of the Egg programming language from the Eloquent Javascript book.
1,616 lines • 1.02 MB
JSON
{
"type": "File",
"start": 0,
"end": 3259,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 136,
"column": 0
}
},
"program": {
"type": "Program",
"start": 0,
"end": 3259,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 136,
"column": 0
}
},
"sourceType": "module",
"body": [
{
"type": "ImportDeclaration",
"start": 0,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 20
}
},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"start": 7,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 9
}
},
"local": {
"type": "Identifier",
"start": 7,
"end": 9,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 9
},
"identifierName": "fs"
},
"name": "fs"
}
}
],
"source": {
"type": "StringLiteral",
"start": 15,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 19
}
},
"extra": {
"rawValue": "fs",
"raw": "\"fs\""
},
"value": "fs"
}
},
{
"type": "ImportDeclaration",
"start": 22,
"end": 57,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 35
}
},
"specifiers": [
{
"type": "ImportSpecifier",
"start": 31,
"end": 36,
"loc": {
"start": {
"line": 3,
"column": 9
},
"end": {
"line": 3,
"column": 14
}
},
"imported": {
"type": "Identifier",
"start": 31,
"end": 36,
"loc": {
"start": {
"line": 3,
"column": 9
},
"end": {
"line": 3,
"column": 14
},
"identifierName": "Lexer"
},
"name": "Lexer"
},
"local": {
"type": "Identifier",
"start": 31,
"end": 36,
"loc": {
"start": {
"line": 3,
"column": 9
},
"end": {
"line": 3,
"column": 14
},
"identifierName": "Lexer"
},
"name": "Lexer"
}
}
],
"source": {
"type": "StringLiteral",
"start": 44,
"end": 56,
"loc": {
"start": {
"line": 3,
"column": 22
},
"end": {
"line": 3,
"column": 34
}
},
"extra": {
"rawValue": "./lexer.js",
"raw": "\"./lexer.js\""
},
"value": "./lexer.js"
}
},
{
"type": "ImportDeclaration",
"start": 58,
"end": 119,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 61
}
},
"specifiers": [
{
"type": "ImportSpecifier",
"start": 67,
"end": 72,
"loc": {
"start": {
"line": 4,
"column": 9
},
"end": {
"line": 4,
"column": 14
}
},
"imported": {
"type": "Identifier",
"start": 67,
"end": 72,
"loc": {
"start": {
"line": 4,
"column": 9
},
"end": {
"line": 4,
"column": 14
},
"identifierName": "Value"
},
"name": "Value"
},
"local": {
"type": "Identifier",
"start": 67,
"end": 72,
"loc": {
"start": {
"line": 4,
"column": 9
},
"end": {
"line": 4,
"column": 14
},
"identifierName": "Value"
},
"name": "Value"
}
},
{
"type": "ImportSpecifier",
"start": 74,
"end": 78,
"loc": {
"start": {
"line": 4,
"column": 16
},
"end": {
"line": 4,
"column": 20
}
},
"imported": {
"type": "Identifier",
"start": 74,
"end": 78,
"loc": {
"start": {
"line": 4,
"column": 16
},
"end": {
"line": 4,
"column": 20
},
"identifierName": "Word"
},
"name": "Word"
},
"local": {
"type": "Identifier",
"start": 74,
"end": 78,
"loc": {
"start": {
"line": 4,
"column": 16
},
"end": {
"line": 4,
"column": 20
},
"identifierName": "Word"
},
"name": "Word"
}
},
{
"type": "ImportSpecifier",
"start": 80,
"end": 85,
"loc": {
"start": {
"line": 4,
"column": 22
},
"end": {
"line": 4,
"column": 27
}
},
"imported": {
"type": "Identifier",
"start": 80,
"end": 85,
"loc": {
"start": {
"line": 4,
"column": 22
},
"end": {
"line": 4,
"column": 27
},
"identifierName": "Apply"
},
"name": "Apply"
},
"local": {
"type": "Identifier",
"start": 80,
"end": 85,
"loc": {
"start": {
"line": 4,
"column": 22
},
"end": {
"line": 4,
"column": 27
},
"identifierName": "Apply"
},
"name": "Apply"
}
},
{
"type": "ImportSpecifier",
"start": 87,
"end": 92,
"loc": {
"start": {
"line": 4,
"column": 29
},
"end": {
"line": 4,
"column": 34
}
},
"imported": {
"type": "Identifier",
"start": 87,
"end": 92,
"loc": {
"start": {
"line": 4,
"column": 29
},
"end": {
"line": 4,
"column": 34
},
"identifierName": "Regex"
},
"name": "Regex"
},
"local": {
"type": "Identifier",
"start": 87,
"end": 92,
"loc": {
"start": {
"line": 4,
"column": 29
},
"end": {
"line": 4,
"column": 34
},
"identifierName": "Regex"
},
"name": "Regex"
}
}
],
"source": {
"type": "StringLiteral",
"start": 100,
"end": 118,
"loc": {
"start": {
"line": 4,
"column": 42
},
"end": {
"line": 4,
"column": 60
}
},
"extra": {
"rawValue": "../interp/ast.js",
"raw": "\"../interp/ast.js\""
},
"value": "../interp/ast.js"
},
"trailingComments": [
{
"type": "CommentBlock",
"value": "*\n * Parser class. Iterates through the given string, tokenizes it and returns a AST tree.\n * @access public\n ",
"start": 121,
"end": 235,
"loc": {
"start": {
"line": 6,
"column": 0
},
"end": {
"line": 9,
"column": 3
}
}
}
]
},
{
"type": "Identifier",
"start": 236,
"end": 3238,
"loc": {
"start": {
"line": 10,
"column": 0
},
"end": {
"line": 133,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 242,
"end": 248,
"loc": {
"start": {
"line": 10,
"column": 6
},
"end": {
"line": 10,
"column": 12
},
"identifierName": "Parser"
},
"name": "Parser",
"leadingComments": null
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 249,
"end": 3238,
"loc": {
"start": {
"line": 10,
"column": 13
},
"end": {
"line": 133,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 323,
"end": 411,
"loc": {
"start": {
"line": 14,
"column": 2
},
"end": {
"line": 18,
"column": 3
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 323,
"end": 334,
"loc": {
"start": {
"line": 14,
"column": 2
},
"end": {
"line": 14,
"column": 13
},
"identifierName": "constructor"
},
"name": "constructor",
"leadingComments": null
},
"kind": "constructor",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 337,
"end": 411,
"loc": {
"start": {
"line": 14,
"column": 16
},
"end": {
"line": 18,
"column": 3
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 343,
"end": 358,
"loc": {
"start": {
"line": 15,
"column": 4
},
"end": {
"line": 15,
"column": 19
}
},
"expression": {
"type": "AssignmentExpression",
"start": 343,
"end": 357,
"loc": {
"start": {
"line": 15,
"column": 4
},
"end": {
"line": 15,
"column": 18
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 343,
"end": 353,
"loc": {
"start": {
"line": 15,
"column": 4
},
"end": {
"line": 15,
"column": 14
}
},
"object": {
"type": "ThisExpression",
"start": 343,
"end": 347,
"loc": {
"start": {
"line": 15,
"column": 4
},
"end": {
"line": 15,
"column": 8
}
}
},
"property": {
"type": "Identifier",
"start": 348,
"end": 353,
"loc": {
"start": {
"line": 15,
"column": 9
},
"end": {
"line": 15,
"column": 14
},
"identifierName": "index"
},
"name": "index"
},
"computed": false
},
"right": {
"type": "NumericLiteral",
"start": 356,
"end": 357,
"loc": {
"start": {
"line": 15,
"column": 17
},
"end": {
"line": 15,
"column": 18
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
}
},
{
"type": "ExpressionStatement",
"start": 363,
"end": 380,
"loc": {
"start": {
"line": 16,
"column": 4
},
"end": {
"line": 16,
"column": 21
}
},
"expression": {
"type": "AssignmentExpression",
"start": 363,
"end": 379,
"loc": {
"start": {
"line": 16,
"column": 4
},
"end": {
"line": 16,
"column": 20
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 363,
"end": 374,
"loc": {
"start": {
"line": 16,
"column": 4
},
"end": {
"line": 16,
"column": 15
}
},
"object": {
"type": "ThisExpression",
"start": 363,
"end": 367,
"loc": {
"start": {
"line": 16,
"column": 4
},
"end": {
"line": 16,
"column": 8
}
}
},
"property": {
"type": "Identifier",
"start": 368,
"end": 374,
"loc": {
"start": {
"line": 16,
"column": 9
},
"end": {
"line": 16,
"column": 15
},
"identifierName": "tokens"
},
"name": "tokens"
},
"computed": false
},
"right": {
"type": "ArrayExpression",
"start": 377,
"end": 379,
"loc": {
"start": {
"line": 16,
"column": 18
},
"end": {
"line": 16,
"column": 20
}
},
"elements": []
}
}
},
{
"type": "ExpressionStatement",
"start": 385,
"end": 407,
"loc": {
"start": {
"line": 17,
"column": 4
},
"end": {
"line": 17,
"column": 26
}
},
"expression": {
"type": "AssignmentExpression",
"start": 385,
"end": 406,
"loc": {
"start": {
"line": 17,
"column": 4
},
"end": {
"line": 17,
"column": 25
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 385,
"end": 399,
"loc": {
"start": {
"line": 17,
"column": 4
},
"end": {
"line": 17,
"column": 18
}
},
"object": {
"type": "ThisExpression",
"start": 385,
"end": 389,
"loc": {
"start": {
"line": 17,
"column": 4
},
"end": {
"line": 17,
"column": 8
}
}
},
"property": {
"type": "Identifier",
"start": 390,
"end": 399,
"loc": {
"start": {
"line": 17,
"column": 9
},
"end": {
"line": 17,
"column": 18
},
"identifierName": "lookahead"
},
"name": "lookahead"
},
"computed": false
},
"right": {
"type": "NullLiteral",
"start": 402,
"end": 406,
"loc": {
"start": {
"line": 17,
"column": 21
},
"end": {
"line": 17,
"column": 25
}
}
}
}
}
],
"directives": []
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\n * Attributes used by the parser, set to default values\n ",
"start": 253,
"end": 320,
"loc": {
"start": {
"line": 11,
"column": 2
},
"end": {
"line": 13,
"column": 5
}
}
}
]
},
{
"type": "ClassMethod",
"start": 415,
"end": 556,
"loc": {
"start": {
"line": 20,
"column": 2
},
"end": {
"line": 28,
"column": 3
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 415,
"end": 425,
"loc": {
"start": {
"line": 20,
"column": 2
},
"end": {
"line": 20,
"column": 12
},
"identifierName": "setProgram"
},
"name": "setProgram"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 426,
"end": 433,
"loc": {
"start": {
"line": 20,
"column": 13
},
"end": {
"line": 20,
"column": 20
},
"identifierName": "program"
},
"name": "program"
}
],
"body": {
"type": "BlockStatement",
"start": 435,
"end": 556,
"loc": {
"start": {
"line": 20,
"column": 22
},
"end": {
"line": 28,
"column": 3
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 441,
"end": 464,
"loc": {
"start": {
"line": 21,
"column": 4
},
"end": {
"line": 21,
"column": 27
}
},
"expression": {
"type": "AssignmentExpression",
"start": 441,
"end": 463,
"loc": {
"start": {
"line": 21,
"column": 4
},
"end": {
"line": 21,
"column": 26
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 441,
"end": 453,
"loc": {
"start": {
"line": 21,
"column": 4
},
"end": {
"line": 21,
"column": 16
}
},
"object": {
"type": "ThisExpression",
"start": 441,
"end": 445,
"loc": {
"start": {
"line": 21,
"column": 4
},
"end": {
"line": 21,
"column": 8
}
}
},
"property": {
"type": "Identifier",
"start": 446,
"end": 453,
"loc": {
"start": {
"line": 21,
"column": 9
},
"end": {
"line": 21,
"column": 16
},
"identifierName": "program"
},
"name": "program"
},
"computed": false
},
"right": {
"type": "Identifier",
"start": 456,
"end": 463,
"loc": {
"start": {
"line": 21,
"column": 19
},
"end": {
"line": 21,
"column": 26
},
"identifierName": "program"
},
"name": "program"
}
}
},
{
"type": "ExpressionStatement",
"start": 470,
"end": 485,
"loc": {
"start": {
"line": 23,
"column": 4
},
"end": {
"line": 23,
"column": 19
}
},
"expression": {
"type": "AssignmentExpression",
"start": 470,
"end": 484,
"loc": {
"start": {
"line": 23,
"column": 4
},
"end": {
"line": 23,
"column": 18
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 470,
"end": 480,
"loc": {
"start": {
"line": 23,
"column": 4
},
"end": {
"line": 23,
"column": 14
}
},
"object": {
"type": "ThisExpression",
"start": 470,
"end": 474,
"loc": {
"start": {
"line": 23,
"column": 4
},
"end": {
"line": 23,
"column": 8
}
}
},
"property": {
"type": "Identifier",
"start": 475,
"end": 480,
"loc": {
"start": {
"line": 23,
"column": 9
},
"end": {
"line": 23,
"column": 14
},
"identifierName": "index"
},
"name": "index"
},
"computed": false
},
"right": {
"type": "NumericLiteral",
"start": 483,
"end": 484,
"loc": {
"start": {
"line": 23,
"column": 17
},
"end": {
"line": 23,
"column": 18
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
}
},
{
"type": "ExpressionStatement",
"start": 490,
"end": 507,
"loc": {
"start": {
"line": 24,
"column": 4
},
"end": {
"line": 24,
"column": 21
}
},
"expression": {
"type": "AssignmentExpression",
"start": 490,
"end": 506,
"loc": {
"start": {
"line": 24,
"column": 4
},
"end": {
"line": 24,
"column": 20
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 490,
"end": 501,
"loc": {
"start": {
"line": 24,
"column": 4
},
"end": {
"line": 24,
"column": 15
}
},
"object": {
"type": "ThisExpression",
"start": 490,
"end": 494,
"loc": {
"start": {
"line": 24,
"column": 4
},
"end": {
"line": 24,
"column": 8
}
}
},
"property": {
"type": "Identifier",
"start": 495,
"end": 501,
"loc": {
"start": {
"line": 24,
"column": 9
},
"end": {
"line": 24,
"column": 15
},
"identifierName": "tokens"
},
"name": "tokens"
},
"computed": false
},
"right": {
"type": "ArrayExpression",
"start": 504,
"end": 506,
"loc": {
"start": {
"line": 24,
"column": 18
},
"end": {
"line": 24,
"column": 20
}
},
"elements": []
}
}
},
{
"type": "ExpressionStatement",
"start": 512,
"end": 534,
"loc": {
"start": {
"line": 25,
"column": 4
},
"end": {
"line": 25,
"column": 26
}
},
"expression": {
"type": "AssignmentExpression",
"start": 512,
"end": 533,
"loc": {
"start": {
"line": 25,
"column": 4
},
"end": {
"line": 25,
"column": 25
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 512,
"end": 526,
"loc": {
"start": {
"line": 25,
"column": 4
},
"end": {
"line": 25,
"column": 18
}
},
"object": {
"type": "ThisExpression",
"start": 512,
"end": 516,
"loc": {
"start": {
"line": 25,
"column": 4
},
"end": {
"line": 25,
"column": 8
}
}
},
"property": {
"type": "Identifier",
"start": 517,
"end": 526,
"loc": {
"start": {
"line": 25,
"column": 9
},
"end": {
"line": 25,
"column": 18
},
"identifierName": "lookahead"
},
"name": "lookahead"
},
"computed": false
},
"right": {
"type": "NullLiteral",
"start": 529,
"end": 533,
"loc": {
"start": {
"line": 25,
"column": 21
},
"end": {
"line": 25,
"column": 25
}
}
}
}
},
{
"type": "ReturnStatement",
"start": 540,
"end": 552,
"loc": {
"start": {
"line": 27,
"column": 4
},
"end": {
"line": 27,
"column": 16
}
},
"argument": {
"type": "ThisExpression",
"start": 547,
"end": 551,
"loc": {
"start": {
"line": 27,
"column": 11
},
"end": {
"line": 27,
"column": 15
}
}
}
}
],
"directives": []
}
},
{
"type": "ClassMethod",
"start": 560,
"end": 1004,
"loc": {
"start": {
"line": 30,
"column": 2
},
"end": {
"line": 49,
"column": 3
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 560,
"end": 565,
"loc": {
"start": {
"line": 30,
"column": 2
},
"end": {
"line": 30,
"column": 7
},
"identifierName": "parse"
},
"name": "parse"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 566,
"end": 573,
"loc": {
"start": {
"line": 30,
"column": 8
},
"end": {
"line": 30,
"column": 15
},
"identifierName": "program"
},
"name": "program"
}
],
"body": {
"type": "BlockStatement",
"start": 575,
"end": 1004,
"loc": {
"start": {
"line": 30,
"column": 17
},
"end": {
"line": 49,
"column": 3
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 581,
"end": 606,
"loc": {
"start": {
"line": 31,
"column": 4
},
"end": {
"line": 31,
"column": 29
}
},
"expression": {
"type": "CallExpression",
"start": 581,
"end": 605,
"loc": {
"start": {
"line": 31,
"column": 4
},
"end": {
"line": 31,
"column": 28
}
},
"callee": {
"type": "MemberExpression",
"start": 581,
"end": 596,
"loc": {
"start": {
"line": 31,
"column": 4
},
"end": {
"line": 31,
"column": 19
}
},
"object": {
"type": "ThisExpression",
"start": 581,
"end": 585,
"loc": {
"start": {
"line": 31,
"column": 4
},
"end": {
"line": 31,
"column": 8
}
}
},
"property": {
"type": "Identifier",
"start": 586,
"end": 596,
"loc": {
"start": {
"line": 31,
"column": 9
},
"end": {
"line": 31,
"column": 19
},
"identifierName": "setProgram"
},
"name": "setProgram"
},
"computed": false
},
"arguments": [
{
"type": "Identifier",
"start": 597,
"end": 604,
"loc": {
"start": {
"line": 31,
"column": 20
},
"end": {
"line": 31,
"column": 27
},
"identifierName": "program"
},
"name": "program"
}
]
},
"trailingComments": [
{
"type": "CommentLine",
"value": " Get array of tokens",
"start": 612,
"end": 634,
"loc": {
"start": {
"line": 33,
"column": 4
},
"end": {
"line": 33,
"column": 26
}
}
}
]
},
{
"type": "ExpressionStatement",
"start": 639,
"end": 677,
"loc": {
"start": {
"line": 34,
"column": 4
},
"end": {
"line": 34,
"column": 42
}
},
"expression": {
"type": "AssignmentExpression",
"start": 639,
"end": 676,
"loc": {
"start": {
"line": 34,
"column": 4
},
"end": {
"line": 34,
"column": 41
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 639,
"end": 650,
"loc": {
"start": {
"line": 34,
"column": 4
},
"end": {
"line": 34,
"column": 15
}
},
"object": {
"type": "ThisExpression",
"start": 639,
"end": 643,
"loc": {
"start": {
"line": 34,
"column": 4
},
"end": {
"line": 34,
"column": 8
}
},
"leadingComments": null
},
"property": {
"type": "Identifier",
"start": 644,
"end": 650,
"loc": {
"start": {
"line": 34,
"column": 9
},
"end": {
"line": 34,
"column": 15
},
"identifierName": "tokens"
},
"name": "tokens"
},
"computed": false,
"leadingComments": null
},
"right": {
"type": "CallExpression",
"start": 653,
"end": 676,
"loc": {
"start": {
"line": 34,
"column": 18
},
"end": {
"line": 3