Skip to content

Add expansion positions in quote-removed words - #102

Open
joerick wants to merge 1 commit into
idank:masterfrom
joerick:expansion-word-positions
Open

joerick wants to merge 1 commit into
idank:masterfrom
joerick:expansion-word-positions

Conversation

@joerick

@joerick joerick commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Hey idank!

An issue cropped up in cibuildwheel that was easier to fix with a feature in bashlex, I hope that's okay, the issue is that if I do

parser.parsesingle(r'echo \$X$X')

I get back-

CommandNode(pos=(0, 10), parts=[
  WordNode(pos=(0, 4), word='echo'),
  WordNode(pos=(5, 10), word='$X$X', parts=[
    ParameterNode(pos=(8, 10), value='X'),
  ]),
])

The problem is that I don't know how to substitute $X into the second word. Up until now we've been using str.replace("$X", "value"), but for this example, it doesn't work.

This PR adds a wordpos attribute-

CommandNode(pos=(0, 10), parts=[
  WordNode(pos=(0, 4), word='echo'),
  WordNode(pos=(5, 10), word='$X$X', parts=[
    ParameterNode(pos=(8, 10), value='X', wordpos=(2, 4)),
  ]),
])

Which indexes the word so the parameter references the exact position in the string.

AI disclosure- I used Astra/Codex for writing the code, I reviewed/edited and I wrote the PR.

Xref pypa/cibuildwheel#3041

@joerick joerick mentioned this pull request Nov 18, 2026
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