Skip to content

Issues with parsing && and || #83

Description

@danny-burrows

While following seems to parse just fine:

foo && bar

However when I try to parse this:

foobar=$(foo && bar)

I get the following error:

bashlex.errors.ParsingError: unexpected token ')' (position 10)

The same goes for ||.

Full Traceback

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/___/.local/lib/python3.11/site-packages/bashlex/parser.py", line 610, in parse
    parts = [p.parse()]
             ^^^^^^^^^
  File "/home/___/.local/lib/python3.11/site-packages/bashlex/parser.py", line 691, in parse
    tree = theparser.parse(lexer=self.tok, context=self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/___/.local/lib/python3.11/site-packages/bashlex/yacc.py", line 439, in parse
    p.callable(pslice)
  File "/home/___/.local/lib/python3.11/site-packages/bashlex/parser.py", line 167, in p_simple_command_element
    p[0] = [_expandword(parserobj, p.slice[1])]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/___/.local/lib/python3.11/site-packages/bashlex/parser.py", line 145, in _expandword
    parts, expandedword = subst._expandwordinternal(parser,
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/___/.local/lib/python3.11/site-packages/bashlex/subst.py", line 271, in _expandwordinternal
    node, sindex[0] = _paramexpand(parserobj, string, sindex[0])
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/___/.local/lib/python3.11/site-packages/bashlex/subst.py", line 165, in _paramexpand
    return _extractcommandsubst(parserobj, string, zindex + 1)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/___/.local/lib/python3.11/site-packages/bashlex/subst.py", line 55, in _extractcommandsubst
    node, si = _parsedolparen(parserobj, string, sindex)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/___/.local/lib/python3.11/site-packages/bashlex/subst.py", line 42, in _parsedolparen
    node, endp = _recursiveparse(parserobj, base, sindex, tokenizerargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/___/.local/lib/python3.11/site-packages/bashlex/subst.py", line 23, in _recursiveparse
    node = p.parse()
           ^^^^^^^^^
  File "/home/___/.local/lib/python3.11/site-packages/bashlex/parser.py", line 691, in parse
    tree = theparser.parse(lexer=self.tok, context=self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/___/.local/lib/python3.11/site-packages/bashlex/yacc.py", line 537, in parse
    tok = self.errorfunc(errtoken)
          ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/___/.local/lib/python3.11/site-packages/bashlex/parser.py", line 548, in p_error
    raise errors.ParsingError('unexpected token %r' % p.value,
bashlex.errors.ParsingError: unexpected token ')' (position 10)

Hope this helps, thanks!

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions