Skip to content

Parse command substitution in arithmetic expressions#2

Open
jdiamond wants to merge 1 commit intowebpro-nl:mainfrom
jdiamond:arith-cmd-subst
Open

Parse command substitution in arithmetic expressions#2
jdiamond wants to merge 1 commit intowebpro-nl:mainfrom
jdiamond:arith-cmd-subst

Conversation

@jdiamond
Copy link

@jdiamond jdiamond commented Mar 22, 2026

Hi, this PR addresses #1.

$(cmd) inside arithmetic contexts ($((expr)), ((expr)), for ((…))) was being flattened into an opaque ArithmeticWord.value string. This adds ArithmeticCommandExpansion to the ArithmeticExpression union, with the same inner/script fields used by CommandExpansionPart at the word level.

A few design notes:

  • Resolution of $(cmd) nodes found inside $((expr)) word parts happens in parts.ts to avoid a circular import (parserlexer).
  • The ArithmeticFor path calls resolveArithmeticExpansions after offsetArith so positions are correct before scripts are parsed.
  • The printer uses e.text for roundtrip safety.

Tests cover raw parsing, resolution at all entry points, and roundtrip verification.

Note: adding a member to the ArithmeticExpression union is a breaking change for TypeScript consumers with exhaustive switches — they'll get a compile error until they handle the new case.

Happy to adjust anything!

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.

1 participant