amplify-education / python-hcl2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot parse file that has two of the same blocks

swarner1033 opened this issue · comments

Getting an exception when trying to parse a file that has two aws providers

provider "aws" {
  region = var.region
  ...
}

provider "aws" {
  region = var.backup_region
  ...
}
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/lark/parsers/lalr_parser_state.py", line 77, in feed_token
    action, arg = states[state][token.type]
                  ~~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: '__ANON_3'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<my file>", line 23, in <module>
    dict = hcl2.load(file)
           ^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/hcl2/api.py", line 14, in load
    return loads(file.read(), with_meta=with_meta)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/hcl2/api.py", line 27, in loads
    tree = hcl2.parse(text + "\n")
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/lark/lark.py", line 658, in parse
    return self.parser.parse(text, start=start, on_error=on_error)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/lark/parser_frontends.py", line 104, in parse
    return self.parser.parse(stream, chosen_start, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/lark/parsers/lalr_parser.py", line 42, in parse
    return self.parser.parse(lexer, start)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/lark/parsers/lalr_parser.py", line 88, in parse
    return self.parse_from_state(parser_state)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/lark/parsers/lalr_parser.py", line 111, in parse_from_state
    raise e
  File "/opt/homebrew/lib/python3.11/site-packages/lark/parsers/lalr_parser.py", line 102, in parse_from_state
    state.feed_token(token)
  File "/opt/homebrew/lib/python3.11/site-packages/lark/parsers/lalr_parser_state.py", line 80, in feed_token
    raise UnexpectedToken(token, expected, state=self, interactive_parser=None)
lark.exceptions.UnexpectedToken: Unexpected token Token('__ANON_3', 'Cell') at line 20, column 7.
Expected one of:
	* PERCENT
	* PLUS
	* MORETHAN
	* __ANON_4
	* __ANON_0
	* __ANON_6
	* LESSTHAN
	* __ANON_2
	* __ANON_5
	* __ANON_9
	* MINUS
	* QMARK
	* SLASH
	* STAR
	* __ANON_7
	* __ANON_1
	* COMMA
	* RBRACE
	* __ANON_8

Versions

Python 3.11.7
pip 24.0 from /opt/homebrew/lib/python3.11/site-packages/pip (python 3.11)
python-hcl2     4.3.2

Was actually #140