Skip to content

Commit

Permalink
Merge pull request #68 from robeden/67-nested-lists
Browse files Browse the repository at this point in the history
Update YACC parser to latest, allow lists within lists and other parse fixes
  • Loading branch information
virtuald committed Apr 14, 2020
2 parents 6009357 + f900940 commit 4ac7c5f
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 1,203 deletions.
3 changes: 3 additions & 0 deletions src/hcl/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def isHcl(s):
:returns: True if HCL, False if JSON, raises ValueError
if neither
'''
if not s:
return True

for c in s:
if c.isspace():
continue
Expand Down
16 changes: 14 additions & 2 deletions src/hcl/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,22 @@ def objectlist_flat(self, lt, replace):
return d

def p_top(self, p):
"top : objectlist"
'''
top : empty
| objectlist
'''
if DEBUG:
self.print_p(p)
p[0] = self.objectlist_flat(p[1], True)

def p_empty_0(self, p):
'''
empty :
'''
if DEBUG:
self.print_p(p)
p[0] = []

def p_objectlist_0(self, p):
"objectlist : objectitem"
if DEBUG:
Expand Down Expand Up @@ -419,6 +430,7 @@ def p_listitems_0(self, p):
| function
| object COMMA
| objectkey COMMA
| list COMMA
'''
if DEBUG:
self.print_p(p)
Expand Down Expand Up @@ -624,7 +636,7 @@ def p_error(self, p):

def __init__(self):
self.yacc = yacc.yacc(
module=self, debug=False, optimize=1, picklefile=pickle_file
module=self, debug=False, optimize=1, debugfile=pickle_file
)

def parse(self, s, export_comments=None):
Expand Down

0 comments on commit 4ac7c5f

Please sign in to comment.