Skip to content

Commit 5ccfa65

Browse files
* HCLReconstructor._reconstruct_token - handle 0 length tokens
* FunctionCallRule.serialize - properly serialize into dollar string * remove unused import
1 parent 107fcb2 commit 5ccfa65

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

hcl2/rule_transformer/reconstructor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ def _reconstruct_token(self, token: Token, parent_rule_name: str = None) -> str:
167167
result = " " + result
168168

169169
self._last_token_name = token.type
170-
self._last_was_space = result[-1].endswith(" ") or result[-1].endswith("\n")
170+
if len(token) != 0:
171+
self._last_was_space = result[-1].endswith(" ") or result[-1].endswith("\n")
171172

172173
return result
173174

hcl2/rule_transformer/rules/containers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
from typing import Tuple, List, Optional, Union, Any
32

43
from hcl2.rule_transformer.rules.abstract import LarkRule

hcl2/rule_transformer/rules/functions.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,9 @@ def arguments(self) -> Optional[ArgumentsRule]:
8989
def serialize(
9090
self, options=SerializationOptions(), context=SerializationContext()
9191
) -> Any:
92-
result = f"{'::'.join(identifier.serialize(options, context) for identifier in self.identifiers)}"
93-
result += (
94-
f"({self.arguments.serialize(options, context) if self.arguments else ''})"
95-
)
92+
with context.modify(inside_dollar_string=True):
93+
result = f"{'::'.join(identifier.serialize(options, context) for identifier in self.identifiers)}"
94+
result += f"({self.arguments.serialize(options, context) if self.arguments else ''})"
9695

9796
if not context.inside_dollar_string:
9897
result = to_dollar_string(result)

0 commit comments

Comments
 (0)