Comparing version 0.15.1 to 0.15.2
@@ -896,3 +896,2 @@ import { Parser, NodeSet, NodeType, DefaultBufferLength, NodeProp, Tree } from '@lezer/common'; | ||
} | ||
const dummyToken = new CachedToken; | ||
class TokenCache { | ||
@@ -902,3 +901,3 @@ constructor(parser, stream) { | ||
this.tokens = []; | ||
this.mainToken = dummyToken; | ||
this.mainToken = null; | ||
this.actions = []; | ||
@@ -943,14 +942,7 @@ this.tokens = parser.tokenizers.map(_ => new CachedToken); | ||
stack.setLookAhead(lookAhead); | ||
if (!main) { | ||
main = dummyToken; | ||
main.start = stack.pos; | ||
if (stack.pos == this.stream.end) { | ||
main.value = stack.p.parser.eofTerm; | ||
main.end = stack.pos; | ||
actionIndex = this.addActions(stack, main.value, main.end, actionIndex); | ||
} | ||
else { | ||
main.value = 0 /* Err */; | ||
main.end = stack.pos + 1; | ||
} | ||
if (!main && stack.pos == this.stream.end) { | ||
main = new CachedToken; | ||
main.value = stack.p.parser.eofTerm; | ||
main.start = main.end = stack.pos; | ||
actionIndex = this.addActions(stack, main.value, main.end, actionIndex); | ||
} | ||
@@ -960,2 +952,11 @@ this.mainToken = main; | ||
} | ||
getMainToken(stack) { | ||
if (this.mainToken) | ||
return this.mainToken; | ||
let main = new CachedToken, { pos, p } = stack; | ||
main.start = pos; | ||
main.end = Math.min(pos + 1, p.stream.end); | ||
main.value = pos == p.stream.end ? p.parser.eofTerm : 0 /* Err */; | ||
return main; | ||
} | ||
updateCachedToken(token, tokenizer, stack) { | ||
@@ -979,3 +980,3 @@ tokenizer.token(this.stream.reset(stack.pos, token), stack); | ||
token.value = 0 /* Err */; | ||
token.end = stack.pos + 1; | ||
token.end = Math.min(stack.p.stream.end, stack.pos + 1); | ||
} | ||
@@ -1059,2 +1060,3 @@ } | ||
for (;;) { | ||
this.tokens.mainToken = null; | ||
if (stack.pos > pos) { | ||
@@ -1072,3 +1074,3 @@ newStacks.push(stack); | ||
stopped.push(stack); | ||
let tok = this.tokens.mainToken; | ||
let tok = this.tokens.getMainToken(stack); | ||
stoppedTokens.push(tok.value, tok.end); | ||
@@ -1085,3 +1087,3 @@ } | ||
if (verbose && stopped) | ||
console.log("Stuck with token " + this.parser.getName(this.tokens.mainToken.value)); | ||
console.log("Stuck with token " + (this.tokens.mainToken ? this.parser.getName(this.tokens.mainToken.value) : "none")); | ||
throw new SyntaxError("No parse at " + pos); | ||
@@ -1088,0 +1090,0 @@ } |
@@ -22,6 +22,7 @@ import { Tree, TreeFragment, NodeSet, NodeType, NodePropSource, Input, PartialParse, Parser, ParseWrapper } from "@lezer/common"; | ||
tokens: CachedToken[]; | ||
mainToken: CachedToken; | ||
mainToken: CachedToken | null; | ||
actions: number[]; | ||
constructor(parser: LRParser, stream: InputStream); | ||
getActions(stack: Stack): number[]; | ||
getMainToken(stack: Stack): CachedToken; | ||
updateCachedToken(token: CachedToken, tokenizer: Tokenizer, stack: Stack): void; | ||
@@ -28,0 +29,0 @@ putAction(action: number, token: number, end: number, index: number): number; |
{ | ||
"name": "@lezer/lr", | ||
"version": "0.15.1", | ||
"version": "0.15.2", | ||
"description": "Incremental parser", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.cjs", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
133890
3332