Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hcl2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from lark.tree import Tree
from hcl2.parser import parser, reconstruction_parser
from hcl2.transformer import DictTransformer
from hcl2.dict_transformer import DictTransformer
from hcl2.reconstructor import HCLReconstructor, HCLReverseTransformer


Expand Down
1 change: 1 addition & 0 deletions hcl2/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

START_LINE_KEY = "__start_line__"
END_LINE_KEY = "__end_line__"
IS_BLOCK = "__is_block__"
4 changes: 4 additions & 0 deletions hcl2/transformer.py → hcl2/dict_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ def heredoc_template_trim(self, args: List) -> str:
def new_line_or_comment(self, args: List) -> _DiscardType:
return Discard

# def EQ(self, args: List):
# print("EQ", args)
# return args

def for_tuple_expr(self, args: List) -> str:
args = self.strip_new_line_tokens(args)
for_expr = " ".join([self.to_tf_inline(arg) for arg in args[1:-1]])
Expand Down
4 changes: 2 additions & 2 deletions hcl2/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def parser() -> Lark:
"""Build standard parser for transforming HCL2 text into python structures"""
return Lark.open(
"hcl2.lark",
"rule_transformer/hcl2.lark",
parser="lalr",
cache=str(PARSER_FILE), # Disable/Delete file to effect changes to the grammar
rel_to=__file__,
Expand All @@ -29,7 +29,7 @@ def reconstruction_parser() -> Lark:
if necessary.
"""
return Lark.open(
"hcl2.lark",
"rule_transformer/hcl2.lark",
parser="lalr",
# Caching must be disabled to allow for reconstruction until lark-parser/lark#1472 is fixed:
#
Expand Down
7 changes: 6 additions & 1 deletion hcl2/reconstructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,17 @@ def _should_add_space(self, rule, current_terminal, is_block_label: bool = False
if self._is_equals_sign(current_terminal):
return True

if is_block_label:
pass
# print(rule, self._last_rule, current_terminal, self._last_terminal)

if is_block_label and isinstance(rule, Token) and rule.value == "string":
if (
current_terminal == self._last_terminal == Terminal("DBLQUOTE")
or current_terminal == Terminal("DBLQUOTE")
and self._last_terminal == Terminal("NAME")
and self._last_terminal == Terminal("IDENTIFIER")
):
# print("true")
return True

# if we're in a ternary or binary operator, add space around the operator
Expand Down
Empty file.
Loading
Loading