Skip to content

Fix: empty function call parsing when multiple functions present#328

Merged
rubysolo merged 1 commit intorubysolo:mainfrom
WantToBeeMe:Fix-empty-function-call-parsing-when-multiple-functions-present
Nov 11, 2025
Merged

Fix: empty function call parsing when multiple functions present#328
rubysolo merged 1 commit intorubysolo:mainfrom
WantToBeeMe:Fix-empty-function-call-parsing-when-multiple-functions-present

Conversation

@WantToBeeMe
Copy link
Contributor

@WantToBeeMe WantToBeeMe commented Nov 10, 2025

Purpose of PR

Fixes a parser bug where consecutive empty function calls (e.g., func() + func()) would fail due to incorrect token skipping.
Uses token index-based skipping instead of token lookup to prevent conflicts.

Why it broke

Functions with 0 arguments are consumed immediately, requiring the closing bracket to be skipped. Previously, the code searched the token list for ), which would always just find the first instance, 3.5.5 and prior, it would delete this from the list, which worked fine since than the next closing bracket would become the first.
however, with the update to 3.5.6 instead of deleting this bracket, it now instead saves its index to be skipped, keeping it still in the same location in the list. This causes func1() + func2() to skip the first closing bracket twice.

The Fix

Before we do anything, we always check if the lookahead is a closing bracket.
By doing so, we already confirmed that the next one is a closing backet. So rather than searching the index of this bracket in the list, we can just simply do the current node index + 1

Changes

  • replaced the index search in the tokens list with the current index + 1
    (For this i removed the tokens list from the arguments, since the only use case was to find this index. and now that that is gone, this list is also not needed there anymore)
  • added a test in the parser suite to capture this case

Before & After

Dentaku.evaluate("count() + count()")

Before:
image

After: 0 (this is expected. count() with no arguments returns 0)

@rubysolo rubysolo merged commit 78a2fa3 into rubysolo:main Nov 11, 2025
9 checks passed
@rubysolo
Copy link
Owner

❤️

@rejeep
Copy link

rejeep commented Dec 10, 2025

Thanks for fixing this. Can you please release a new patch version including this?

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.

3 participants