Skip to content

Unexpected token with no matched text at the end of tokenstream #5

@LakshyAAAgrawal

Description

@LakshyAAAgrawal

Consider the following code:

text = """private void unlockMap(Player player) {
        TowerData towerData = player.getTowerData();
        if (!towerData.getClass().equals(TowerData.class)) {
            CommandHandler.sendTranslatedMessage(player, "commands.generic.no_permissions");
        } else {
            if (towerData."""

import code_tokenize as ctok
tokens = ctok.tokenize(text, lang='java', syntax_error='ignore')

assert tokens[-1].type == '.', (tokens[-1].type, tokens[-1].text)

The result of executing the above code is:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[23], line 11
      8 import code_tokenize as ctok
      9 tokens = ctok.tokenize(text, lang='java', syntax_error='ignore')
---> 11 assert tokens[-1].type == '.', (tokens[-1].type, tokens[-1].text)

AssertionError: ('}', '')

There is an additional token of type '}' in the end of the tokenstream, and it doesn't match any text.
The tokenstream upto the last token is as expected:

[private,
 void,
 unlockMap,
 ,
 (,
 Player,
 player,
 ),
 {,
 TowerData,
 towerData,
 =,
 player,
 .,
 getTowerData,
 (,
 ),
 ;,
 if,
 (,
 !,
 towerData,
 .,
 getClass,
 (,
 ),
 .,
 equals,
 (,
 TowerData,
 .,
 class,
 ),
 ),
 {,
 CommandHandler,
 .,
 sendTranslatedMessage,
 (,
 player,
 ,,
 "commands.generic.no_permissions",
 ),
 ;,
 },
 else,
 {,
 if,
 (,
 towerData,
 .,
 ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions