Skip to content
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

Command substitution #50

Open
sereysethy opened this issue Aug 21, 2019 · 1 comment
Open

Command substitution #50

sereysethy opened this issue Aug 21, 2019 · 1 comment

Comments

@sereysethy
Copy link

Hi,
I was about to make a pull request for a command substitution that returned a wrong position when there are spaces in the commands in the command substitution $(foo ). But then I discovered another problem and I couldnt find how to fix it. It is when there is a semi column in the list of commands, parsing failed.

Ex: parsing this command failed $(foo;). I got this error. Can you tell me where the problem lies? It is a list, but I couldnt find where to fix it. It does not happen with another form of command subsitution `command;`. I know they are treated differently in parser.

File "python3.6/site-packages/bashlex/parser.py", line 605, in parse
	    parts = [p.parse()]
	  File "python3.6/site-packages/bashlex/parser.py", line 686, in parse
	    tree = theparser.parse(lexer=self.tok, context=self)
	  File "python3.6/site-packages/bashlex/yacc.py", line 277, in parse
	    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc,context)
	  File "python3.6/site-packages/bashlex/yacc.py", line 998, in parseopt_notrack
	    p.callable(pslice)
	  File "python3.6/site-packages/bashlex/parser.py", line 157, in p_simple_command_element
	    p[0] = [_expandword(parserobj, p.slice[1])]
	  File "python3.6/site-packages/bashlex/parser.py", line 137, in _expandword
	    doublequoted, 0, 0)
	  File "python3.6/site-packages/bashlex/subst.py", line 271, in _expandwordinternal
	    node, sindex[0] = _paramexpand(parserobj, string, sindex[0])
	  File "python3.6/site-packages/bashlex/subst.py", line 165, in _paramexpand
	    return _extractcommandsubst(parserobj, string, zindex + 1)
	  File "python3.6/site-packages/bashlex/subst.py", line 55, in _extractcommandsubst
	    node, si = _parsedolparen(parserobj, string, sindex)
	  File "python3.6/site-packages/bashlex/subst.py", line 42, in _parsedolparen
	    node, endp = _recursiveparse(parserobj, base, sindex, tokenizerargs)
	  File "python3.6/site-packages/bashlex/subst.py", line 23, in _recursiveparse
	    node = p.parse()
	  File "python3.6/site-packages/bashlex/parser.py", line 686, in parse
	    tree = theparser.parse(lexer=self.tok, context=self)
	  File "python3.6/site-packages/bashlex/yacc.py", line 277, in parse
	    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc,context)
	  File "python3.6/site-packages/bashlex/yacc.py", line 1079, in parseopt_notrack
	    tok = self.errorfunc(errtoken)
	  File "python3.6/site-packages/bashlex/parser.py", line 543, in p_error
	    p.lexer.source, p.lexpos)
	bashlex.errors.ParsingError: unexpected token ')' (position 4)
@idank
Copy link
Owner

idank commented Aug 24, 2019

Command substitutions are parsed recursively. The code that handles this is in bashlex/subst.py, see _recursiveparse. I'd try debugging it and putting a breakpoint in that function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants