Skip to content

Structure lists given at the uppermost level break pyhcl #11

Description

@saj

Hashicorp's HCL parser for Go will accept input like the the following:

foo {
    key = 7
}
foo {
    key = 12
}

pyhcl 0.2.1 barfs when given the same input:

>>> s = """foo {
...     key = 7
... }
... foo {
...     key = 12
... }"""
>>> hcl.loads(s)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/private/var/folders/hm/lxv5j0v12sj17drqtymbxcyh0000gn/T/tmpbOqahU/.deps/pyhcl-0.2.1-py2-none-any.whl/hcl/api.py", line 62, in loads
    return HclParser().parse(s)
  File "/private/var/folders/hm/lxv5j0v12sj17drqtymbxcyh0000gn/T/tmpbOqahU/.deps/pyhcl-0.2.1-py2-none-any.whl/hcl/parser.py", line 293, in parse
    return self.yacc.parse(s, lexer=Lexer())
  File "/private/var/folders/hm/lxv5j0v12sj17drqtymbxcyh0000gn/T/tmpbOqahU/.deps/ply-3.4-py2-none-any.whl/ply/yacc.py", line 265, in parse
    return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
  File "/private/var/folders/hm/lxv5j0v12sj17drqtymbxcyh0000gn/T/tmpbOqahU/.deps/ply-3.4-py2-none-any.whl/ply/yacc.py", line 971, in parseopt_notrack
    p.callable(pslice)
  File "/private/var/folders/hm/lxv5j0v12sj17drqtymbxcyh0000gn/T/tmpbOqahU/.deps/pyhcl-0.2.1-py2-none-any.whl/hcl/parser.py", line 89, in p_top
    p[0] = self.objectlist_flat(p[1],True)
  File "/private/var/folders/hm/lxv5j0v12sj17drqtymbxcyh0000gn/T/tmpbOqahU/.deps/pyhcl-0.2.1-py2-none-any.whl/hcl/parser.py", line 76, in objectlist_flat
    for k2, v2 in iteritems(vv):
  File "/private/var/folders/hm/lxv5j0v12sj17drqtymbxcyh0000gn/T/tmpbOqahU/.deps/pyhcl-0.2.1-py2-none-any.whl/hcl/parser.py", line 27, in iteritems
    return iter(d.iteritems())
AttributeError: 'int' object has no attribute 'iteritems'

I noticed the unit test for this case is currently commented out.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions