diff --git a/hcl2/parser.py b/hcl2/parser.py index 276a69f..b83b600 100644 --- a/hcl2/parser.py +++ b/hcl2/parser.py @@ -42,7 +42,7 @@ def strip_line_comment(line: str) -> tuple[str, str, str] | tuple[str, None, Non class Hcl2: """Wrapper class for Lark""" - lark_parser = Lark(grammar=LARK_GRAMMAR, parser="lalr", propagate_positions=True, cache=True) + lark_parser = Lark(grammar=LARK_GRAMMAR, parser="lalr", propagate_positions=True, cache=True, regex=True) def parse(self, text: str) -> dict[str, list[dict[str, Any]]]: """Parses a HCL file and returns a dict""" diff --git a/requirements.txt b/requirements.txt index 44325d0..ec43590 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ # http://docs.python.org/2/distutils/setupscript.html#relationships-between-distributions-and-packages lark>=1.0.0 importlib-resources>=2.0.0,<7.0.0; python_version < '3.9' +regex==2024.9.11 diff --git a/test/helpers/terraform-config/bad_regex.tf b/test/helpers/terraform-config/bad_regex.tf new file mode 100644 index 0000000..3414e6e --- /dev/null +++ b/test/helpers/terraform-config/bad_regex.tf @@ -0,0 +1,9 @@ +resource "aws_glue_connection" "example" { + name = "example-connection" + connection_properties = { + startswith(each.value.connection_properties[x], "$${abcded:" + + +variable "connection_properties" { + +} \ No newline at end of file diff --git a/test/unit/test_load.py b/test/unit/test_load.py index 1680b8a..ecf6ef8 100644 --- a/test/unit/test_load.py +++ b/test/unit/test_load.py @@ -40,7 +40,7 @@ def _load_test_files(self): hcl2.load(hcl2_file) self.fail("Should throw parsing error for file") except Exception as err: - if not str(err).startswith('Line has unclosed quote marks'): + if not str(err).startswith('Line has unclosed quote marks') and not str(err).startswith('No terminal matches'): self.fail(f'Got an unexpected error, {err}') else: with open(file_path, 'r', encoding='utf8') as hcl2_file, \