eggtended-js
Version:
A extended version of the Egg programming language from the Eloquent Javascript book.
1,552 lines • 1.16 MB
JSON
{
"type": "File",
"start": 0,
"end": 3507,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 165,
"column": 0
}
},
"program": {
"type": "Program",
"start": 0,
"end": 3507,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 165,
"column": 0
}
},
"sourceType": "module",
"body": [
{
"type": "ImportDeclaration",
"start": 0,
"end": 41,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 41
}
},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"start": 7,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 17
}
},
"local": {
"type": "Identifier",
"start": 7,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 17
},
"identifierName": "tokenRegex"
},
"name": "tokenRegex"
}
}
],
"source": {
"type": "StringLiteral",
"start": 23,
"end": 40,
"loc": {
"start": {
"line": 1,
"column": 23
},
"end": {
"line": 1,
"column": 40
}
},
"extra": {
"rawValue": "./tokenRegex.js",
"raw": "\"./tokenRegex.js\""
},
"value": "./tokenRegex.js"
}
},
{
"type": "ImportDeclaration",
"start": 42,
"end": 62,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 20
}
},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"start": 49,
"end": 51,
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 9
}
},
"local": {
"type": "Identifier",
"start": 49,
"end": 51,
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 9
},
"identifierName": "fs"
},
"name": "fs"
}
}
],
"source": {
"type": "StringLiteral",
"start": 57,
"end": 61,
"loc": {
"start": {
"line": 2,
"column": 15
},
"end": {
"line": 2,
"column": 19
}
},
"extra": {
"rawValue": "fs",
"raw": "\"fs\""
},
"value": "fs"
}
},
{
"type": "Identifier",
"start": 64,
"end": 3261,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 149,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 70,
"end": 75,
"loc": {
"start": {
"line": 4,
"column": 6
},
"end": {
"line": 4,
"column": 11
},
"identifierName": "Lexer"
},
"name": "Lexer"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 76,
"end": 3261,
"loc": {
"start": {
"line": 4,
"column": 12
},
"end": {
"line": 149,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 80,
"end": 142,
"loc": {
"start": {
"line": 5,
"column": 2
},
"end": {
"line": 8,
"column": 3
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 80,
"end": 91,
"loc": {
"start": {
"line": 5,
"column": 2
},
"end": {
"line": 5,
"column": 13
},
"identifierName": "constructor"
},
"name": "constructor"
},
"kind": "constructor",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 94,
"end": 142,
"loc": {
"start": {
"line": 5,
"column": 16
},
"end": {
"line": 8,
"column": 3
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 100,
"end": 119,
"loc": {
"start": {
"line": 6,
"column": 4
},
"end": {
"line": 6,
"column": 23
}
},
"expression": {
"type": "AssignmentExpression",
"start": 100,
"end": 118,
"loc": {
"start": {
"line": 6,
"column": 4
},
"end": {
"line": 6,
"column": 22
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 100,
"end": 114,
"loc": {
"start": {
"line": 6,
"column": 4
},
"end": {
"line": 6,
"column": 18
}
},
"object": {
"type": "ThisExpression",
"start": 100,
"end": 104,
"loc": {
"start": {
"line": 6,
"column": 4
},
"end": {
"line": 6,
"column": 8
}
}
},
"property": {
"type": "Identifier",
"start": 105,
"end": 114,
"loc": {
"start": {
"line": 6,
"column": 9
},
"end": {
"line": 6,
"column": 18
},
"identifierName": "lastIndex"
},
"name": "lastIndex"
},
"computed": false
},
"right": {
"type": "NumericLiteral",
"start": 117,
"end": 118,
"loc": {
"start": {
"line": 6,
"column": 21
},
"end": {
"line": 6,
"column": 22
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
}
},
{
"type": "ExpressionStatement",
"start": 124,
"end": 138,
"loc": {
"start": {
"line": 7,
"column": 4
},
"end": {
"line": 7,
"column": 18
}
},
"expression": {
"type": "AssignmentExpression",
"start": 124,
"end": 137,
"loc": {
"start": {
"line": 7,
"column": 4
},
"end": {
"line": 7,
"column": 17
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 124,
"end": 133,
"loc": {
"start": {
"line": 7,
"column": 4
},
"end": {
"line": 7,
"column": 13
}
},
"object": {
"type": "ThisExpression",
"start": 124,
"end": 128,
"loc": {
"start": {
"line": 7,
"column": 4
},
"end": {
"line": 7,
"column": 8
}
}
},
"property": {
"type": "Identifier",
"start": 129,
"end": 133,
"loc": {
"start": {
"line": 7,
"column": 9
},
"end": {
"line": 7,
"column": 13
},
"identifierName": "line"
},
"name": "line"
},
"computed": false
},
"right": {
"type": "NumericLiteral",
"start": 136,
"end": 137,
"loc": {
"start": {
"line": 7,
"column": 16
},
"end": {
"line": 7,
"column": 17
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
}
}
}
],
"directives": []
}
},
{
"type": "ClassMethod",
"start": 146,
"end": 261,
"loc": {
"start": {
"line": 10,
"column": 2
},
"end": {
"line": 17,
"column": 3
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 146,
"end": 156,
"loc": {
"start": {
"line": 10,
"column": 2
},
"end": {
"line": 10,
"column": 12
},
"identifierName": "setProgram"
},
"name": "setProgram"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 157,
"end": 164,
"loc": {
"start": {
"line": 10,
"column": 13
},
"end": {
"line": 10,
"column": 20
},
"identifierName": "program"
},
"name": "program"
}
],
"body": {
"type": "BlockStatement",
"start": 166,
"end": 261,
"loc": {
"start": {
"line": 10,
"column": 22
},
"end": {
"line": 17,
"column": 3
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 172,
"end": 195,
"loc": {
"start": {
"line": 11,
"column": 4
},
"end": {
"line": 11,
"column": 27
}
},
"expression": {
"type": "AssignmentExpression",
"start": 172,
"end": 194,
"loc": {
"start": {
"line": 11,
"column": 4
},
"end": {
"line": 11,
"column": 26
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 172,
"end": 184,
"loc": {
"start": {
"line": 11,
"column": 4
},
"end": {
"line": 11,
"column": 16
}
},
"object": {
"type": "ThisExpression",
"start": 172,
"end": 176,
"loc": {
"start": {
"line": 11,
"column": 4
},
"end": {
"line": 11,
"column": 8
}
}
},
"property": {
"type": "Identifier",
"start": 177,
"end": 184,
"loc": {
"start": {
"line": 11,
"column": 9
},
"end": {
"line": 11,
"column": 16
},
"identifierName": "program"
},
"name": "program"
},
"computed": false
},
"right": {
"type": "Identifier",
"start": 187,
"end": 194,
"loc": {
"start": {
"line": 11,
"column": 19
},
"end": {
"line": 11,
"column": 26
},
"identifierName": "program"
},
"name": "program"
}
}
},
{
"type": "ExpressionStatement",
"start": 201,
"end": 220,
"loc": {
"start": {
"line": 13,
"column": 4
},
"end": {
"line": 13,
"column": 23
}
},
"expression": {
"type": "AssignmentExpression",
"start": 201,
"end": 219,
"loc": {
"start": {
"line": 13,
"column": 4
},
"end": {
"line": 13,
"column": 22
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 201,
"end": 215,
"loc": {
"start": {
"line": 13,
"column": 4
},
"end": {
"line": 13,
"column": 18
}
},
"object": {
"type": "ThisExpression",
"start": 201,
"end": 205,
"loc": {
"start": {
"line": 13,
"column": 4
},
"end": {
"line": 13,
"column": 8
}
}
},
"property": {
"type": "Identifier",
"start": 206,
"end": 215,
"loc": {
"start": {
"line": 13,
"column": 9
},
"end": {
"line": 13,
"column": 18
},
"identifierName": "lastIndex"
},
"name": "lastIndex"
},
"computed": false
},
"right": {
"type": "NumericLiteral",
"start": 218,
"end": 219,
"loc": {
"start": {
"line": 13,
"column": 21
},
"end": {
"line": 13,
"column": 22
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
}
},
{
"type": "ExpressionStatement",
"start": 225,
"end": 239,
"loc": {
"start": {
"line": 14,
"column": 4
},
"end": {
"line": 14,
"column": 18
}
},
"expression": {
"type": "AssignmentExpression",
"start": 225,
"end": 238,
"loc": {
"start": {
"line": 14,
"column": 4
},
"end": {
"line": 14,
"column": 17
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 225,
"end": 234,
"loc": {
"start": {
"line": 14,
"column": 4
},
"end": {
"line": 14,
"column": 13
}
},
"object": {
"type": "ThisExpression",
"start": 225,
"end": 229,
"loc": {
"start": {
"line": 14,
"column": 4
},
"end": {
"line": 14,
"column": 8
}
}
},
"property": {
"type": "Identifier",
"start": 230,
"end": 234,
"loc": {
"start": {
"line": 14,
"column": 9
},
"end": {
"line": 14,
"column": 13
},
"identifierName": "line"
},
"name": "line"
},
"computed": false
},
"right": {
"type": "NumericLiteral",
"start": 237,
"end": 238,
"loc": {
"start": {
"line": 14,
"column": 16
},
"end": {
"line": 14,
"column": 17
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
}
}
},
{
"type": "ReturnStatement",
"start": 245,
"end": 257,
"loc": {
"start": {
"line": 16,
"column": 4
},
"end": {
"line": 16,
"column": 16
}
},
"argument": {
"type": "ThisExpression",
"start": 252,
"end": 256,
"loc": {
"start": {
"line": 16,
"column": 11
},
"end": {
"line": 16,
"column": 15
}
}
}
}
],
"directives": []
}
},
{
"type": "ClassMethod",
"start": 265,
"end": 349,
"loc": {
"start": {
"line": 19,
"column": 2
},
"end": {
"line": 23,
"column": 3
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 265,
"end": 273,
"loc": {
"start": {
"line": 19,
"column": 2
},
"end": {
"line": 19,
"column": 10
},
"identifierName": "tokenize"
},
"name": "tokenize"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 274,
"end": 281,
"loc": {
"start": {
"line": 19,
"column": 11
},
"end": {
"line": 19,
"column": 18
},
"identifierName": "program"
},
"name": "program"
}
],
"body": {
"type": "BlockStatement",
"start": 283,
"end": 349,
"loc": {
"start": {
"line": 19,
"column": 20
},
"end": {
"line": 23,
"column": 3
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 289,
"end": 314,
"loc": {
"start": {
"line": 20,
"column": 4
},
"end": {
"line": 20,
"column": 29
}
},
"expression": {
"type": "CallExpression",
"start": 289,
"end": 313,
"loc": {
"start": {
"line": 20,
"column": 4
},
"end": {
"line": 20,
"column": 28
}
},
"callee": {
"type": "MemberExpression",
"start": 289,
"end": 304,
"loc": {
"start": {
"line": 20,
"column": 4
},
"end": {
"line": 20,
"column": 19
}
},
"object": {
"type": "ThisExpression",
"start": 289,
"end": 293,
"loc": {
"start": {
"line": 20,
"column": 4
},
"end": {
"line": 20,
"column": 8
}
}
},
"property": {
"type": "Identifier",
"start": 294,
"end": 304,
"loc": {
"start": {
"line": 20,
"column": 9
},
"end": {
"line": 20,
"column": 19
},
"identifierName": "setProgram"
},
"name": "setProgram"
},
"computed": false
},
"arguments": [
{
"type": "Identifier",
"start": 305,
"end": 312,
"loc": {
"start": {
"line": 20,
"column": 20
},
"end": {
"line": 20,
"column": 27
},
"identifierName": "program"
},
"name": "program"
}
]
}
},
{
"type": "ReturnStatement",
"start": 320,
"end": 345,
"loc": {
"start": {
"line": 22,
"column": 4
},
"end": {
"line": 22,
"column": 29
}
},
"argument": {
"type": "CallExpression",
"start": 327,
"end": 344,
"loc": {
"start": {
"line": 22,
"column": 11
},
"end": {
"line": 22,
"column": 28
}
},
"callee": {
"type": "MemberExpression",
"start": 327,
"end": 342,
"loc": {
"start": {
"line": 22,
"column": 11
},
"end": {
"line": 22,
"column": 26
}
},
"object": {
"type": "ThisExpression",
"start": 327,
"end": 331,
"loc": {
"start": {
"line": 22,
"column": 11
},
"end": {
"line": 22,
"column": 15
}
}
},
"property": {
"type": "Identifier",
"start": 332,
"end": 342,
"loc": {
"start": {
"line": 22,
"column": 16
},
"end": {
"line": 22,
"column": 26
},
"identifierName": "_getTokens"
},
"name": "_getTokens"
},
"computed": false
},
"arguments": []
}
}
],
"directives": []
}
},
{
"type": "ClassMethod",
"start": 353,
"end": 425,
"loc": {
"start": {
"line": 25,
"column": 2
},
"end": {
"line": 27,
"column": 3
}
},
"static": true,
"computed": false,
"key": {
"type": "Identifier",
"start": 360,
"end": 368,
"loc": {
"start": {
"line": 25,
"column": 9
},
"end": {
"line": 25,
"column": 17
},
"identifierName": "tokenize"
},
"name": "tokenize"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 369,
"end": 376,
"loc": {
"start": {
"line": 25,
"column": 18
},
"end": {
"line": 25,
"column": 25
},
"identifierName": "program"
},
"name": "program"
}
],
"body": {
"type": "BlockStatement",
"start": 378,
"end": 425,
"loc": {
"start": {
"line": 25,
"column": 27
},
"end": {
"line": 27,
"column": 3
}
},
"body": [
{
"type": "ReturnStatement",
"start": 384,
"end": 421,
"loc": {
"start": {
"line": 26,
"column": 4
},
"end": {
"line": 26,
"column": 41
}
},
"argument": {
"type": "CallExpression",
"start": 391,
"end": 420,
"loc": {
"start": {
"line": 26,
"column": 11
},
"end": {
"line": 26,
"column": 40
}
},
"callee": {
"type": "MemberExpression",
"start": 391,
"end": 411,
"loc": {
"start": {
"line": 26,
"column": 11
},
"end": {
"line": 26,
"column": 31
}
},
"object": {
"type": "NewExpression",
"start": 391,
"end": 402,
"loc": {
"start": {
"line": 26,
"column": 11
},
"end": {
"line": 26,
"column": 22
}
},
"callee": {
"type": "Identifier",
"start": 395,
"end": 400,
"loc": {
"start": {
"line": 26,
"column": 15
},
"end": {
"line": 26,
"column": 20
},
"identifierName": "Lexer"
},
"name": "Lexer"
},
"arguments": []
},
"property": {
"type": "Identifier",
"start": 403,
"end": 411,
"loc": {
"start": {
"line": 26,
"column": 23
},
"end": {
"line": 26,
"column": 31
},
"identifierName": "tokenize"
},
"name": "tokenize"
},
"computed": false
},
"arguments": [
{
"type": "Identifier",
"start": 412,
"end": 419,
"loc": {
"start": {
"line": 26,
"column": 32
},
"end": {
"line": 26,
"column": 39
},
"identifierName": "program"
},
"name": "program"
}
]
}
}
],
"directives": []
}
},
{
"type": "ClassMethod",
"start": 429,
"end": 545,
"loc": {
"start": {
"line": 29,
"column": 2
},
"end": {
"line": 33,
"column": 3
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 429,
"end": 445,
"loc": {
"start": {
"line": 29,
"column": 2
},
"end": {
"line": 29,
"column": 18
},
"identifierName": "tokenizeFromFile"
},
"name": "tokenizeFromFile"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 446,
"end": 450,
"loc": {
"start": {
"line": 29,
"column": 19
},
"end": {
"line": 29,
"column": 23
},
"identifierName": "file"
},
"name": "file"
}
],
"body": {
"type": "BlockStatement",
"start": 452,
"end": 545,
"loc": {
"start": {
"line": 29,
"column": 25
},
"end": {
"line": 33,
"column": 3
}
},
"body": [
{
"type": "VariableDeclaration",
"start": 458,
"end": 505,
"loc": {
"start": {
"line": 30,
"column": 4
},
"end": {
"line": 30,
"column": 51
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 464,
"end": 504,
"loc": {
"start": {
"line": 30,
"column": 10
},
"end": {
"line": 30,
"column": 50
}
},
"id": {
"type": "Identifier",
"start": 464,
"end": 471,
"loc": {
"start": {
"line": 30,
"column": 10
},
"end": {
"line": 30,
"column": 17
},
"identifierName": "program"
},
"name": "program"
},
"init": {
"type": "CallExpression",
"start": 474,
"end": 504,
"loc": {
"start": {
"line": 30,
"column": 20
},
"end": {
"line": 30,
"column": 50
}
},
"callee": {
"type": "MemberExpression",
"start": 474,
"end": 489,
"loc": {
"start": {
"line": 30,
"column": 20
},
"end": {
"line": 30,
"column": 35
}
},
"object": {
"type": "Identifier",
"start": 474,
"end": 476,
"loc": {
"start": {
"line": 30,
"column": 20
},
"end": {
"line": 30,
"column": 22
},
"identifierName": "fs"
},
"name": "fs"
},
"property": {
"type": "Identifier",
"start": 477,
"end": 489,
"loc": {
"start": {
"line": 30,
"column": 23
},
"end": {
"line": 30,
"column": 35
},
"identifierName": "readFileSync"
},
"name": "readFileSync"
},
"computed": false
},
"arguments": [
{
"type": "Identifier",
"start": 490,
"end": 494,
"loc": {
"start": {
"line": 30,
"column": 36
},
"end": {
"line": 30,
"column": 40
},
"identifierName": "file"
},
"name": "file"
},
{
"type": "StringLiteral",
"start": 496,
"end": 503,
"loc": {
"start": {
"line": 30,
"column": 42
},
"end": {
"line": 30,
"column": 49
}
},
"extra": {
"rawValue": "utf-8",
"raw": "\"utf-8\""
},
"value": "utf-8"
}
]
}
}
],
"kind": "const"
},
{
"type": "ReturnStatement",
"start": 511,
"end": 541,
"loc": {
"start": {
"line": 32,
"column": 4
},
"end": {
"line": 32,
"