Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot parse file that has two of the same blocks #150

Closed
swarner1033 opened this issue Feb 13, 2024 · 1 comment
Closed

Cannot parse file that has two of the same blocks #150

swarner1033 opened this issue Feb 13, 2024 · 1 comment

Comments

@swarner1033
Copy link

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
@swarner1033
Copy link
Author

Was actually #140

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant