idank / bashlex

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

space at the end of line - parse error #55

Open bAndie91 opened 4 years ago

bAndie91 commented 4 years ago
>>> bashlex.parse('cmd1\ncmd2 \ncmd3\n')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "bashlex/parser.py", line 614, in parse
    part = _parser(s[index:], strictmode=strictmode).parse()
  File "bashlex/parser.py", line 682, in parse
    tree = theparser.parse(lexer=self.tok, context=self)
  File "bashlex/yacc.py", line 277, in parse
    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc,context)
  File "bashlex/yacc.py", line 1079, in parseopt_notrack
    tok = self.errorfunc(errtoken)
  File "bashlex/parser.py", line 539, in p_error
    p.lexer.source, p.lexpos)
bashlex.errors.ParsingError: unexpected token 'cmd3' (position 1)
samlikins commented 1 year ago

I was unable to reproduce this issue using version 0.18.

idank commented 1 year ago

Hey, thanks for going over these issues. It would be extra awesome if you could add a test case that shows these parse correctly.

samlikins commented 1 year ago

@idank: Absolutely!

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('cmd1\ncmd2 \ncmd3\n')
[CommandNode(parts=[WordNode(parts=[] pos=(0, 4) word='cmd1')] pos=(0, 4)), CommandNode(parts=[WordNode(parts=[] pos=(5, 9) word='cmd2')] pos=(5, 9)), CommandNode(parts=[WordNode(parts=[] pos=(11, 15) word='cmd3')] pos=(11, 15))]