Skip to content

Commit 3a25229

Browse files
hildjjMingun
authored andcommitted
Optimization (inference match result): Test compiler interface in order to generate MatchResult
1 parent c82b6e9 commit 3a25229

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/compiler/passes/inference-match-result.js

+8
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ function inferenceMatchResult(ast) {
5959
// 6 == 3! -- permutations count for all transitions from one match
6060
// state to another.
6161
// After 6 iterations the cycle with guarantee begins
62+
// For example, an input of `start = [] start` will generate the
63+
// sequence: 0 -> -1 -> -1 (then stop)
64+
//
65+
// A more complex grammar theoretically would generate the
66+
// sequence: 0 -> 1 -> 0 -> -1 -> 0 -> 1 -> ... (then cycle)
67+
// but there are no examples of such grammars yet (possible, they
68+
// do not exist at all)
69+
6270
// istanbul ignore next This is canary test, shouldn't trigger in real life
6371
if (++count > 6) {
6472
throw new GrammarError(

test/types/peg.test-d.ts

+15
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,21 @@ describe("peg.d.ts", () => {
308308
"zero_or_more",
309309
]);
310310
});
311+
312+
it("compiles", () => {
313+
const ast = peggy.parser.parse("start = 'foo'", {
314+
grammarSource: "it compiles",
315+
reservedWords: peggy.RESERVED_WORDS.slice(),
316+
});
317+
expectType<peggy.ast.Grammar>(ast);
318+
const parser = peggy.compiler.compile(
319+
ast,
320+
peggy.compiler.passes
321+
);
322+
expectType<peggy.Parser>(parser);
323+
expectType<peggy.ast.MatchResult|undefined>(ast.rules[0].match);
324+
expect(ast.rules[0].match).toBe(0);
325+
});
311326
});
312327

313328
describe("run tsd", () => {

0 commit comments

Comments
 (0)