Skip to content

Commit

Permalink
Info isn't re-fetched when changed
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Dec 15, 2024
1 parent e6bc452 commit 5e75f6f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ export function parse(options: ParseOptions): Node[] {
const max_cycles = options.maxCycles ?? 5;
const id = options.id;

if (id) parseInfo.set(id, { parseNodeCalls: 0, nodesParsed: 0, ignoredLiterals: 0 });
const info: ParseInfo = { parseNodeCalls: 0, nodesParsed: 0, ignoredLiterals: 0 };

if (id) parseInfo.set(id, info);

let position = 0,
dirtyPosition = 0;
Expand All @@ -83,15 +85,15 @@ export function parse(options: ParseOptions): Node[] {

for (let i = 0; i < raw_tokens.length; i++) {
if (!options.ignoreLiterals.includes(raw_tokens[i].kind)) tokens.push(raw_tokens[i]);
else if (id) parseInfo.get(id)!.ignoredLiterals++;
else if (id) info.ignoredLiterals++;
}

const literals = 'tokens' in options ? options.literals : [...options.literals].map(literal => literal.name);

const attempts = new Map<string, Node | null>();

function parseNode(kind: string, parents: string[] = []): Node | null {
if (id) parseInfo.get(id)!.parseNodeCalls++;
if (id) info.parseNodeCalls++;

const depth = parents.length;

Expand Down Expand Up @@ -120,7 +122,7 @@ export function parse(options: ParseOptions): Node[] {
throw `Possible infinite loop: ${loop.join(' -> ')} -> ... at ${node.line}:${node.column}`;
}

if (id) parseInfo.get(id)!.nodesParsed++;
if (id) info.nodesParsed++;

if (literals.includes(kind)) {
const token = tokens[position];
Expand Down

0 comments on commit 5e75f6f

Please sign in to comment.