From 70c00b375eb51b03c94f97d859d355ab7444c605 Mon Sep 17 00:00:00 2001 From: Alexander McCord <11488393+alexmccord@users.noreply.github.com> Date: Mon, 28 Feb 2022 04:49:42 -0800 Subject: [PATCH] Update syntax-metatable-type-annotation.md --- rfcs/syntax-metatable-type-annotation.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/rfcs/syntax-metatable-type-annotation.md b/rfcs/syntax-metatable-type-annotation.md index b72b404c..e430e0eb 100644 --- a/rfcs/syntax-metatable-type-annotation.md +++ b/rfcs/syntax-metatable-type-annotation.md @@ -65,6 +65,24 @@ declare function getmetatable(tab: {metatable MT}): MT declare function getmetatable(tab: any): nil ``` +For RFC completeness: just like indexers, it is not legal syntax when the parser context is not a table type annotation. `type Foo = metatable Bar` and `{f: (metatable Bar) -> ()}` and other variants are illegal. + +Formally, the grammar change is: + +```diff + TableIndexer = '[' Type ']' ':' Type ++ TableMetatable = 'metatable' Type + TableProp = NAME ':' Type +- TablePropOrIndexer = TableProp | TableIndexer +- PropList = TablePropOrIndexer {fieldsep TablePropOrIndexer} [fieldsep] +- TableType = '{' PropList '} ++ TableEntry = TableProp | TableIndexer | TableMetatable ++ TableEntries = TableEntry {fieldsep TablePropOrIndexer} [fieldsep] ++ TableType = '{' TableEntries '}' +``` + +... ignoring that we can't describe in EBNF that some syntax can only show up once but anywhere within a list. + ## Drawbacks The syntax is unfortunately very identical to properties, where the only difference between them is a single character, `:`. Observe: `{metatable T}` vs `{metatable: T}` where the former is a table with the metatable of type T, and the latter is a table with one property `metatable` of type `T`.