Skip to content

A way to distinguish between luajit long tokens and lua 5.3 long tokens #155

@toxamin

Description

@toxamin

What feature are you requesting?

Currently, when parsing both LuaJIT and Lua 5.3+ files, the lexer creates tokens that have a value of type long.
For example, in LuaJIT 50LL, and in Lua 5.3 50, both produce a token with the same value. This is normally not an issue, as we can simply check whether the token ends with LL to distinguish between them, however that is clunky, and makes analysis code reliant on the text of the token, rather than the value.
I propose implementing a separate type for LuaJIT longs, such as a record LuaJITLong, and using that as the token value instead.

Can you go in further detail of what this feature is about?

var hmm = LuaSyntaxTree.ParseText("local a = 50LL", new LuaParseOptions(LuaSyntaxOptions.LuaJIT21));
var lit = hmm.GetRoot().DescendantNodes().OfType<LiteralExpressionSyntax>().First();
var tok = lit.Token;
var hmm2 = LuaSyntaxTree.ParseText("local a = 50", new LuaParseOptions(LuaSyntaxOptions.Lua54));
var lit2 = hmm2.GetRoot().DescendantNodes().OfType<LiteralExpressionSyntax>().First();
var tok2 = lit2.Token;
// Here, the tok.Value == tok2.Value

Please ensure you have done the following actions:

  • I have checked that there are no similar requests already open.
  • I have confirmed that this has not been implemented on the latest nightly version.
  • I have confirmed that this feature will be useful for all (or most) users of Loretta.
  • I acknowledge my issue will be closed if any step has been skipped.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions