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

heredoc parsing in function cause strange extra results #36

Open
bamanzi opened this issue Dec 21, 2018 · 0 comments
Open

heredoc parsing in function cause strange extra results #36

bamanzi opened this issue Dec 21, 2018 · 0 comments

Comments

@bamanzi
Copy link

bamanzi commented Dec 21, 2018

for the code as following

code = '''cat << EOF
abc
def
EOF'''
ret = bashlex.parse(code)
print(ret[0].dump())

we got:

CommandNode(pos=(0, 9), parts=[
  WordNode(pos=(0, 3), word='cat'),
  RedirectNode(heredoc=
    HeredocNode(pos=(10, 21), value='abc\ndef\nEOF'), output=
    WordNode(pos=(6, 9), word='EOF'), pos=(4, 21), type='<<'),
])

that's fine so far.

but for the code:

code = '''function foo () {
cat << EOF
abc
def
EOF
}'''
ret = bashlex.parse(code)
print(ret[0].dump())

we got:

FunctionNode(pos=(0, 40), parts=[
  ReservedwordNode(pos=(0, 8), word='function'),
  WordNode(pos=(9, 12), word='foo'),
  ReservedwordNode(pos=(12, 13), word='('),
  ReservedwordNode(pos=(13, 14), word=')'),
  CompoundNode(list=[
    ReservedwordNode(pos=(15, 16), word='{'),
    ListNode(pos=(17, 39), parts=[
        CommandNode(pos=(17, 26), parts=[
          WordNode(pos=(17, 20), word='cat'),
          RedirectNode(heredoc=
            HeredocNode(pos=(31, 38), value='def\nEOF'), output=
            WordNode(pos=(23, 26), word='EOF'), pos=(21, 26), type='<<'),
        ]),
        OperatorNode(op='\n', pos=(26, 27)),
        CommandNode(pos=(27, 30), parts=[
          WordNode(pos=(27, 30), word='abc'),
        ]),
        OperatorNode(op='\n', pos=(30, 39)),
      ]),
    ReservedwordNode(pos=(39, 40), word='}'),
  ], pos=(15, 40)),
])

in this case, abc no longer a part of the heredoc, but came out as a standalone CommandNode.

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

1 participant