Skip to content

Commit

Permalink
Allow files containing only comments
Browse files Browse the repository at this point in the history
  • Loading branch information
robeden committed Apr 14, 2020
1 parent 778fc27 commit 3cbb16f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
13 changes: 12 additions & 1 deletion 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
3 changes: 3 additions & 0 deletions tests/fixtures/only_comments.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This is an empty file, except for a comment.

# Another comment
1 change: 1 addition & 0 deletions tests/fixtures/only_comments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions tests/test_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
('function.hcl', 'function.json', None),
('multiline_bad.hcl', 'multiline.json', None),
('nested_lists.hcl', 'nested_lists.json', None),
('only_comments.hcl', 'only_comments.json', None),
('scientific.hcl', 'scientific.json', None),
('structure.hcl', 'structure_flat.json', None),
#('structure2.hcl', 'structure2.json', None), # not in the golang tests
Expand Down

0 comments on commit 3cbb16f

Please sign in to comment.