Skip to content

Ambgious grammar for locals named record/interface/... #1132

Description

@purplesyringa

I'm trying to make a parser compatible with Teal, and I'm having trouble figuring out how to correctly parse local record ... annotations. Not everything that starts with local record is a record annotation, it could also be a variable, and from a quick test, Teal parses this correctly:

local record -- compiled to Lua as-is
local record <const> = 1 -- <const> is removed

However, there is one scenario where this ambiguity resolution seems to fail:

local record
global interface X end

Both lines are correct individually, but Teal parses this as

local record global
    interface X
    end
-- missing end

...and throws a corresponding error. There are other similar examples, e.g.

local record
func(1) -- syntax error, expected identifier at "func"

Is this intended? I believed that Teal tries to be compatible with Lua, so at least the last snippet would be parsed correctly, since it's pure Lua, but apparently that's not the case.

If this is intended, what are the heuristics for determining whether a given local record ... annotation is a record or a variable?

Metadata

Metadata

Assignees

No one assigned

    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