Skip to content

lark grammar fails on nested unary not operators #4564

@cyberthirst

Description

@cyberthirst

Version Information

  • vyper Version (output of vyper --version): 6a00171

What's your issue about?

def test_unary_not(get_contract):
    code = """
@external
def round_trip() -> uint256:
    b: uint256 = empty(uint256)
    return ~~b
    """

    _ = get_contract(code)
self = <lark.lexer.ContextualLexer object at 0x107fc4fe0>
lexer_state = <lark.lexer.LexerState object at 0x11e7b1d80>
parser_state = <lark.parsers.lalr_parser_state.ParserState object at 0x11e7b1e00>

    def lex(self, lexer_state: LexerState, parser_state: 'ParserState') -> Iterator[Token]:
        try:
            while True:
                lexer = self.lexers[parser_state.position]
                yield lexer.next_token(lexer_state, parser_state)
        except EOFError:
            pass
        except UnexpectedCharacters as e:
            # In the contextual lexer, UnexpectedCharacters can mean that the terminal is defined, but not in the current context.
            # This tests the input against the global context, to provide a nicer error.
            try:
                last_token = lexer_state.last_token  # Save last_token. Calling root_lexer.next_token will change this to the wrong token
                token = self.root_lexer.next_token(lexer_state, parser_state)
>               raise UnexpectedToken(token, e.allowed, state=parser_state, token_history=[last_token], terminals_by_name=self.root_lexer.terminals_by_name)
E               lark.exceptions.UnexpectedToken: Unexpected token Token('TILDE', '~') at line 5, column 13.
E               Expected one of: 
E               	* _ABI_DECODE
E               	* OCT_NUMBER
E               	* STATICCALL
E               	* BIN_NUMBER
E               	* EXTCALL
E               	* FLOAT_NUMBER
E               	* ELLIPSIS
E               	* DEC_NUMBER
E               	* STRING
E               	* LSQB
E               	* NAME
E               	* BOOL
E               	* LPAR
E               	* HEX_NUMBER
E               	* EMPTY
E               	* LBRACE
E               	* DOCSTRING
E               	* ABI_DECODE
E               Previous tokens: [Token('TILDE', '~')]

../../../../venv/lib/python3.12/site-packages/lark/lexer.py:674: UnexpectedToken

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions