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

"No terminal matches '|' in the current parser context" when parsing multi-line conditional #142

Open
xRokco opened this issue Jul 31, 2023 · 0 comments

Comments

@xRokco
Copy link

xRokco commented Jul 31, 2023

I have the following Terraform local:

my_local = {
    for k, v in local.map_a : k => v
    if lookup(local.map_b[v.id], "enabled", false)
    || (
      contains(local.map_c, v.id)
      && contains(local.map_d, v.id)
    )
  }

It returns the following error when I attempt to parse the file:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/lark/lexer.py", line 590, in lex
    yield lexer.next_token(lexer_state, parser_state)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/lark/lexer.py", line 528, in next_token
    raise UnexpectedCharacters(lex_state.text, line_ctr.char_pos, line_ctr.line, line_ctr.column,
lark.exceptions.UnexpectedCharacters: No terminal matches '|' in the current parser context, at line 20 col 5
    || (
    ^
Expected one of:
    * /<<(?P<heredoc>[a-zA-Z][a-zA-Z0-9._-]+)\n(?:.|\n)*?(?P=heredoc)/
    * BANG
    * /#.*\n/
    * COLON
    * RSQB
    * /[a-zA-Z_][a-zA-Z0-9_-]*/
    * LBRACE
    * STRING_LIT
    * RBRACE
    * DECIMAL
    * LSQB
    * /\n/
    * /<<-(?P<heredoc_trim>[a-zA-Z][a-zA-Z0-9._-]+)\n(?:.|\n)*?(?P=heredoc_trim)/
    * MINUS
    * /\/\/.*\n/
    * LPAR
    * COMMA
    * RPAR
Previous tokens: Token('__ANON_0', '\n')

I can fix this by moving the entire local on to a single line, or adjusting it like this:

my_local = {
    for k, v in local.map_a : k => v
    if lookup(local.map_b[v.id], "enabled", false) || (
      contains(local.map_c, v.id) && (
      contains(local.map_d, v.id))
    )
  }

Seems like as long as I put || or && at the start or end of a line it produces this error.

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