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

Unexpected token exception on empty heredoc #101

Closed
KetchupBomb opened this issue Aug 25, 2022 · 0 comments · Fixed by #117
Closed

Unexpected token exception on empty heredoc #101

KetchupBomb opened this issue Aug 25, 2022 · 0 comments · Fixed by #117

Comments

@KetchupBomb
Copy link

File content for foo.tf:

foo = <<EOF
Hello world
EOF

File content for bar.tf:

bar = <<EOF
EOF

Parsing with both hcl and hcl2:

>>> import hcl as hcl1
>>> import hcl2

>>> hcl1.load(open("foo.tf"))
{'foo': 'Hello world'}

>>> hcl1.load(open("bar.tf"))
{'bar': ''}

>>> hcl2.load(open("foo.tf"))
{'foo': 'Hello world'}

>>> hcl2.load(open("bar.tf"))
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/lark/parsers/lalr_parser.py", line 59, in get_action
    return states[state][token.type]
KeyError: 'LESSTHAN'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/hcl2/api.py", line 9, in load
    return loads(file.read())
  File "/usr/local/lib/python3.9/site-packages/hcl2/api.py", line 18, in loads
    return hcl2.parse(text + "\n")
  File "/usr/local/lib/python3.9/site-packages/lark/lark.py", line 464, in parse
    return self.parser.parse(text, start=start)
  File "/usr/local/lib/python3.9/site-packages/lark/parser_frontends.py", line 115, in parse
    return self._parse(token_stream, start)
  File "/usr/local/lib/python3.9/site-packages/lark/parser_frontends.py", line 63, in _parse
    return self.parser.parse(input, start, *args)
  File "/usr/local/lib/python3.9/site-packages/lark/parsers/lalr_parser.py", line 35, in parse
    return self.parser.parse(*args)
  File "/usr/local/lib/python3.9/site-packages/lark/parsers/lalr_parser.py", line 88, in parse
    action, arg = get_action(token)
  File "/usr/local/lib/python3.9/site-packages/lark/parsers/lalr_parser.py", line 66, in get_action
    raise UnexpectedToken(token, expected, state=state, puppet=puppet)
lark.exceptions.UnexpectedToken: Unexpected token Token('LESSTHAN', '<') at line 1, column 7.
Expected one of: 
        * LSQB
        * BANG
        * MINUS
        * __ANON_3
        * LBRACE
        * LPAR
        * __ANON_11
        * STRING_LIT
        * DECIMAL
        * __ANON_10

This seems like valid HCL, both in theory and in practice with HCL1, so it appears to be an HCL2 (only) bug.

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

Successfully merging a pull request may close this issue.

1 participant