Skip to content

fix: allow expressions inside list constructors (GH #135) - #420

Open
toddr-bot wants to merge 2 commits into
mainfrom
koan.toddr.bot/fix-list-expr-parsing
Open

toddr-bot wants to merge 2 commits into
mainfrom
koan.toddr.bot/fix-list-expr-parsing

Conversation

@toddr-bot

Copy link
Copy Markdown
Contributor

What

Expressions with operators (concatenation, arithmetic, comparison, boolean, ternary) now work inside [...] list constructors.

Why

Fixes GH #135. The parser grammar restricted list elements to simple terms (identifiers, literals, numbers), so [ 'foo' _ 'bar' ] threw "unexpected token (_)" and [ 1 + 2 ] threw "unexpected token (+)". The workaround was assigning to a variable first, which was unintuitive.

How

Changed the list production rule in Parser.yp from list term to list expr, allowing any expression as a list element. Regenerated Grammar.pm via yapp. The change introduces 3 additional shift/reduce conflicts in the LALR tables, all correctly resolved by the existing operator precedence declarations. Range syntax [1 .. 5] and space-separated lists [1 2 3] continue to work — the parser greedily consumes operators, so [1 + 2 3] correctly produces [3, 3].

Testing

  • 9 new test cases in t/list.t covering: string concatenation, arithmetic, division, comparison, ternary, variable expressions, NOT, and boolean operators in list constructors
  • Full test suite: 2910 tests pass, 0 regressions

🤖 Generated with Claude Code

@toddr-bot

Copy link
Copy Markdown
Contributor Author

Recreated from #372 (auto-closed when the toddr-bot fork was removed). Original branch is now hosted on this repo.

@toddr

toddr commented May 24, 2026

Copy link
Copy Markdown
Member

@toddr-bot rebase

The parser grammar restricted list elements to simple terms (identifiers,
literals, numbers), rejecting expressions with operators like string
concatenation or arithmetic. Change the list production rule from
`list: list term` to `list: list expr` so that constructs like
`[ 'foo' _ 'bar' ]` and `[ 1 + 2, x * 3 ]` parse correctly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@toddr-bot

Copy link
Copy Markdown
Contributor Author

Rebase with requested adjustments

Branch koan.toddr.bot/fix-list-expr-parsing was rebased onto main and review feedback was applied.

Stats

3 files changed, 4135 insertions(+), 4057 deletions(-)
Actions performed
  • Already-solved check: negative (confidence=high, reasoning=Parser.yp on main still uses 'term' in list production rule; no commit addresses GH Parser can't handle list constructor around string concatenation [rt.cpan.org #117863] #135 or list con)
  • Resolved merge conflicts (1 round(s))
  • Rebased koan.toddr.bot/fix-list-expr-parsing onto origin/main
  • Pre-push CI check: previous run passed
  • Force-pushed koan.toddr.bot/fix-list-expr-parsing to origin
  • CI check enqueued in ## CI (async)

CI status

CI will be checked asynchronously.


Automated by Kōan

@toddr-bot
toddr-bot force-pushed the koan.toddr.bot/fix-list-expr-parsing branch from 749c4a3 to 5d7c357 Compare May 24, 2026 20:32
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.

2 participants