Skip to content

Parsing a multi-line multi-conditional expression causes exception - Unexpected token Token('QMARK', '?') #269

@mvn187

Description

@mvn187

Describe the bug

A clear and concise description of what the bug is.
similar to #77 but with "multi conditionals"
If you have multiple condition checks over multiple lines you get an UnexpectedToken Error

If you write it all in one line it does not throw the error e.g.
foo = (bar ? baz(foo) : foo == "bar" ? "baz" : foo)

Software:

  • OS: [macOS / Windows / Linux]
VERSION_ID="15.5"
PRETTY_NAME="SUSE Linux Enterprise Server 15 SP5"
  • Python version Python 3.11.10
  • python-hcl2 version
pip show python-hcl2                        
Name: python-hcl2
Version: 7.3.1
Summary: A parser for HCL2
Home-page: https://github.com/amplify-education/python-hcl2

Snippet of HCL2 code causing the unexpected behaviour:

locals {
  foo = (
    bar
    ? baz(foo)
    : foo == "bar"
    ? "baz"
    : foo
  )
}

Expected behavior
No Error

A clear and concise description of what you expected to happen, e.g. python dictionary or JSON you expected to receive as a result of parsing.

Exception traceback (if applicable):

self = <lark.parsers.lalr_parser_state.ParserState object at 0xffffb5201140>, token = Token('QMARK', '?'), is_end = False

    def feed_token(self, token: Token, is_end=False) -> Any:
        state_stack = self.state_stack
        value_stack = self.value_stack
        states = self.parse_conf.states
        end_state = self.parse_conf.end_state
        callbacks = self.parse_conf.callbacks
    
        while True:
            state = state_stack[-1]
            try:
                action, arg = states[state][token.type]
            except KeyError:
                expected = {s for s in states[state].keys() if s.isupper()}
>               raise UnexpectedToken(token, expected, state=self, interactive_parser=None)
E               lark.exceptions.UnexpectedToken: Unexpected token Token('QMARK', '?') at line 11, column 5.
E               Expected one of: 
E                       * RPAR

/usr/local/lib/python3.11/site-packages/lark/parsers/lalr_parser_state.py:80: UnexpectedToken

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions