@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.
Files changed (46) hide show
  1. package/README.md +132 -0
  2. package/dist/cli.d.ts +2 -0
  3. package/dist/cli.js +47 -0
  4. package/dist/cli.js.map +1 -0
  5. package/dist/generator.d.ts +28 -0
  6. package/dist/generator.js +290 -0
  7. package/dist/generator.js.map +1 -0
  8. package/dist/grammarParser.d.ts +27 -0
  9. package/dist/grammarParser.js +73 -0
  10. package/dist/grammarParser.js.map +1 -0
  11. package/dist/index.d.ts +5 -0
  12. package/dist/index.js +15 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/parser.d.ts +102 -0
  15. package/dist/parser.js +125 -0
  16. package/dist/parser.js.map +1 -0
  17. package/dist/tableParser.d.ts +16 -0
  18. package/dist/tableParser.js +59 -0
  19. package/dist/tableParser.js.map +1 -0
  20. package/dist/utils/Result.d.ts +9 -0
  21. package/dist/utils/Result.js +3 -0
  22. package/dist/utils/Result.js.map +1 -0
  23. package/dist/utils/Stack.d.ts +7 -0
  24. package/dist/utils/Stack.js +26 -0
  25. package/dist/utils/Stack.js.map +1 -0
  26. package/dist/utils/errorWindowBuilder.d.ts +2 -0
  27. package/dist/utils/errorWindowBuilder.js +20 -0
  28. package/dist/utils/errorWindowBuilder.js.map +1 -0
  29. package/example/LoLang/Features_Array_Methods.lol +31 -0
  30. package/example/LoLang/example.ts +214 -0
  31. package/example/LoLang/grammar.txt +149 -0
  32. package/example/LoLang/table.txt +497 -0
  33. package/example/math/example.ts +49 -0
  34. package/example/math/grammar.txt +11 -0
  35. package/example/math/table.txt +22 -0
  36. package/package.json +36 -0
  37. package/src/cli.ts +49 -0
  38. package/src/generator.ts +394 -0
  39. package/src/grammarParser.ts +97 -0
  40. package/src/index.ts +12 -0
  41. package/src/parser.ts +207 -0
  42. package/src/tableParser.ts +69 -0
  43. package/src/utils/Result.ts +3 -0
  44. package/src/utils/Stack.ts +23 -0
  45. package/src/utils/errorWindowBuilder.ts +23 -0
  46. package/tsconfig.json +30 -0
