Skip to content

Commit 6a4f01c

Browse files
committed
avoid caching of lazy combinator when disabled
1 parent fa567fe commit 6a4f01c

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/parser/lexer.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ const longWord = choiceOnlyOne(matchString("a"), matchString("n"))
116116
)
117117
.skip(spaces);
118118

119-
Parser.startCache(cache);
120-
121119
/** Parses X ala X constructions if allowed by the settings. */
122120
const xAlaX = lazy(() => {
123121
if (settings.xAlaXPartialParsing) {
@@ -131,8 +129,6 @@ const xAlaX = lazy(() => {
131129
})
132130
.map<Token>((word) => ({ type: "x ala x", word }));
133131

134-
Parser.endCache();
135-
136132
/** Parses a punctuation. */
137133
const punctuation = choiceOnlyOne(
138134
match(/[.,:;?!·\u{F199C}\u{F199D}]+/u, "punctuation")

src/parser/parser-lib.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,13 @@ export function lookAhead<T>(parser: Parser<T>): Parser<T> {
144144
*/
145145
export function lazy<T>(parser: () => Parser<T>): Parser<T> {
146146
const { cache } = Parser;
147-
const cachedParser = new Lazy(() => Parser.inContext(parser, cache));
148-
Parser.addToCache(cachedParser);
149-
return new Parser((src) => cachedParser.getValue().parser(src));
147+
if (Parser.cache != null) {
148+
const cachedParser = new Lazy(() => Parser.inContext(parser, cache));
149+
Parser.addToCache(cachedParser);
150+
return new Parser((src) => cachedParser.getValue().parser(src));
151+
} else {
152+
return new Parser((src) => Parser.inContext(parser, cache).parser(src));
153+
}
150154
}
151155
/**
152156
* Evaluates all parsers on the same source string and sums it all on a single

0 commit comments

Comments
 (0)