Skip to content

Base prefix before a simple expansion, $((10#$n)), produces an ERROR node #351

Open

Description

@DeusData

Thanks for tree-sitter-bash, and for keeping it maintained!

A base prefix followed by a simple (unbraced) expansion inside arithmetic produces an ERROR node:

echo $((10#$n))

Actual tree (at a06c2e4415e9):

(program (command name: (command_name (word))
  argument: (arithmetic_expansion (ERROR) (simple_expansion (variable_name)))))

The braced form and a literal both parse clean:

  • echo $((10#${n})) gives (arithmetic_expansion (number (expansion (variable_name))))
  • echo $((10#5)) gives (arithmetic_expansion (number))

Expected: 10#$n should be a number wrapping a simple_expansion, the same way the braced form wraps an expansion:

(arithmetic_expansion (number (simple_expansion (variable_name))))

$((10#$n)) is the standard idiom for making bash read a zero-padded value (08, 09) as decimal, so it turns up often in date and version handling.

Found while indexing with codebase-memory-mcp (DeusData/codebase-memory-mcp#2078).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions