-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fail to parse single line string with comment #32
Comments
Signed-off-by: Nick Diego Yamane <nick@diegoyam.com>
- Reported and patch sent upstream: idank/bashlex#32 idank/bashlex#33 - Revert this patch once it's merged Signed-off-by: Nick Diego Yamane <nick@diegoyam.com>
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..
The text was updated successfully, but these errors were encountered: