Skip to content

Commit

Permalink
~Fixed incorrect calculation of SyntaxNode start ref
Browse files Browse the repository at this point in the history
  • Loading branch information
AjaniBilby committed Aug 8, 2023
1 parent cc7395f commit 2ae5e42
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
8 changes: 4 additions & 4 deletions dist/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export function MapTreeRefs(tree, str, sharedRef) {
ref: Reference.blank(),
bytes: 0
};
while (stack.length > 0) {
while (true) {
const curr = stack.pop();
if (!curr)
continue;
break;
if (curr.ref === sharedRef) {
// Don't calculate forward progression if not needed
if (cursor.bytes !== curr.end)
ProgressCursor(str, curr.end, cursor);
if (cursor.bytes !== curr.start)
ProgressCursor(str, curr.start, cursor);
curr.ref = new ReferenceRange(cursor.ref.clone(), cursor.ref // no alloc fill in
);
stack.push(curr); // revisit node for ref.end mapping (after children)
Expand Down
5 changes: 5 additions & 0 deletions docs/source/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Version 4.0.5

### Fixes:
- [x] References generated on successful pass not having the correct start reference

## Version 4.0.5

### Fixes:
- [x] Hexadecimal characters weren't encoding correctly (`\x6b` == `k`)
- [x] Reduced changes of wasm infinitely allocating to basically zero (as long as you don't try and parse an infinite string)
Expand Down
16 changes: 8 additions & 8 deletions docs/source/static/dist/bnf-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1794,14 +1794,14 @@ function MapTreeRefs$1(tree, str, sharedRef) {
ref: Reference$1.blank(),
bytes: 0
};
while (stack.length > 0) {
while (true) {
const curr = stack.pop();
if (!curr)
continue;
break;
if (curr.ref === sharedRef) {
// Don't calculate forward progression if not needed
if (cursor.bytes !== curr.end)
ProgressCursor$1(str, curr.end, cursor);
if (cursor.bytes !== curr.start)
ProgressCursor$1(str, curr.start, cursor);
curr.ref = new ReferenceRange$1(cursor.ref.clone(), cursor.ref // no alloc fill in
);
stack.push(curr); // revisit node for ref.end mapping (after children)
Expand Down Expand Up @@ -1956,14 +1956,14 @@ function MapTreeRefs(tree, str, sharedRef) {
ref: Reference.blank(),
bytes: 0
};
while (stack.length > 0) {
while (true) {
const curr = stack.pop();
if (!curr)
continue;
break;
if (curr.ref === sharedRef) {
// Don't calculate forward progression if not needed
if (cursor.bytes !== curr.end)
ProgressCursor(str, curr.end, cursor);
if (cursor.bytes !== curr.start)
ProgressCursor(str, curr.start, cursor);
curr.ref = new ReferenceRange(cursor.ref.clone(), cursor.ref // no alloc fill in
);
stack.push(curr); // revisit node for ref.end mapping (after children)
Expand Down
6 changes: 3 additions & 3 deletions source/wasm/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ function MapTreeRefs(tree: SyntaxNode, str: string, sharedRef: ReferenceRange) {
bytes: 0
};

while (stack.length > 0) {
while (true) {
const curr = stack.pop();
if (!curr) continue;
if (!curr) break;

if (curr.ref === sharedRef) {
// Don't calculate forward progression if not needed
if (cursor.bytes !== curr.end) ProgressCursor(str, curr.end, cursor);
if (cursor.bytes !== curr.start) ProgressCursor(str, curr.start, cursor);

curr.ref = new ReferenceRange(
cursor.ref.clone(),
Expand Down

0 comments on commit 2ae5e42

Please sign in to comment.