Skip to content

Symbol with keyword value is lexed as keyword #3940

@Earlopain

Description

@Earlopain

In syntax_suggest, it lexes the code and counts various keywords. If it encounters a symbol like :module, it looks at state bits to decide if the token really is a keyword or not. ruby/syntax_suggest@10232e4

For the rewrite to native prism I don't want to rely on state at all. But I noticed that prism also lexes in the following way:

pp Prism.lex(":next").value
=> [[SYMBOL_BEGIN(1,0)-(1,1)(":"), 128], [KEYWORD_NEXT(1,1)-(1,5)("next"), 8], [EOF(1,5)-(1,5)(""), 2]]

# And similarly etc.
pp Prism.lex(":@foo").value
=> [[SYMBOL_BEGIN(1,0)-(1,1)(":"), 128], [INSTANCE_VARIABLE(1,1)-(1,5)("@foo"), 8], [EOF(1,5)-(1,5)(""), 2]]

Basically it happens in all the places that handle PM_CASE_KEYWORD (at least). Prism has the context, would it make sense to emit these as IDENTIFIER instead?

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