Open nickdiego opened 6 years ago
The issue was not fully documented, so not certain what string was used which caused the issue. Based on the description, I've attempted to provide several iterations of comment strings.
In a Python interactive session with the following setup:
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('# comment')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/.local/lib/python3.10/site-packages/bashlex/parser.py", line 620, in parse
ef.visit(parts[-1])
File "/home/user/.local/lib/python3.10/site-packages/bashlex/ast.py", line 38, in visit
k = n.kind
AttributeError: 'str' object has no attribute 'kind'. Did you mean: 'find'?
A comment on it's own fails with this error, adding space before it fails also:
>>> bashlex.parse(' # comment')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/.local/lib/python3.10/site-packages/bashlex/parser.py", line 620, in parse
ef.visit(parts[-1])
File "/home/user/.local/lib/python3.10/site-packages/bashlex/ast.py", line 38, in visit
k = n.kind
AttributeError: 'str' object has no attribute 'kind'. Did you mean: 'find'?
>>> bashlex.parse('\t# comment')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/.local/lib/python3.10/site-packages/bashlex/parser.py", line 620, in parse
ef.visit(parts[-1])
File "/home/user/.local/lib/python3.10/site-packages/bashlex/ast.py", line 38, in visit
k = n.kind
Comments after commands don't fail:
>>> bashlex.parse('STRING="string with" # comment')
[CommandNode(parts=[AssignmentNode(parts=[] pos=(0, 20) word='STRING=string with')] pos=(0, 20))]
Comments starting on new lines after commands don't fail:
>>> bashlex.parse('STRING="string with"\n# comment')
[CommandNode(parts=[AssignmentNode(parts=[] pos=(0, 20) word='STRING=string with')] pos=(0, 20))]
>>> bashlex.parse('STRING="string with" \
... \
... # comment')
[CommandNode(parts=[AssignmentNode(parts=[] pos=(0, 20) word='STRING=string with')] pos=(0, 20))]
I'm using
bashlex
to parse build log files to extract compilation commands. I've just realized that when single line strings with comments are passed to the parser, it fails raising the exception below:Patch coming..