Skip to content

Fix an error in the code generator for "repeated" node#365

Merged
hildjj merged 1 commit intopeggyjs:mainfrom
Mingun:fix-364
Mar 2, 2023
Merged

Fix an error in the code generator for "repeated" node#365
hildjj merged 1 commit intopeggyjs:mainfrom
Mingun:fix-364

Conversation

@Mingun
Copy link
Copy Markdown
Member

@Mingun Mingun commented Mar 2, 2023

The problem only with repeated expressions with delimiter. We cannot use the same bytecode for the 1st and the others repetitions, because after the first element the saved position is present in the variables stack. The stack in the append loop looks like:

stack: [arr]
stack: [arr element]
stack: [arr+] -- append the first element

Start loop
stack: [arr pos] -- this `pos` shifts all external label indexes in `expression` by 1
stack: [arr pos delimiter]
stack: [arr pos delimiter element]
stack: [arr+] -- append the others elements
Go to start of loop

Fixes #364.

The 1st and the others expressions should have different offsets to the variable stack.
The 2nd and more should skip the delimiter in stack
@hildjj hildjj merged commit 6066dbf into peggyjs:main Mar 2, 2023
@Mingun Mingun deleted the fix-364 branch January 1, 2024 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug in repetitions

2 participants