We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ff06e94 commit fa8953bCopy full SHA for fa8953b
2 files changed
hcl2/hcl2.lark
@@ -61,11 +61,12 @@ STRING_CHARS : /(?:(?!\${)([^"\\]|\\.))+/ // any character except '"'
61
string_with_interpolation: "\"" (STRING_CHARS)* interpolation_maybe_nested (STRING_CHARS | interpolation_maybe_nested)* "\""
62
interpolation_maybe_nested: "${" expression "}"
63
64
-int_lit : DECIMAL+
65
-!float_lit: DECIMAL+ "." DECIMAL+ (EXP_MARK DECIMAL+)?
66
- | DECIMAL+ ("." DECIMAL+)? EXP_MARK DECIMAL+
+int_lit : NEGATIVE_DECIMAL? DECIMAL+ | NEGATIVE_DECIMAL+
+!float_lit: (NEGATIVE_DECIMAL? DECIMAL+ | NEGATIVE_DECIMAL+) "." DECIMAL+ (EXP_MARK)?
+ | (NEGATIVE_DECIMAL? DECIMAL+ | NEGATIVE_DECIMAL+) ("." DECIMAL+)? (EXP_MARK)
67
+NEGATIVE_DECIMAL : "-" DECIMAL
68
DECIMAL : "0".."9"
-EXP_MARK : ("e" | "E") ("+" | "-")?
69
+EXP_MARK : ("e" | "E") ("+" | "-")? DECIMAL+
70
EQ : /[ \t]*=(?!=|>)/
71
72
tuple : "[" (new_line_or_comment* expression new_line_or_comment* ",")* (new_line_or_comment* expression)? new_line_or_comment* "]"
test/unit/test_hcl2_syntax.py
@@ -72,7 +72,7 @@ def test_block_multiple_labels(self):
73
def test_unary_operation(self):
74
operations = [
75
- ("identifier = -10", {"identifier": "${-10}"}),
+ ("identifier = -10", {"identifier": -10}),
76
("identifier = !true", {"identifier": "${!true}"}),
77
]
78
for hcl, dict_ in operations:
@@ -151,3 +151,16 @@ def test_index(self):
151
for call, expected in indexes.items():
152
result = self.load_to_dict(call)
153
self.assertDictEqual(result, expected)
154
+
155
+ def test_e_notation(self):
156
+ literals = {
157
+ "var = 3e4": {"var": 30000.0},
158
+ "var = 3.5e5": {"var": 350000.0},
159
+ "var = -3e6": {"var": -3e6},
160
+ "var = -2.3e4": {"var": -2.3e4},
161
+ "var = -5e-2": {"var": -5e-2},
162
+ "var = -6.1e-3": {"var": -6.1e-3},
163
+ }
164
+ for actual, expected in literals.items():
165
+ result = self.load_to_dict(actual)
166
+ self.assertDictEqual(result, expected)
0 commit comments