@scinorandex/sparse 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +132 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +47 -0
- package/dist/cli.js.map +1 -0
- package/dist/generator.d.ts +28 -0
- package/dist/generator.js +290 -0
- package/dist/generator.js.map +1 -0
- package/dist/grammarParser.d.ts +27 -0
- package/dist/grammarParser.js +73 -0
- package/dist/grammarParser.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/parser.d.ts +102 -0
- package/dist/parser.js +125 -0
- package/dist/parser.js.map +1 -0
- package/dist/tableParser.d.ts +16 -0
- package/dist/tableParser.js +59 -0
- package/dist/tableParser.js.map +1 -0
- package/dist/utils/Result.d.ts +9 -0
- package/dist/utils/Result.js +3 -0
- package/dist/utils/Result.js.map +1 -0
- package/dist/utils/Stack.d.ts +7 -0
- package/dist/utils/Stack.js +26 -0
- package/dist/utils/Stack.js.map +1 -0
- package/dist/utils/errorWindowBuilder.d.ts +2 -0
- package/dist/utils/errorWindowBuilder.js +20 -0
- package/dist/utils/errorWindowBuilder.js.map +1 -0
- package/example/LoLang/Features_Array_Methods.lol +31 -0
- package/example/LoLang/example.ts +214 -0
- package/example/LoLang/grammar.txt +149 -0
- package/example/LoLang/table.txt +497 -0
- package/example/math/example.ts +49 -0
- package/example/math/grammar.txt +11 -0
- package/example/math/table.txt +22 -0
- package/package.json +36 -0
- package/src/cli.ts +49 -0
- package/src/generator.ts +394 -0
- package/src/grammarParser.ts +97 -0
- package/src/index.ts +12 -0
- package/src/parser.ts +207 -0
- package/src/tableParser.ts +69 -0
- package/src/utils/Result.ts +3 -0
- package/src/utils/Stack.ts +23 -0
- package/src/utils/errorWindowBuilder.ts +23 -0
- package/tsconfig.json +30 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildStates = exports.LR1ParserGraveError = exports.Sparse = exports.tryBuildProductions = exports.buildProductions = exports.generateStates = exports.GeneratorResult = void 0;
|
|
4
|
+
var generator_1 = require("./generator");
|
|
5
|
+
Object.defineProperty(exports, "GeneratorResult", { enumerable: true, get: function () { return generator_1.GeneratorResult; } });
|
|
6
|
+
Object.defineProperty(exports, "generateStates", { enumerable: true, get: function () { return generator_1.generateStates; } });
|
|
7
|
+
var grammarParser_1 = require("./grammarParser");
|
|
8
|
+
Object.defineProperty(exports, "buildProductions", { enumerable: true, get: function () { return grammarParser_1.buildProductions; } });
|
|
9
|
+
Object.defineProperty(exports, "tryBuildProductions", { enumerable: true, get: function () { return grammarParser_1.tryBuildProductions; } });
|
|
10
|
+
var parser_1 = require("./parser");
|
|
11
|
+
Object.defineProperty(exports, "Sparse", { enumerable: true, get: function () { return parser_1.Sparse; } });
|
|
12
|
+
Object.defineProperty(exports, "LR1ParserGraveError", { enumerable: true, get: function () { return parser_1.LR1ParserGraveError; } });
|
|
13
|
+
var tableParser_1 = require("./tableParser");
|
|
14
|
+
Object.defineProperty(exports, "buildStates", { enumerable: true, get: function () { return tableParser_1.buildStates; } });
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAA8D;AAArD,4GAAA,eAAe,OAAA;AAAE,2GAAA,cAAc,OAAA;AACxC,iDAAoF;AAA/D,iHAAA,gBAAgB,OAAA;AAAE,oHAAA,mBAAmB,OAAA;AAE1D,mCAOkB;AALhB,gGAAA,MAAM,OAAA;AACN,6GAAA,mBAAmB,OAAA;AAKrB,6CAA4C;AAAnC,0GAAA,WAAW,OAAA"}
|
package/dist/parser.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Slex, Token } from "@scinorandex/slex";
|
|
2
|
+
import { Production } from "./grammarParser";
|
|
3
|
+
import { Stack } from "./utils/Stack";
|
|
4
|
+
import { Result } from "./utils/Result";
|
|
5
|
+
export type TableAction = {
|
|
6
|
+
type: "shift" | "reduce" | "goto";
|
|
7
|
+
value: number;
|
|
8
|
+
};
|
|
9
|
+
export declare class TableState {
|
|
10
|
+
readonly actions: Map<string, TableAction>;
|
|
11
|
+
constructor();
|
|
12
|
+
getTerminalAction(terminal: string): TableAction | undefined;
|
|
13
|
+
getVariableAction(variable: string): TableAction | undefined;
|
|
14
|
+
}
|
|
15
|
+
export type LR1StackSymbol<TokenType, Metadata, Node> = {
|
|
16
|
+
type: "token";
|
|
17
|
+
token: Token<TokenType, Metadata>;
|
|
18
|
+
} | {
|
|
19
|
+
type: "node";
|
|
20
|
+
node: Node;
|
|
21
|
+
};
|
|
22
|
+
export declare class Sparse<TokenType, Metadata, Node> {
|
|
23
|
+
readonly options: {
|
|
24
|
+
productions: Production[];
|
|
25
|
+
states: TableState[];
|
|
26
|
+
toStringifiedTokenType: (tokenType: TokenType) => string;
|
|
27
|
+
};
|
|
28
|
+
constructor(options: {
|
|
29
|
+
productions: Production[];
|
|
30
|
+
states: TableState[];
|
|
31
|
+
toStringifiedTokenType: (tokenType: TokenType) => string;
|
|
32
|
+
});
|
|
33
|
+
static tryFromProductions<TokenType, Metadata, Node>(options: {
|
|
34
|
+
productions: Production[];
|
|
35
|
+
toStringifiedTokenType: (tokenType: TokenType) => string;
|
|
36
|
+
}): Result<Sparse<TokenType, Metadata, Node>>;
|
|
37
|
+
static fromProductions<TokenType, Metadata, Node>(options: {
|
|
38
|
+
productions: Production[];
|
|
39
|
+
toStringifiedTokenType: (tokenType: TokenType) => string;
|
|
40
|
+
}): Sparse<TokenType, Metadata, Node>;
|
|
41
|
+
generate(lexer: ReturnType<Slex<TokenType, Metadata>["generate"]>, options: {
|
|
42
|
+
reducer: (input: LR1StackSymbol<TokenType, Metadata, Node>[], productionIndex: number) => Node;
|
|
43
|
+
recover?: ParserRecoveryFunction<TokenType, Metadata, Node>;
|
|
44
|
+
}): LR1Parser<TokenType, Metadata, Node>;
|
|
45
|
+
}
|
|
46
|
+
export type ParserRecoveryFunction<TokenType, Metadata, Node> = (options: {
|
|
47
|
+
lexer: ReturnType<Slex<TokenType, Metadata>["generate"]>;
|
|
48
|
+
statesStack: Stack<number>;
|
|
49
|
+
symbolsStack: Stack<LR1StackSymbol<TokenType, Metadata, Node>>;
|
|
50
|
+
isSafe: () => boolean;
|
|
51
|
+
addError: (reason: string) => void;
|
|
52
|
+
crash: (reason: string) => {
|
|
53
|
+
success: false;
|
|
54
|
+
reason: string;
|
|
55
|
+
};
|
|
56
|
+
finish: (options?: {
|
|
57
|
+
newToken: Token<TokenType, Metadata>;
|
|
58
|
+
}) => {
|
|
59
|
+
success: true;
|
|
60
|
+
token?: Token<TokenType, Metadata>;
|
|
61
|
+
};
|
|
62
|
+
states: TableState[];
|
|
63
|
+
}) => {
|
|
64
|
+
success: true;
|
|
65
|
+
token?: Token<TokenType, Metadata>;
|
|
66
|
+
} | {
|
|
67
|
+
success: false;
|
|
68
|
+
reason: string;
|
|
69
|
+
};
|
|
70
|
+
export type ParserError<TokenType, Metadata> = {
|
|
71
|
+
token: Token<TokenType, Metadata>;
|
|
72
|
+
message: string;
|
|
73
|
+
};
|
|
74
|
+
export type ParserResult<TokenType, Metadata, Node> = {
|
|
75
|
+
result: Node | null;
|
|
76
|
+
errors: ParserError<TokenType, Metadata>[];
|
|
77
|
+
};
|
|
78
|
+
declare class LR1Parser<TokenType, Metadata, Node> {
|
|
79
|
+
readonly options: {
|
|
80
|
+
productions: Production[];
|
|
81
|
+
states: TableState[];
|
|
82
|
+
toStringifiedTokenType: (tokenType: TokenType) => string;
|
|
83
|
+
};
|
|
84
|
+
readonly reducer: (input: LR1StackSymbol<TokenType, Metadata, Node>[], productionIndex: number) => Node;
|
|
85
|
+
readonly recover: ParserRecoveryFunction<TokenType, Metadata, Node> | null;
|
|
86
|
+
readonly lexer: ReturnType<Slex<TokenType, Metadata>["generate"]>;
|
|
87
|
+
statesStack: Stack<number>;
|
|
88
|
+
symbolsStack: Stack<LR1StackSymbol<TokenType, Metadata, Node>>;
|
|
89
|
+
exceptions: ParserError<TokenType, Metadata>[];
|
|
90
|
+
constructor(options: {
|
|
91
|
+
productions: Production[];
|
|
92
|
+
states: TableState[];
|
|
93
|
+
toStringifiedTokenType: (tokenType: TokenType) => string;
|
|
94
|
+
}, reducer: (input: LR1StackSymbol<TokenType, Metadata, Node>[], productionIndex: number) => Node, recover: ParserRecoveryFunction<TokenType, Metadata, Node> | null, lexer: ReturnType<Slex<TokenType, Metadata>["generate"]>);
|
|
95
|
+
parse(): ParserResult<TokenType, Metadata, Node>;
|
|
96
|
+
}
|
|
97
|
+
export declare class LR1ParserGraveError<TokenType, Metadata> extends Error {
|
|
98
|
+
readonly reason: string;
|
|
99
|
+
readonly currentToken: Token<TokenType, Metadata>;
|
|
100
|
+
constructor(reason: string, currentToken: Token<TokenType, Metadata>, err?: Error);
|
|
101
|
+
}
|
|
102
|
+
export {};
|
package/dist/parser.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LR1ParserGraveError = exports.Sparse = exports.TableState = void 0;
|
|
4
|
+
const generator_1 = require("./generator");
|
|
5
|
+
const Stack_1 = require("./utils/Stack");
|
|
6
|
+
class TableState {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.actions = new Map();
|
|
9
|
+
}
|
|
10
|
+
getTerminalAction(terminal) {
|
|
11
|
+
return this.actions.get(`[${terminal}]`);
|
|
12
|
+
}
|
|
13
|
+
getVariableAction(variable) {
|
|
14
|
+
return this.actions.get(variable);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.TableState = TableState;
|
|
18
|
+
class Sparse {
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.options = options;
|
|
21
|
+
}
|
|
22
|
+
static tryFromProductions(options) {
|
|
23
|
+
const statesResult = (0, generator_1.generateStates)(options.productions);
|
|
24
|
+
if (statesResult.success === false)
|
|
25
|
+
return statesResult;
|
|
26
|
+
const states = statesResult.value;
|
|
27
|
+
const sparse = new Sparse({
|
|
28
|
+
productions: options.productions,
|
|
29
|
+
states: states.toStates(),
|
|
30
|
+
toStringifiedTokenType: options.toStringifiedTokenType,
|
|
31
|
+
});
|
|
32
|
+
return { success: true, value: sparse };
|
|
33
|
+
}
|
|
34
|
+
static fromProductions(options) {
|
|
35
|
+
const result = Sparse.tryFromProductions(options);
|
|
36
|
+
if (result.success === false)
|
|
37
|
+
throw new Error(`Encountered error "${result.reason}" at ${result.token.line}:${result.token.column}`);
|
|
38
|
+
return result.value;
|
|
39
|
+
}
|
|
40
|
+
generate(lexer, options) {
|
|
41
|
+
var _a;
|
|
42
|
+
return new LR1Parser(this.options, options.reducer, (_a = options.recover) !== null && _a !== void 0 ? _a : null, lexer);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.Sparse = Sparse;
|
|
46
|
+
class LR1Parser {
|
|
47
|
+
constructor(options, reducer, recover, lexer) {
|
|
48
|
+
this.options = options;
|
|
49
|
+
this.reducer = reducer;
|
|
50
|
+
this.recover = recover;
|
|
51
|
+
this.lexer = lexer;
|
|
52
|
+
this.statesStack = new Stack_1.Stack([0]);
|
|
53
|
+
this.symbolsStack = new Stack_1.Stack();
|
|
54
|
+
this.exceptions = [];
|
|
55
|
+
}
|
|
56
|
+
parse() {
|
|
57
|
+
var _a;
|
|
58
|
+
const { productions, states, toStringifiedTokenType } = this.options;
|
|
59
|
+
while (true) {
|
|
60
|
+
let currentState = this.statesStack.peek();
|
|
61
|
+
let token = this.lexer.peekNextToken();
|
|
62
|
+
let action = states[currentState].getTerminalAction(toStringifiedTokenType(token.type));
|
|
63
|
+
if (action == null) {
|
|
64
|
+
if (this.recover === null)
|
|
65
|
+
throw new LR1ParserGraveError(`Invalid syntax. Expected ${[...states[currentState].actions.keys()].join(",")} but got ${toStringifiedTokenType(token.type)}`, token);
|
|
66
|
+
const recoveryResult = this.recover({
|
|
67
|
+
lexer: this.lexer,
|
|
68
|
+
states,
|
|
69
|
+
statesStack: this.statesStack,
|
|
70
|
+
symbolsStack: this.symbolsStack,
|
|
71
|
+
addError: (reason) => this.exceptions.push({ message: reason, token: this.lexer.peekNextToken() }),
|
|
72
|
+
crash: (reason) => ({ success: false, reason }),
|
|
73
|
+
finish: (options) => ({ success: true, token: options === null || options === void 0 ? void 0 : options.newToken }),
|
|
74
|
+
isSafe: () => states[this.statesStack.peek()].actions.has(`[${toStringifiedTokenType(this.lexer.peekNextToken().type)}]`),
|
|
75
|
+
});
|
|
76
|
+
if (recoveryResult.success === false)
|
|
77
|
+
throw new LR1ParserGraveError(recoveryResult.reason, token);
|
|
78
|
+
token = (_a = recoveryResult.token) !== null && _a !== void 0 ? _a : this.lexer.peekNextToken();
|
|
79
|
+
currentState = this.statesStack.peek();
|
|
80
|
+
action = states[currentState].getTerminalAction(toStringifiedTokenType(token.type));
|
|
81
|
+
}
|
|
82
|
+
const fixedAction = action;
|
|
83
|
+
if (fixedAction.type === "shift") {
|
|
84
|
+
token = this.lexer.getNextToken();
|
|
85
|
+
this.statesStack.push(fixedAction.value);
|
|
86
|
+
this.symbolsStack.push({ type: "token", token: token });
|
|
87
|
+
}
|
|
88
|
+
else if (fixedAction.type === "reduce") {
|
|
89
|
+
if (fixedAction.value === 0)
|
|
90
|
+
break;
|
|
91
|
+
const production = productions[fixedAction.value];
|
|
92
|
+
const popped = [];
|
|
93
|
+
for (let i = 0; i < production.rhs.length; i++) {
|
|
94
|
+
popped.unshift(this.symbolsStack.pop());
|
|
95
|
+
this.statesStack.pop();
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
this.symbolsStack.push({ type: "node", node: this.reducer(popped, fixedAction.value) });
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
const input = JSON.stringify(popped, null, 2);
|
|
102
|
+
throw new LR1ParserGraveError(`Error while performing reduction for production: ${fixedAction.value}. Reduction input: ${input}`, token);
|
|
103
|
+
}
|
|
104
|
+
const topNode = this.statesStack.peek();
|
|
105
|
+
const gotoAction = states[topNode].getVariableAction(production.lhs.lexeme);
|
|
106
|
+
if (gotoAction == undefined)
|
|
107
|
+
throw new LR1ParserGraveError(`No GOTO action for for state: ${topNode} and production: ${production.lhs}. Actions: Reduce by production ${fixedAction.value}`, token);
|
|
108
|
+
else if (gotoAction.type !== "goto")
|
|
109
|
+
throw new LR1ParserGraveError(`Expected GOTO action for state: ${topNode} and production: ${production.lhs}. Actions: Reduce by production ${fixedAction.value}. Received: ${gotoAction.type}`, token);
|
|
110
|
+
this.statesStack.push(gotoAction.value);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const top = this.symbolsStack.peek();
|
|
114
|
+
return { result: top.type === "node" ? top.node : null, errors: this.exceptions };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
class LR1ParserGraveError extends Error {
|
|
118
|
+
constructor(reason, currentToken, err) {
|
|
119
|
+
super(reason);
|
|
120
|
+
this.reason = reason;
|
|
121
|
+
this.currentToken = currentToken;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.LR1ParserGraveError = LR1ParserGraveError;
|
|
125
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":";;;AACA,2CAA6C;AAE7C,yCAAsC;AAKtC,MAAa,UAAU;IAGrB;QACE,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;IAC3B,CAAC;IAEM,iBAAiB,CAAC,QAAgB;QACvC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,QAAQ,GAAG,CAAC,CAAC;IAC3C,CAAC;IAEM,iBAAiB,CAAC,QAAgB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AU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;gBAE5E,IAAI,UAAU,IAAI,SAAS;oBACzB,MAAM,IAAI,mBAAmB,CAC3B,iCAAiC,OAAO,oBAAoB,UAAU,CAAC,GAAG,mCAAmC,WAAW,CAAC,KAAK,EAAE,EAChI,KAAK,CACN,CAAC;qBACC,IAAI,UAAU,CAAC,IAAI,KAAK,MAAM;oBACjC,MAAM,IAAI,mBAAmB,CAC3B,mCAAmC,OAAO,oBAAoB,UAAU,CAAC,GAAG,mCAAmC,WAAW,CAAC,KAAK,eAAe,UAAU,CAAC,IAAI,EAAE,EAChK,KAAK,CACN,CAAC;gBAEJ,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YAC1C,CAAC;QACH,CAAC;QAED,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;QACrC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC;IACpF,CAAC;CACF;AAED,MAAa,mBAAyC,SAAQ,KAAK;IACjE,YAA4B,MAAc,EAAkB,YAAwC,EAAE,GAAW;QAC/G,KAAK,CAAC,MAAM,CAAC,CAAC;QADY,WAAM,GAAN,MAAM,CAAQ;QAAkB,iBAAY,GAAZ,YAAY,CAA4B;IAEpG,CAAC;CACF;AAJD,kDAIC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Slex } from "@scinorandex/slex";
|
|
2
|
+
import { TableState } from "./parser";
|
|
3
|
+
type TableTokenMetadata = {};
|
|
4
|
+
export declare enum TableTokenType {
|
|
5
|
+
PRODUCTION_NAME = 0,
|
|
6
|
+
TOKEN_NAME = 1,
|
|
7
|
+
COMMA = 2,
|
|
8
|
+
EQUALS = 3,
|
|
9
|
+
SHIFT_ACTION = 4,
|
|
10
|
+
REDUCE_ACTION = 5,
|
|
11
|
+
GOTO_ACTION = 6,
|
|
12
|
+
EOF = 7
|
|
13
|
+
}
|
|
14
|
+
export declare const tableLexerGenerator: Slex<TableTokenType, TableTokenMetadata>;
|
|
15
|
+
export declare const buildStates: (grammar: string) => TableState[];
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildStates = exports.tableLexerGenerator = exports.TableTokenType = void 0;
|
|
4
|
+
const slex_1 = require("@scinorandex/slex");
|
|
5
|
+
const parser_1 = require("./parser");
|
|
6
|
+
var TableTokenType;
|
|
7
|
+
(function (TableTokenType) {
|
|
8
|
+
TableTokenType[TableTokenType["PRODUCTION_NAME"] = 0] = "PRODUCTION_NAME";
|
|
9
|
+
TableTokenType[TableTokenType["TOKEN_NAME"] = 1] = "TOKEN_NAME";
|
|
10
|
+
TableTokenType[TableTokenType["COMMA"] = 2] = "COMMA";
|
|
11
|
+
TableTokenType[TableTokenType["EQUALS"] = 3] = "EQUALS";
|
|
12
|
+
TableTokenType[TableTokenType["SHIFT_ACTION"] = 4] = "SHIFT_ACTION";
|
|
13
|
+
TableTokenType[TableTokenType["REDUCE_ACTION"] = 5] = "REDUCE_ACTION";
|
|
14
|
+
TableTokenType[TableTokenType["GOTO_ACTION"] = 6] = "GOTO_ACTION";
|
|
15
|
+
TableTokenType[TableTokenType["EOF"] = 7] = "EOF";
|
|
16
|
+
})(TableTokenType || (exports.TableTokenType = TableTokenType = {}));
|
|
17
|
+
exports.tableLexerGenerator = new slex_1.Slex({
|
|
18
|
+
EOF_TYPE: TableTokenType.EOF,
|
|
19
|
+
isHigherPrecedence: () => false,
|
|
20
|
+
});
|
|
21
|
+
exports.tableLexerGenerator.addRule("lowercase", "a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z");
|
|
22
|
+
exports.tableLexerGenerator.addRule("uppercase", "A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z");
|
|
23
|
+
exports.tableLexerGenerator.addRule("letter", "${lowercase} | ${uppercase}");
|
|
24
|
+
exports.tableLexerGenerator.addRule("digit", "0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9");
|
|
25
|
+
exports.tableLexerGenerator.addRule("alphanumeric", "${letter} | ${digit}");
|
|
26
|
+
exports.tableLexerGenerator.addRule("identifier", "(${letter} | ${digit} | $_)*");
|
|
27
|
+
exports.tableLexerGenerator.addRule("comma", "$,", TableTokenType.COMMA);
|
|
28
|
+
exports.tableLexerGenerator.addRule("equals", "$=", TableTokenType.EQUALS);
|
|
29
|
+
exports.tableLexerGenerator.addRule("production_name", "$< ${identifier} $>", TableTokenType.PRODUCTION_NAME);
|
|
30
|
+
exports.tableLexerGenerator.addRule("token_name", "$[ ${identifier} $]", TableTokenType.TOKEN_NAME);
|
|
31
|
+
exports.tableLexerGenerator.addRule("shift_action", "s(${digit})*", TableTokenType.SHIFT_ACTION);
|
|
32
|
+
exports.tableLexerGenerator.addRule("reduce_action", "r(${digit})*", TableTokenType.REDUCE_ACTION);
|
|
33
|
+
exports.tableLexerGenerator.addRule("goto_action", "${digit}(${digit})*", TableTokenType.GOTO_ACTION);
|
|
34
|
+
const buildStates = (grammar) => grammar.split("\n").map((line) => {
|
|
35
|
+
const lexer = exports.tableLexerGenerator.generate(line, () => ({}));
|
|
36
|
+
const state = new parser_1.TableState();
|
|
37
|
+
const expect = (type) => {
|
|
38
|
+
const token = lexer.peekNextToken();
|
|
39
|
+
if (token.type !== type)
|
|
40
|
+
throw new Error(`Expected ${TableTokenType[type]}, got ${TableTokenType[token.type]}`);
|
|
41
|
+
lexer.getNextToken();
|
|
42
|
+
};
|
|
43
|
+
while (lexer.hasNextToken()) {
|
|
44
|
+
const token = lexer.getNextToken();
|
|
45
|
+
expect(TableTokenType.EQUALS);
|
|
46
|
+
const value = lexer.getNextToken();
|
|
47
|
+
const setting = token.type === TableTokenType.PRODUCTION_NAME
|
|
48
|
+
? { type: "goto", value: parseInt(value.lexeme) }
|
|
49
|
+
: value.type === TableTokenType.REDUCE_ACTION
|
|
50
|
+
? { type: "reduce", value: parseInt(value.lexeme.substring(1)) }
|
|
51
|
+
: { type: "shift", value: parseInt(value.lexeme.substring(1)) };
|
|
52
|
+
state.actions.set(token.lexeme, setting);
|
|
53
|
+
if (lexer.peekNextToken().type == TableTokenType.COMMA)
|
|
54
|
+
lexer.getNextToken();
|
|
55
|
+
}
|
|
56
|
+
return state;
|
|
57
|
+
});
|
|
58
|
+
exports.buildStates = buildStates;
|
|
59
|
+
//# sourceMappingURL=tableParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tableParser.js","sourceRoot":"","sources":["../src/tableParser.ts"],"names":[],"mappings":";;;AAAA,4CAAyC;AACzC,qCAAmD;AAGnD,IAAY,cASX;AATD,WAAY,cAAc;IACxB,yEAAe,CAAA;IACf,+DAAU,CAAA;IACV,qDAAK,CAAA;IACL,uDAAM,CAAA;IACN,mEAAY,CAAA;IACZ,qEAAa,CAAA;IACb,iEAAW,CAAA;IACX,iDAAG,CAAA;AACL,CAAC,EATW,cAAc,8BAAd,cAAc,QASzB;AAEY,QAAA,mBAAmB,GAAG,IAAI,WAAI,CAAqC;IAC9E,QAAQ,EAAE,cAAc,CAAC,GAAG;IAC5B,kBAAkB,EAAE,GAAG,EAAE,CAAC,KAAK;CAChC,CAAC,CAAC;AAEH,2BAAmB,CAAC,OAAO,CACzB,WAAW,EACX,uGAAuG,CACxG,CAAC;AACF,2BAAmB,CAAC,OAAO,CACzB,WAAW,EACX,uGAAuG,CACxG,CAAC;AACF,2BAAmB,CAAC,OAAO,CAAC,QAAQ,EAAE,6BAA6B,CAAC,CAAC;AACrE,2BAAmB,CAAC,OAAO,CAAC,OAAO,EAAE,uCAAuC,CAAC,CAAC;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"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Stack = void 0;
|
|
4
|
+
class Stack {
|
|
5
|
+
push(item) {
|
|
6
|
+
this.items.push(item);
|
|
7
|
+
}
|
|
8
|
+
pop() {
|
|
9
|
+
const item = this.items.pop();
|
|
10
|
+
if (item === undefined)
|
|
11
|
+
throw new Error("Stack is empty");
|
|
12
|
+
return item;
|
|
13
|
+
}
|
|
14
|
+
peek() {
|
|
15
|
+
const ret = this.items[this.items.length - 1];
|
|
16
|
+
if (ret === undefined)
|
|
17
|
+
throw new Error("Stack is empty");
|
|
18
|
+
return ret;
|
|
19
|
+
}
|
|
20
|
+
constructor(items = []) {
|
|
21
|
+
this.items = [];
|
|
22
|
+
this.items = items;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.Stack = Stack;
|
|
26
|
+
//# sourceMappingURL=Stack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Stack.js","sourceRoot":"","sources":["../../src/utils/Stack.ts"],"names":[],"mappings":";;;AAAA,MAAa,KAAK;IAGT,IAAI,CAAC,IAAO;QACjB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAEM,GAAG;QACR,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;QAC9B,IAAI,IAAI,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAC1D,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,IAAI;QACT,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC9C,IAAI,GAAG,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;QACzD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,YAAY,QAAa,EAAE;QAlBnB,UAAK,GAAQ,EAAE,CAAC;QAmBtB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAtBD,sBAsBC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildErrorWindow = void 0;
|
|
4
|
+
const buildErrorWindow = (file, token) => {
|
|
5
|
+
const lines = file.split("\n");
|
|
6
|
+
const length = Math.max(`${token.line}`.length, `${token.column}`.length);
|
|
7
|
+
let second = "", third = "";
|
|
8
|
+
for (let i = 0; i < token.column + length + 3; i++) {
|
|
9
|
+
second += " ";
|
|
10
|
+
third += "-";
|
|
11
|
+
}
|
|
12
|
+
second += "|";
|
|
13
|
+
third += "┘";
|
|
14
|
+
let window = `${token.line.toString().padStart(length)} | ${lines.length <= token.line - 1 ? "" : lines[token.line - 1]}\n${second}\n${third}\n`;
|
|
15
|
+
if (token.line < lines.length)
|
|
16
|
+
window += `${(token.line + 1).toString().padStart(length)} | ${lines[token.line]}\n`;
|
|
17
|
+
return window;
|
|
18
|
+
};
|
|
19
|
+
exports.buildErrorWindow = buildErrorWindow;
|
|
20
|
+
//# sourceMappingURL=errorWindowBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorWindowBuilder.js","sourceRoot":"","sources":["../../src/utils/errorWindowBuilder.ts"],"names":[],"mappings":";;;AAEO,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAE,KAAmB,EAAE,EAAE;IACpE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE/B,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;IAC1E,IAAI,MAAM,GAAG,EAAE,EACb,KAAK,GAAG,EAAE,CAAC;IAEb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACnD,MAAM,IAAI,GAAG,CAAC;QACd,KAAK,IAAI,GAAG,CAAC;IACf,CAAC;IACD,MAAM,IAAI,GAAG,CAAC;IACd,KAAK,IAAI,GAAG,CAAC;IAEb,IAAI,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,MACpD,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,CAC5D,KAAK,MAAM,KAAK,KAAK,IAAI,CAAC;IAE1B,IAAI,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,MAAM;QAAE,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;IACpH,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AApBW,QAAA,gBAAgB,oBAoB3B"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// An example showing different array methods in LoLang
|
|
2
|
+
item champions: message[] = ["Caps", "Uzi", "Pewdiepie", "Bengi", "Perkz", "Miss Fortune"];
|
|
3
|
+
item THRESHOLD: stats = 6;
|
|
4
|
+
|
|
5
|
+
// Array::filter
|
|
6
|
+
item longNameChampions: message[] = champions.filter(skill (item name: message): goat -> {
|
|
7
|
+
recast name.length() > THRESHOLD;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
broadcast("\n\n\nChampions with long names:");
|
|
11
|
+
broadcast(longNameChampions);
|
|
12
|
+
|
|
13
|
+
// Array::map
|
|
14
|
+
item modifiedChampions: message[] = champions.map(skill (item name: message): message -> {
|
|
15
|
+
recast name + " is a champion";
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
broadcast("\n\n\nModified champions list:");
|
|
19
|
+
broadcast(modifiedChampions);
|
|
20
|
+
|
|
21
|
+
// Array::push
|
|
22
|
+
item T1Roster: message[] = ["Doran", "Oner", "Faker", "Gumayushi", "Keria", "Smash"];
|
|
23
|
+
cannon(item champ: message of T1Roster){
|
|
24
|
+
champions.push(champ);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Remove "Smash" from the Roster
|
|
28
|
+
champions.pop();
|
|
29
|
+
|
|
30
|
+
broadcast("\n\n\nNew Value of champions:");
|
|
31
|
+
broadcast(champions);
|