idank / bashlex

Python parser for bash
GNU General Public License v3.0
550 stars 94 forks source link

[request] Add support for local, global, and export #72

Open BlankCanvasStudio opened 2 years ago

BlankCanvasStudio commented 2 years ago

If an assign statement is used after local, global, and export it is treated as a word node, not an assignment node.

curtisforrester commented 1 year ago

Agree. I often will declare functions as:

foo() {
  local key="$1"
  local value="$2"
  # Do the "needful"
}
samlikins commented 1 year ago

I was unable to reproduce an issue with local, global, or export using version 0.18.

samlikins commented 1 year ago

In a Python interactive session (using bashlex v0.18):

Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bashlex
>>> bashlex.parse('local key=1')
[CommandNode(parts=[WordNode(parts=[] pos=(0, 5) word='local'), WordNode(parts=[] pos=(6, 11) word='key=1')] pos=(0, 11))]
>>> bashlex.parse('global key=1')
[CommandNode(parts=[WordNode(parts=[] pos=(0, 6) word='global'), WordNode(parts=[] pos=(7, 12) word='key=1')] pos=(0, 12))]
>>> bashlex.parse('export key=1')
[CommandNode(parts=[WordNode(parts=[] pos=(0, 6) word='export'), WordNode(parts=[] pos=(7, 12) word='key=1')] pos=(0, 12))]