package/README.md ADDED
@@ -0,0 +1,132 @@
1
+ ## Sparse - Scin's Parsing Library
2
+
3
+ Sparse allows developers to easily create LR1 parsers and LR1 parsing tables.
4
+
5
+ **Features:**
6
+ - Complete Error Handling API - when parsing fails, you have the final say on where parsing stops
7
+ - Deferred Reductions - you create the nodes and Sparse builds the tree
8
+ - Full [Slex](https://github.com/scinscinscin/slex) integration - define your entire language as a set of DFA and CFG rules
9
+ - Optional Table Output - use Sparse to build your tables for use in other languages
10
+
11
+ ## Getting Started
12
+
13
+ 1. **Define the CFG of your language.**
14
+
15
+ The CFG is defined by creating a file containing a list of productions. Variables are identifiers encased in angle brackets like `<STATEMENT>`, while terminals are encased in square-brackets like `[L_COLON]`.
16
+
17
+ An example production includes: `<IF_STATEMENT> : [IF] [L_PAREN] <EXPRESSION> [R_PAREN] <STATEMENT> <ELSE_IF_STATEMENTS> [ELSE] <STATEMENT>;`.
18
+
19
+ An example CFG for a basic MDAS calculator is the following:
20
+
21
+ ```
22
+ <S>: <PROGRAM>;
23
+ <PROGRAM>: <EXPRESSION> [EOF];
24
+ <PROGRAM>: [EOF];
25
+ <EXPRESSION>: <TERM_EXPRESSION>;
26
+ <TERM_EXPRESSION>: <FACTOR_EXPRESSION> [PLUS] <TERM_EXPRESSION>;
27
+ <TERM_EXPRESSION>: <FACTOR_EXPRESSION> [MINUS] <TERM_EXPRESSION>;
28
+ <TERM_EXPRESSION>: <FACTOR_EXPRESSION>;
29
+ <FACTOR_EXPRESSION>: <ENDPOINT> [STAR] <FACTOR_EXPRESSION>;
30
+ <FACTOR_EXPRESSION>: <ENDPOINT> [SLASH] <FACTOR_EXPRESSION>;
31
+ <FACTOR_EXPRESSION>: <ENDPOINT>;
32
+ <ENDPOINT>: [NUMBER];
33
+ ```
34
+
35
+ 2. **Create your [Slex](https://github.com/scinscinscin/slex) lexer.**
36
+
37
+ ```ts
38
+ import { Slex } from "@scinorandex/slex";
39
+
40
+ // Make sure the identifiers here match with the terminals in your CFG.
41
+ enum TokenType {
42
+ PLUS, MINUS, STAR, SLASH, NUMBER, EOF
43
+ }
44
+
45
+ type Metadata = {};
46
+
47
+ const lexerGenerator = new Slex<TokenType, Metadata>({
48
+ EOF_TYPE: TokenType.EOF,
49
+ isHigherPrecedence: ({ current, next }) => false,
50
+ });
51
+
52
+ lexerGenerator.addRule("plus", "$+", TokenType.PLUS);
53
+ lexerGenerator.addRule("minus", "$-", TokenType.MINUS);
54
+ lexerGenerator.addRule("star", "$*", TokenType.STAR);
55
+ lexerGenerator.addRule("forward_slash", "$/", TokenType.SLASH);
56
+ lexerGenerator.addRule("digit", "0|1|2|3|4|5|6|7|8|9");
57
+ lexerGenerator.addRule("float_number", "(${digit})+$.(${digit})+");
58
+ lexerGenerator.addRule("decimal_number", "(${digit})+");
59
+ lexerGenerator.addRule("number_literal", "${float_number}|${decimal_number}", TokenType.NUMBER);
60
+
61
+ const lexer = lexerGenerator.generate(`2.4 + 3.5 * 1 / 456.789`, () => ({}));
62
+ ```
63
+
64
+ 3. **Define the node representation.**
65
+
66
+ Sparse allows you to build the AST however you want, deferring to your functions when its time to make a reduction, giving you control over the representation.
67
+
68
+ ```ts
69
+ type StringifiedNode = (StringifiedNode | string)[];
70
+
71
+ // It doesn't have to be a class. It just has to be a structure that all nodes
72
+ // in the AST adhere to. Classes allow this to be done easily through subclassing.
73
+ class Node {
74
+ constructor(public readonly nodes: LR1StackSymbol<TokenType, {}, Node>[]) {}
75
+ toObject(): StringifiedNode {
76
+ return this.nodes.map((node) => (node.type === "token"
77
+ ? node.token.lexeme
78
+ : node.node.toObject()
79
+ ));
80
+ }
81
+ }
82
+ ```
83
+
84
+ 4. **Building the productions and the parser.**
85
+
86
+ Productions are built using the `buildProductions()` function, which can be passed into Sparse alongside `toStringifiedTokenType`, which converts a numerical TypeScript enum to the name of the terminal.
87
+
88
+ ```ts
89
+ async function main() {
90
+ const toStringifiedTokenType = (type: TokenType) => TokenType[type];
91
+ const productions = buildProductions(await fs.readFile("./example/math/grammar.txt", "utf8"));
92
+ const parserGenerator = Sparse.fromProductions<TokenType, Metadata, Node>({ productions, toStringifiedTokenType });
93
+ }
94
+ ```
95
+
96
+ 5. **Define your reducer and begin parsing.**
97
+
98
+ Finally, you can define the parser's reduction function and optionally define the recovery handling function.
99
+
100
+ ```ts
101
+ const parser = parserGenerator.generate(lexer, {
102
+ reducer: (input, productionIndex) => new Node(input),
103
+ });
104
+
105
+ console.log(parser.parse().result!.toObject());
106
+ ```
107
+
108
+ ## Exporting and Loading the Parsing Table
109
+
110
+ It takes a while for Sparse to build states (around 30 seconds for a file containing 150 productions). This can be alleviated by generating the parsing table and loading the states directly instead. This method also allows you to edit the parsing table to resolve parsing conflicts.
111
+
112
+ To create the the states, you can run `npx @scinorandex/sparse --input=<input> --output=<output>`.
113
+
114
+ Afterwards, you can create a parser with pre-built states like the following:
115
+
116
+ ```ts
117
+ async function main() {
118
+ const toStringifiedTokenType = (type: TokenType) => TokenType[type];
119
+ const productions = buildProductions(await fs.readFile("./example/math/grammar.txt", "utf8"));
120
+
121
+ // Notice how the "new Sparse()" constructor is used here instead of "Sparse.fromProductions()"
122
+ const states = buildStates(await fs.readFile("./example/math/table.txt", "utf8"));
123
+ const parserGenerator = new Sparse<TokenType, Metadata, Node>({ productions, states, toStringifiedTokenType });
124
+ }
125
+ ```
126
+
127
+ ---
128
+
129
+ ## Roadmap
130
+
131
+ 1. Support grouping and other modifiers in the CFG. Currently, you have to unroll your grammar and remove kleene-star, kleene-plus, optional, and other modifiers.
132
+ 2. Potentially add LALR(1) support. Currently, the parser only supports outputting LR(1) tables. Tables can be significantly smaller if it made LALR(1) tables instead.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #! /usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,47 @@
1
+ #! /usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const promises_1 = __importDefault(require("fs/promises"));
8
+ const grammarParser_1 = require("./grammarParser");
9
+ const generator_1 = require("./generator");
10
+ const minimist_1 = __importDefault(require("minimist"));
11
+ const path_1 = __importDefault(require("path"));
12
+ const errorWindowBuilder_1 = require("./utils/errorWindowBuilder");
13
+ const args = (0, minimist_1.default)(process.argv.slice(2));
14
+ function checkFileExists(filepath) {
15
+ return new Promise((resolve, reject) => {
16
+ promises_1.default.access(filepath, promises_1.default.constants.F_OK)
17
+ .then(() => resolve(true))
18
+ .catch(() => resolve(false));
19
+ });
20
+ }
21
+ async function main() {
22
+ if (typeof args.input !== "string" || typeof args.output !== "string") {
23
+ console.log("Usage: npx @scinorandex/sparse --input=<input> --output=<output>");
24
+ return;
25
+ }
26
+ const inputFile = path_1.default.resolve(args.input);
27
+ const outputFile = path_1.default.resolve(args.output);
28
+ console.log(`Reading grammar from ${inputFile} and outputting table to ${outputFile}\n`);
29
+ if (!(await checkFileExists(inputFile)))
30
+ return console.log(`File ${inputFile} does not exist`);
31
+ const grammar = await promises_1.default.readFile(args.input, "utf8");
32
+ const productionsResult = (0, grammarParser_1.tryBuildProductions)(grammar);
33
+ if (productionsResult.success === false) {
34
+ console.log(productionsResult.reason);
35
+ console.log((0, errorWindowBuilder_1.buildErrorWindow)(grammar, productionsResult.token));
36
+ return;
37
+ }
38
+ const generatorResult = (0, generator_1.generateStates)(productionsResult.value);
39
+ if (generatorResult.success === false) {
40
+ console.log(generatorResult.reason);
41
+ console.log((0, errorWindowBuilder_1.buildErrorWindow)(grammar, generatorResult.token));
42
+ return;
43
+ }
44
+ await promises_1.default.writeFile(outputFile, generatorResult.value.toTable(), { encoding: "utf-8" });
45
+ }
46
+ main();
47
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src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CAAC,CAAC;IACtD,MAAM,iBAAiB,GAAG,IAAA,mCAAmB,EAAC,OAAO,CAAC,CAAC;IACvD,IAAI,iBAAiB,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;QACtC,OAAO,CAAC,GAAG,CAAC,IAAA,qCAAgB,EAAC,OAAO,EAAE,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;QAChE,OAAO;IACT,CAAC;IAED,MAAM,eAAe,GAAG,IAAA,0BAAc,EAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAChE,IAAI,eAAe,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;QACtC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QACpC,OAAO,CAAC,GAAG,CAAC,IAAA,qCAAgB,EAAC,OAAO,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;QAC9D,OAAO;IACT,CAAC;IAED,MAAM,kBAAE,CAAC,SAAS,CAAC,UAAU,EAAE,eAAe,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;AACzF,CAAC;AAED,IAAI,EAAE,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { Production } from "./grammarParser";
2
+ import { TableState } from "./parser";
3
+ import { Result } from "./utils/Result";
4
+ type Item = Production & {
5
+ dot: number;
6
+ lookahead: string[];
7
+ };
8
+ type State = {
9
+ itemSet: Item[];
10
+ kernel: Item;
11
+ count: number;
12
+ };
13
+ export declare const generateStates: (productions: Production[]) => Result<GeneratorResult>;
14
+ export declare class GeneratorResult {
15
+ readonly states: State[];
16
+ readonly ActionTable: Map<string, {
17
+ action: "shift" | "reduce";
18
+ value: number;
19
+ }>[];
20
+ readonly GotoTable: Map<string, number>[];
21
+ constructor(states: State[], ActionTable: Map<string, {
22
+ action: "shift" | "reduce";
23
+ value: number;
24
+ }>[], GotoTable: Map<string, number>[]);
25
+ toTable(): string;
26
+ toStates(): TableState[];
27
+ }
28
+ export {};
@@ -0,0 +1,290 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GeneratorResult = exports.generateStates = void 0;
4
+ const parser_1 = require("./parser");
5
+ const xContainsAllOfY = (xs, ys) => [...ys].every((x) => xs.has(x));
6
+ const EOF_STRING = "[EOF]";
7
+ function computeFirstSets(allProductions) {
8
+ const ret = new Map();
9
+ for (const production of allProductions)
10
+ ret.set(production.lhs.lexeme, new Set());
11
+ let wasEdited = true;
12
+ while (wasEdited) {
13
+ wasEdited = false;
14
+ for (const production of allProductions) {
15
+ const toBeModified = ret.get(production.lhs.lexeme);
16
+ const firstRhsToken = production.rhs[0];
17
+ if (firstRhsToken.type === "variable") {
18
+ const add = ret.get(firstRhsToken.token.lexeme);
19
+ if (add == null) {
20
+ return {
21
+ success: false,
22
+ reason: `Variable "${firstRhsToken.token.lexeme}" doesn't have a corresponding left hand side`,
23
+ token: firstRhsToken.token,
24
+ };
25
+ }
26
+ if (!xContainsAllOfY(toBeModified, add)) {
27
+ wasEdited = true;
28
+ ret.set(production.lhs.lexeme, new Set([...toBeModified, ...add]));
29
+ }
30
+ }
31
+ else if (firstRhsToken.type === "terminal") {
32
+ if (toBeModified.has(firstRhsToken.token.lexeme) == false) {
33
+ wasEdited = true;
34
+ ret.set(production.lhs.lexeme, new Set([...toBeModified, firstRhsToken.token.lexeme]));
35
+ }
36
+ }
37
+ }
38
+ }
39
+ return { success: true, value: ret };
40
+ }
41
+ function computeFollowSets(allProductions) {
42
+ const firstSetsResult = computeFirstSets(allProductions);
43
+ if (firstSetsResult.success === false)
44
+ return firstSetsResult;
45
+ const firstSets = firstSetsResult.value;
46
+ const ret = new Map();
47
+ for (const production of allProductions)
48
+ ret.set(production.lhs.lexeme, new Set());
49
+ ret.get(allProductions[0].lhs.lexeme).add(EOF_STRING);
50
+ let wasEdited = true;
51
+ while (wasEdited) {
52
+ wasEdited = false;
53
+ for (const variable of ret.keys()) {
54
+ for (const currentProduction of allProductions) {
55
+ const rhs = currentProduction.rhs;
56
+ for (let i = 0; i < rhs.length; i++) {
57
+ const currentRhsToken = rhs[i];
58
+ if (currentRhsToken.type === "variable" && currentRhsToken.token.lexeme === variable) {
59
+ if (i === rhs.length - 1) {
60
+ const toBeAdded = ret.get(currentProduction.lhs.lexeme);
61
+ const receiver = ret.get(variable);
62
+ if (!xContainsAllOfY(receiver, toBeAdded)) {
63
+ wasEdited = true;
64
+ ret.set(variable, new Set([...toBeAdded, ...receiver]));
65
+ }
66
+ }
67
+ else {
68
+ const nextRhsToken = rhs[i + 1];
69
+ if (nextRhsToken.type === "terminal") {
70
+ const existing = ret.get(variable);
71
+ if (!existing.has(nextRhsToken.token.lexeme)) {
72
+ wasEdited = true;
73
+ ret.set(variable, new Set([...existing, nextRhsToken.token.lexeme]));
74
+ }
75
+ }
76
+ else if (nextRhsToken.type === "variable") {
77
+ const firstSet = firstSets.get(nextRhsToken.token.lexeme);
78
+ if (firstSet == null)
79
+ return {
80
+ success: false,
81
+ reason: `Variable "${nextRhsToken.token.lexeme}" doesn't have a corresponding left hand side`,
82
+ token: nextRhsToken.token,
83
+ };
84
+ if (!xContainsAllOfY(ret.get(variable), firstSet)) {
85
+ wasEdited = true;
86
+ ret.set(variable, new Set([...ret.get(variable), ...firstSet]));
87
+ }
88
+ }
89
+ }
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
95
+ return { success: true, value: { firstSets, followSets: ret } };
96
+ }
97
+ const generateStates = (productions) => {
98
+ const followSetsResult = computeFollowSets(productions);
99
+ if (followSetsResult.success == false)
100
+ return followSetsResult;
101
+ const { firstSets, followSets } = followSetsResult.value;
102
+ const determineNextLookAhead = (lhs, array) => {
103
+ if (array.length === 0) {
104
+ const followSet = followSets.get(lhs.lexeme);
105
+ if (followSet != undefined)
106
+ return { success: true, value: [...followSet] };
107
+ return {
108
+ success: false,
109
+ reason: `Variable ${lhs.lexeme} not present in computed follow sets`,
110
+ token: lhs,
111
+ };
112
+ }
113
+ else {
114
+ const next = array[0];
115
+ if (next.type === "terminal")
116
+ return { success: true, value: [next.token.lexeme] };
117
+ const testing = firstSets.get(next.token.lexeme);
118
+ if (testing !== undefined)
119
+ return { success: true, value: [...testing] };
120
+ return {
121
+ success: false,
122
+ reason: `Variable ${next.token.lexeme} not present in computed first sets`,
123
+ token: next.token,
124
+ };
125
+ }
126
+ };
127
+ function generateInitialItemSet(production) {
128
+ const initialItem = { lhs: production.lhs, rhs: production.rhs, dot: 0, lookahead: [EOF_STRING] };
129
+ return expandItemSet([initialItem]);
130
+ }
131
+ function expandItemSet(items) {
132
+ const itemSet = [...items];
133
+ const unprocesssedItems = [...items];
134
+ while (unprocesssedItems.length > 0) {
135
+ const currentItem = unprocesssedItems.shift();
136
+ const after = currentItem.rhs[currentItem.dot];
137
+ if (after == null)
138
+ continue;
139
+ if (after.type === "variable") {
140
+ const newProductions = productions.filter((p) => p.lhs.lexeme === after.token.lexeme);
141
+ const rest = currentItem.rhs.slice(currentItem.dot + 1);
142
+ const lookaheadResult = determineNextLookAhead(currentItem.lhs, rest);
143
+ if (lookaheadResult.success === false)
144
+ return lookaheadResult;
145
+ const lookahead = lookaheadResult.value;
146
+ for (const newProduction of newProductions) {
147
+ const newItem = { lhs: newProduction.lhs, rhs: newProduction.rhs, dot: 0, lookahead };
148
+ const encoding = JSON.stringify(newItem);
149
+ if (itemSet.some((i) => JSON.stringify(i) === encoding) == false) {
150
+ unprocesssedItems.push(newItem);
151
+ itemSet.push(newItem);
152
+ }
153
+ }
154
+ }
155
+ }
156
+ return { success: true, value: { itemSet, kernel: items[0] } };
157
+ }
158
+ const initialItemSetResult = generateInitialItemSet(productions[0]);
159
+ if (initialItemSetResult.success === false)
160
+ return initialItemSetResult;
161
+ const initialItemSet = initialItemSetResult.value;
162
+ function generateStates(_initialState) {
163
+ const initialState = Object.assign(Object.assign({}, _initialState), { count: 0 });
164
+ const states = [initialState];
165
+ const unprocessedStates = [initialState];
166
+ const GotoTable = [];
167
+ const ActionTable = [];
168
+ while (unprocessedStates.length > 0) {
169
+ const currentState = unprocessedStates.shift();
170
+ const nextStates_Goto = new Map();
171
+ const nextStates_Shift = new Map();
172
+ calculateNextItem: for (const item of currentState.itemSet) {
173
+ const nextSymbol = item.rhs[item.dot];
174
+ if (nextSymbol == null) {
175
+ const productionToReduceTo = productions
176
+ .map((p, i) => [p, i])
177
+ .find(([p, _]) => JSON.stringify(p.rhs) === JSON.stringify(item.rhs) && p.lhs.lexeme === item.lhs.lexeme)[1];
178
+ for (const lookahead of item.lookahead) {
179
+ if (ActionTable[currentState.count] === undefined)
180
+ ActionTable[currentState.count] = new Map();
181
+ ActionTable[currentState.count].set(lookahead, { action: "reduce", value: productionToReduceTo });
182
+ }
183
+ continue calculateNextItem;
184
+ }
185
+ const newItem = Object.assign(Object.assign({}, item), { dot: item.dot + 1 });
186
+ if (nextSymbol.type === "variable") {
187
+ if (nextStates_Goto.has(nextSymbol.token.lexeme))
188
+ nextStates_Goto.get(nextSymbol.token.lexeme).push(newItem);
189
+ else
190
+ nextStates_Goto.set(nextSymbol.token.lexeme, [newItem]);
191
+ }
192
+ else if (nextSymbol.type === "terminal") {
193
+ if (nextStates_Shift.has(nextSymbol.token.lexeme))
194
+ nextStates_Shift.get(nextSymbol.token.lexeme).push(newItem);
195
+ else
196
+ nextStates_Shift.set(nextSymbol.token.lexeme, [newItem]);
197
+ }
198
+ }
199
+ for (const [gotoTransition, gotoItems] of nextStates_Goto.entries()) {
200
+ const expandedItemsResult = expandItemSet(gotoItems);
201
+ if (expandedItemsResult.success === false)
202
+ return expandedItemsResult;
203
+ const expandedItems = expandedItemsResult.value;
204
+ let existingState = states.find((s) => {
205
+ return (s.kernel.lhs === expandedItems.kernel.lhs &&
206
+ s.kernel.rhs.length === expandedItems.kernel.rhs.length &&
207
+ JSON.stringify(s.kernel.rhs) === JSON.stringify(expandedItems.kernel.rhs) &&
208
+ s.kernel.lookahead.length === expandedItems.kernel.lookahead.length &&
209
+ JSON.stringify(s.kernel.lookahead) === JSON.stringify(expandedItems.kernel.lookahead) &&
210
+ JSON.stringify(s.itemSet) === JSON.stringify(expandedItems.itemSet));
211
+ });
212
+ if (GotoTable[currentState.count] === undefined)
213
+ GotoTable[currentState.count] = new Map();
214
+ if (existingState == undefined) {
215
+ const newState = {
216
+ itemSet: expandedItems.itemSet,
217
+ kernel: expandedItems.kernel,
218
+ count: states.length,
219
+ };
220
+ states.push(newState);
221
+ unprocessedStates.push(newState);
222
+ existingState = newState;
223
+ }
224
+ GotoTable[currentState.count].set(gotoTransition, existingState.count);
225
+ }
226
+ for (const [shiftTransition, shiftItems] of nextStates_Shift.entries()) {
227
+ const expandedItemsResult = expandItemSet(shiftItems);
228
+ if (expandedItemsResult.success === false)
229
+ return expandedItemsResult;
230
+ const expandedItems = expandedItemsResult.value;
231
+ let existingState = states.find((s) => {
232
+ return (s.kernel.lhs === expandedItems.kernel.lhs &&
233
+ s.kernel.rhs.length === expandedItems.kernel.rhs.length &&
234
+ JSON.stringify(s.kernel.rhs) === JSON.stringify(expandedItems.kernel.rhs) &&
235
+ s.kernel.lookahead.length === expandedItems.kernel.lookahead.length &&
236
+ JSON.stringify(s.kernel.lookahead) === JSON.stringify(expandedItems.kernel.lookahead) &&
237
+ JSON.stringify(s.itemSet) === JSON.stringify(expandedItems.itemSet));
238
+ });
239
+ if (ActionTable[currentState.count] === undefined)
240
+ ActionTable[currentState.count] = new Map();
241
+ if (existingState == undefined) {
242
+ const newState = {
243
+ itemSet: expandedItems.itemSet,
244
+ kernel: expandedItems.kernel,
245
+ count: states.length,
246
+ };
247
+ states.push(newState);
248
+ unprocessedStates.push(newState);
249
+ existingState = newState;
250
+ }
251
+ ActionTable[currentState.count].set(shiftTransition, { action: "shift", value: existingState.count });
252
+ }
253
+ }
254
+ return { success: true, value: { states, GotoTable, ActionTable } };
255
+ }
256
+ const StatesResult = generateStates(initialItemSet);
257
+ if (StatesResult.success === false)
258
+ return StatesResult;
259
+ const { states, ActionTable, GotoTable } = StatesResult.value;
260
+ return { success: true, value: new GeneratorResult(states, ActionTable, GotoTable) };
261
+ };
262
+ exports.generateStates = generateStates;
263
+ class GeneratorResult {
264
+ constructor(states, ActionTable, GotoTable) {
265
+ this.states = states;
266
+ this.ActionTable = ActionTable;
267
+ this.GotoTable = GotoTable;
268
+ }
269
+ toTable() {
270
+ return this.ActionTable.map((actions, idx) => {
271
+ return [
272
+ ...[...actions.entries()].map(([k, { action, value }]) => `${k}=${action === "reduce" ? "r" : "s"}${value}`),
273
+ ...(this.GotoTable[idx] === undefined ? [] : [...this.GotoTable[idx].entries()].map(([k, v]) => `${k}=${v}`)),
274
+ ].join(", ");
275
+ }).join("\n");
276
+ }
277
+ toStates() {
278
+ return this.ActionTable.map((actions, idx) => {
279
+ const tableState = new parser_1.TableState();
280
+ for (const [k, { action, value }] of actions.entries())
281
+ tableState.actions.set(k, { type: action === "reduce" ? "reduce" : "shift", value });
282
+ if (this.GotoTable[idx] !== undefined)
283
+ for (const [k, value] of this.GotoTable[idx].entries())
284
+ tableState.actions.set(k, { type: "goto", value });
285
+ return tableState;
286
+ });
287
+ }
288
+ }
289
+ exports.GeneratorResult = GeneratorResult;
290
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":";;;AACA,qCAAsC;AAGtC,MAAM,eAAe,GAAG,CAAI,EAAU,EAAE,EAAU,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACvF,MAAM,UAAU,GAAG,OAAO,CAAC;AAG3B,SAAS,gBAAgB,CAAC,cAA4B;IAEpD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC3C,KA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CAAC,CAAC;QACf,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,GAAG,EAAE,EAAE;YAC3C,MAAM,UAAU,GAAG,IAAI,mBAAU,EAAE,CAAC;YACpC,KAAK,MAAM,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE;gBACpD,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;YAEvF,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,SAAS;gBACnC,KAAK,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE;oBAAE,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;YAE7G,OAAO,UAAU,CAAC;QACpB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA5BD,0CA4BC"}
@@ -0,0 +1,27 @@
1
+ import { Slex, Token } from "@scinorandex/slex";
2
+ import { Result } from "./utils/Result";
3
+ export type Production = {
4
+ lhs: GrammarToken;
5
+ rhs: {
6
+ type: "terminal" | "variable";
7
+ token: GrammarToken;
8
+ }[];
9
+ };
10
+ export type GrammarTokenMetadata = {};
11
+ export declare enum GrammarTokenType {
12
+ PRODUCTION_NAME = 0,
13
+ TOKEN_NAME = 1,
14
+ COLON = 2,
15
+ SEMICOLON = 3,
16
+ EOF = 4
17
+ }
18
+ export type GrammarToken = Token<GrammarTokenType, GrammarTokenMetadata>;
19
+ export declare const grammarLexerGenerator: Slex<GrammarTokenType, GrammarTokenMetadata>;
20
+ interface LexerInterface {
21
+ peekNextToken(): GrammarToken;
22
+ getNextToken(): GrammarToken;
23
+ hasNextToken(): boolean;
24
+ }
25
+ export declare const tryBuildProductions: (lexer: LexerInterface | string) => Result<Production[]>;
26
+ export declare const buildProductions: (lexer: LexerInterface | string) => Production[];
27
+ export {};
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildProductions = exports.tryBuildProductions = exports.grammarLexerGenerator = exports.GrammarTokenType = void 0;
4
+ const slex_1 = require("@scinorandex/slex");
5
+ var GrammarTokenType;
6
+ (function (GrammarTokenType) {
7
+ GrammarTokenType[GrammarTokenType["PRODUCTION_NAME"] = 0] = "PRODUCTION_NAME";
8
+ GrammarTokenType[GrammarTokenType["TOKEN_NAME"] = 1] = "TOKEN_NAME";
9
+ GrammarTokenType[GrammarTokenType["COLON"] = 2] = "COLON";
10
+ GrammarTokenType[GrammarTokenType["SEMICOLON"] = 3] = "SEMICOLON";
11
+ GrammarTokenType[GrammarTokenType["EOF"] = 4] = "EOF";
12
+ })(GrammarTokenType || (exports.GrammarTokenType = GrammarTokenType = {}));
13
+ exports.grammarLexerGenerator = new slex_1.Slex({
14
+ EOF_TYPE: GrammarTokenType.EOF,
15
+ isHigherPrecedence: () => false,
16
+ });
17
+ exports.grammarLexerGenerator.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");
18
+ exports.grammarLexerGenerator.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");
19
+ exports.grammarLexerGenerator.addRule("letter", "${lowercase} | ${uppercase}");
20
+ exports.grammarLexerGenerator.addRule("digit", "0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9");
21
+ exports.grammarLexerGenerator.addRule("alphanumeric", "${letter} | ${digit}");
22
+ exports.grammarLexerGenerator.addRule("identifier", "(${letter} | ${digit} | $_)*");
23
+ exports.grammarLexerGenerator.addRule("colon", "$:", GrammarTokenType.COLON);
24
+ exports.grammarLexerGenerator.addRule("semicolon", "$;", GrammarTokenType.SEMICOLON);
25
+ exports.grammarLexerGenerator.addRule("production_name", "$< ${identifier} $>", GrammarTokenType.PRODUCTION_NAME);
26
+ exports.grammarLexerGenerator.addRule("token_name", "$[ ${identifier} $]", GrammarTokenType.TOKEN_NAME);
27
+ const tryBuildProductions = (lexer) => {
28
+ if (typeof lexer === "string")
29
+ lexer = exports.grammarLexerGenerator.generate(lexer, () => ({}));
30
+ const productions = [];
31
+ const expect = (type) => {
32
+ const token = lexer.peekNextToken();
33
+ if (token.type !== type)
34
+ throw new Error(`Expected ${type}, got ${token.type}`);
35
+ lexer.getNextToken();
36
+ };
37
+ const buildProduction = () => {
38
+ const productionLHS = lexer.getNextToken();
39
+ expect(GrammarTokenType.COLON);
40
+ const production = { lhs: productionLHS, rhs: [] };
41
+ while (lexer.peekNextToken().type != GrammarTokenType.SEMICOLON) {
42
+ const productionRHS = lexer.getNextToken();
43
+ if (productionRHS.type == GrammarTokenType.PRODUCTION_NAME)
44
+ production.rhs.push({ type: "variable", token: productionRHS });
45
+ else if (productionRHS.type == GrammarTokenType.TOKEN_NAME)
46
+ production.rhs.push({ type: "terminal", token: productionRHS });
47
+ else
48
+ return {
49
+ success: false,
50
+ reason: `Unexpected token type: ${GrammarTokenType[productionRHS.type]}`,
51
+ token: productionRHS,
52
+ };
53
+ }
54
+ expect(GrammarTokenType.SEMICOLON);
55
+ return { success: true, value: production };
56
+ };
57
+ while (lexer.hasNextToken()) {
58
+ const result = buildProduction();
59
+ if (result.success === false)
60
+ return result;
61
+ productions.push(result.value);
62
+ }
63
+ return { success: true, value: productions };
64
+ };
65
+ exports.tryBuildProductions = tryBuildProductions;
66
+ const buildProductions = (lexer) => {
67
+ const result = (0, exports.tryBuildProductions)(lexer);
68
+ if (result.success === false)
69
+ throw new Error(`Encountered error "${result.reason}" while parsing grammar at ${result.token.line}:${result.token.column}`);
70
+ return result.value;
71
+ };
72
+ exports.buildProductions = buildProductions;
73
+ //# sourceMappingURL=grammarParser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grammarParser.js","sourceRoot":"","sources":["../src/grammarParser.ts"],"names":[],"mappings":";;;AAAA,4CAAgD;AAMhD,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC1B,6EAAe,CAAA;IACf,mEAAU,CAAA;IACV,yDAAK,CAAA;IACL,iEAAS,CAAA;IACT,qDAAG,CAAA;AACL,CAAC,EANW,gBAAgB,gCAAhB,gBAAgB,QAM3B;AAIY,QAAA,qBAAqB,GAAG,IAAI,WAAI,CAAyC;IACpF,QAAQ,EAAE,gBAAgB,CAAC,GAAG;IAC9B,kBAAkB,EAAE,GAAG,EAAE,CAAC,KAAK;CAChC,CAAC,CAAC;AAEH,6BAAqB,CAAC,OAAO,CAC3B,WAAW,EACX,uGAAuG,CACxG,CAAC;AACF,6BAAqB,CAAC,OAAO,CAC3B,WAAW,EACX,uGAAuG,CACxG,CAAC;AACF,6BAAqB,CAAC,OAAO,CAAC,QAAQ,EAAE,6BAA6B,CAAC,CAAC;AACvE,6BAAqB,CAAC,OAAO,CAAC,OAAO,EAAE,uCAAuC,CAAC,CAAC;AAChF,6BAAqB,CAAC,OAAO,CAAC,cAAc,EAAE,sBAAsB,CAAC,CAAC;AACtE,6BAAqB,CAAC,OAAO,CAAC,YAAY,EAAE,8BAA8B,CAAC,CAAC;AAC5E,6BAAqB,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC;AACrE,6BAAqB,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;AAC7E,6BAAqB,CAAC,OAAO,CAAC,iBAAiB,EAAE,qBAAqB,EAAE,gBAAgB,CAAC,eAAe,C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grammarParser";
3
+ export { Result } from "./utils/Result";
4
+ export { ParserRecoveryFunction, Sparse, LR1ParserGraveError, LR1StackSymbol, ParserResult, ParserError, } from "./parser";
5
+ export { buildStates } from "./tableParser";