Skip to content

Can not parse file that has "in" attribute #148

Closed

Description

@aston-r

Hi,

STR:

  • create the tf file with context:
resource "aws_api_gateway_rest_api" "example" {

  body = jsonencode({
	security_definitions = {
		sigv4 = {
		  type                         = "apiKey"
		  name                         = "Authorization"
		  in                           = "header"
		  x-amazon-apigateway-authtype = "awsSigv4"
		}
	  }
  })
}

Actual Result:

  File "/usr/local/lib/python3.12/site-packages/hcl2/api.py", line 14, in load
    return loads(file.read(), with_meta=with_meta)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/hcl2/api.py", line 27, in loads
    tree = hcl2.parse(text + "\n")
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/lark/lark.py", line 658, in parse
    return self.parser.parse(text, start=start, on_error=on_error)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/lark/parser_frontends.py", line 104, in parse
    return self.parser.parse(stream, chosen_start, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/lark/parsers/lalr_parser.py", line 42, in parse
    return self.parser.parse(lexer, start)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/lark/parsers/lalr_parser.py", line 88, in parse
    return self.parse_from_state(parser_state)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/lark/parsers/lalr_parser.py", line 111, in parse_from_state
    raise e
  File "/usr/local/lib/python3.12/site-packages/lark/parsers/lalr_parser.py", line 102, in parse_from_state
    state.feed_token(token)
  File "/usr/local/lib/python3.12/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('IN', 'in') at line 32, column 7.
Expected one of:
	* BANG
	* MINUS
	* __ANON_3
	* STRING_LIT
	* DECIMAL
	* LBRACE
	* LPAR
	* LSQB
	* __ANON_11
	* RBRACE
	* __ANON_10

Activity

  1. jqcorreia commented on Jun 14, 2024

    @jqcorreia

    Upon testing this in https://www.lark-parser.org/ide/ changing the parser to Earley seems to not have this error. Being mostly ignorant in this topic, is there any reason to use a specific parser?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions