Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 75 additions & 17 deletions definitions/luau.luau
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type Pair<T, Separator> = { node: T, separator: Token<Separator>? }
export type Punctuated<T, Separator = ","> = { Pair<T, Separator> }

export type AstLocal = {
location: span,
kind: "local",
name: Token<string>,
colon: Token<":">?,
Expand All @@ -57,32 +58,43 @@ export type AstLocal = {
}

export type AstExprGroup = {
location: span,
tag: "group",
openparens: Token<"(">,
expression: AstExpr,
closeparens: Token<")">,
}

export type AstExprConstantNil = Token<"nil"> & { kind: "expr", tag: "nil" }
export type AstExprConstantNil = Token<"nil"> & { location: span, kind: "expr", tag: "nil" }

export type AstExprConstantBool = Token<"true" | "false"> & { kind: "expr", tag: "boolean", value: boolean }

export type AstExprConstantNumber = Token<string> & { kind: "expr", tag: "number", value: number }
export type AstExprConstantBool =
Token<"true" | "false">
& { location: span, kind: "expr", tag: "boolean", value: boolean }

export type AstExprConstantNumber = Token<string> & { location: span, kind: "expr", tag: "number", value: number }
export type AstExprConstantString = Token<string> & {
location: span,
kind: "expr",
tag: "string",
quotestyle: "single" | "double" | "block" | "interp",
blockdepth: number,
}

export type AstExprLocal = { kind: "expr", tag: "local", token: Token<string>, ["local"]: AstLocal, upvalue: boolean }
export type AstExprLocal = {
location: span,
kind: "expr",
tag: "local",
token: Token<string>,
["local"]: AstLocal,
upvalue: boolean,
}

export type AstExprGlobal = { kind: "expr", tag: "global", name: Token }
export type AstExprGlobal = { location: span, kind: "expr", tag: "global", name: Token }

export type AstExprVarargs = Token<"..."> & { kind: "expr", tag: "vararg" }
export type AstExprVarargs = Token<"..."> & { location: span, kind: "expr", tag: "vararg" }

export type AstExprCall = {
location: span,
kind: "expr",
tag: "call",
func: AstExpr,
Expand All @@ -94,6 +106,7 @@ export type AstExprCall = {
}

export type AstExprIndexName = {
location: span,
kind: "expr",
tag: "indexname",
expression: AstExpr,
Expand All @@ -103,6 +116,7 @@ export type AstExprIndexName = {
}

export type AstExprIndexExpr = {
location: span,
kind: "expr",
tag: "index",
expression: AstExpr,
Expand Down Expand Up @@ -131,6 +145,7 @@ export type AstFunctionBody = {
}

export type AstExprAnonymousFunction = {
location: span,
kind: "expr",
tag: "function",
attributes: { AstAttribute },
Expand Down Expand Up @@ -164,16 +179,24 @@ export type AstExprTableItemGeneral = {
export type AstExprTableItem = AstExprTableItemList | AstExprTableItemRecord | AstExprTableItemGeneral

export type AstExprTable = {
location: span,
kind: "expr",
tag: "table",
openbrace: Token<"{">,
entries: { AstExprTableItem },
closebrace: Token<"}">,
}

export type AstExprUnary = { kind: "expr", tag: "unary", operator: Token<"not" | "-" | "#">, operand: AstExpr }
export type AstExprUnary = {
location: span,
kind: "expr",
tag: "unary",
operator: Token<"not" | "-" | "#">,
operand: AstExpr,
}

export type AstExprBinary = {
location: span,
kind: "expr",
tag: "binary",
lhsoperand: AstExpr,
Expand All @@ -182,13 +205,15 @@ export type AstExprBinary = {
}

export type AstExprInterpString = {
location: span,
kind: "expr",
tag: "interpolatedstring",
strings: { Token<string> },
expressions: { AstExpr },
}

export type AstExprTypeAssertion = {
location: span,
kind: "expr",
tag: "cast",
operand: AstExpr,
Expand All @@ -205,6 +230,7 @@ export type AstElseIfExpr = {
}

export type AstExprIfElse = {
location: span,
kind: "expr",
tag: "conditional",
ifkeyword: Token<"if">,
Expand Down Expand Up @@ -238,6 +264,7 @@ export type AstExpr = { kind: "expr" } & (
)

export type AstStatBlock = {
location: span,
kind: "stat",
tag: "block",
statements: { AstStat },
Expand All @@ -251,6 +278,7 @@ export type AstElseIfStat = {
}

export type AstStatIf = {
location: span,
kind: "stat",
tag: "conditional",
ifkeyword: Token<"if">,
Expand All @@ -264,6 +292,7 @@ export type AstStatIf = {
}

export type AstStatWhile = {
location: span,
kind: "stat",
tag: "while",
whilekeyword: Token<"while">,
Expand All @@ -274,6 +303,7 @@ export type AstStatWhile = {
}

export type AstStatRepeat = {
location: span,
kind: "stat",
tag: "repeat",
repeatkeyword: Token<"repeat">,
Expand All @@ -282,20 +312,22 @@ export type AstStatRepeat = {
condition: AstExpr,
}

export type AstStatBreak = Token<"break"> & { kind: "stat", tag: "break" }
export type AstStatBreak = Token<"break"> & { location: span, kind: "stat", tag: "break" }

export type AstStatContinue = Token<"continue"> & { kind: "stat", tag: "continue" }
export type AstStatContinue = Token<"continue"> & { location: span, kind: "stat", tag: "continue" }

export type AstStatReturn = {
location: span,
kind: "stat",
tag: "return",
returnkeyword: Token<"return">,
expressions: Punctuated<AstExpr>,
}

export type AstStatExpr = { kind: "stat", tag: "expression", expression: AstExpr }
export type AstStatExpr = { location: span, kind: "stat", tag: "expression", expression: AstExpr }

export type AstStatLocal = {
location: span,
kind: "stat",
tag: "local",
localkeyword: Token<"local">,
Expand All @@ -305,6 +337,7 @@ export type AstStatLocal = {
}

export type AstStatFor = {
location: span,
kind: "stat",
tag: "for",
forkeyword: Token<"for">,
Expand All @@ -321,6 +354,7 @@ export type AstStatFor = {
}

export type AstStatForIn = {
location: span,
kind: "stat",
tag: "forin",
forkeyword: Token<"for">,
Expand All @@ -333,6 +367,7 @@ export type AstStatForIn = {
}

export type AstStatAssign = {
location: span,
kind: "stat",
tag: "assign",
variables: Punctuated<AstExpr>,
Expand All @@ -341,16 +376,18 @@ export type AstStatAssign = {
}

export type AstStatCompoundAssign = {
location: span,
kind: "stat",
tag: "compoundassign",
variable: AstExpr,
operand: Token, -- TODO: enforce token type,
value: AstExpr,
}

export type AstAttribute = Token<"@checked" | "@native" | "@deprecated"> & { kind: "attribute" }
export type AstAttribute = Token<"@checked" | "@native" | "@deprecated"> & { location: span, kind: "attribute" }

export type AstStatFunction = {
location: span,
kind: "stat",
tag: "function",
attributes: { AstAttribute },
Expand All @@ -360,6 +397,7 @@ export type AstStatFunction = {
}

export type AstStatLocalFunction = {
location: span,
kind: "stat",
tag: "localfunction",
attributes: { AstAttribute },
Expand All @@ -370,6 +408,7 @@ export type AstStatLocalFunction = {
}

export type AstStatTypeAlias = {
location: span,
kind: "stat",
tag: "typealias",
export: Token<"export">?,
Expand All @@ -384,6 +423,7 @@ export type AstStatTypeAlias = {
}

export type AstStatTypeFunction = {
location: span,
kind: "stat",
tag: "typefunction",
export: Token<"export">?,
Expand Down Expand Up @@ -429,6 +469,7 @@ export type AstGenericTypePack = {
}

export type AstTypeReference = {
location: span,
kind: "type",
tag: "reference",
prefix: Token<string>?,
Expand All @@ -439,11 +480,19 @@ export type AstTypeReference = {
closeparameters: Token<">">?,
}

export type AstTypeSingletonBool = Token<"true" | "false"> & { kind: "type", tag: "boolean", value: boolean }
export type AstTypeSingletonBool =
Token<"true" | "false">
& { location: span, kind: "type", tag: "boolean", value: boolean }

export type AstTypeSingletonString = Token<string> & { kind: "type", tag: "string", quotestyle: "single" | "double" }
export type AstTypeSingletonString = Token<string> & {
location: span,
kind: "type",
tag: "string",
quotestyle: "single" | "double",
}

export type AstTypeTypeof = {
location: span,
kind: "type",
tag: "typeof",
typeof: Token<"typeof">,
Expand All @@ -453,16 +502,18 @@ export type AstTypeTypeof = {
}

export type AstTypeGroup = {
location: span,
kind: "type",
tag: "group",
openparens: Token<"(">,
type: AstType,
closeparens: Token<")">,
}

export type AstTypeOptional = Token<"?"> & { kind: "type", tag: "optional" }
export type AstTypeOptional = Token<"?"> & { location: span, kind: "type", tag: "optional" }

export type AstTypeUnion = {
location: span,
kind: "type",
tag: "union",
leading: Token<"|">?,
Expand All @@ -471,13 +522,15 @@ export type AstTypeUnion = {
}

export type AstTypeIntersection = {
location: span,
kind: "type",
tag: "intersection",
leading: Token<"&">?,
types: Punctuated<AstType, "&">,
}

export type AstTypeArray = {
location: span,
kind: "type",
tag: "array",
openbrace: Token<"{">,
Expand Down Expand Up @@ -520,6 +573,7 @@ export type AstTypeTableItemProperty = {
export type AstTypeTableItem = AstTypeTableItemIndexer | AstTypeTableItemStringProperty | AstTypeTableItemProperty

export type AstTypeTable = {
location: span,
kind: "type",
tag: "table",
openbrace: Token<"{">,
Expand All @@ -528,12 +582,14 @@ export type AstTypeTable = {
}

export type AstTypeFunctionParameter = {
location: span,
name: Token?,
colon: Token<":">?,
type: AstType,
}

export type AstTypeFunction = {
location: span,
kind: "type",
tag: "function",
opengenerics: Token<"<">?,
Expand Down Expand Up @@ -563,6 +619,7 @@ export type AstType = { kind: "type" } & (
)

export type AstTypePackExplicit = {
location: span,
kind: "typepack",
tag: "explicit",
openparens: Token<"(">?,
Expand All @@ -571,9 +628,10 @@ export type AstTypePackExplicit = {
closeparens: Token<")">?,
}

export type AstTypePackGeneric = { kind: "typepack", tag: "generic", name: Token, ellipsis: Token<"..."> }
export type AstTypePackGeneric = { location: span, kind: "typepack", tag: "generic", name: Token, ellipsis: Token<"..."> }

export type AstTypePackVariadic = {
location: span,
kind: "typepack",
tag: "variadic",
--- May be nil when present as the vararg annotation in a function body
Expand All @@ -583,7 +641,7 @@ export type AstTypePackVariadic = {

export type AstTypePack = { kind: "typepack" } & (AstTypePackExplicit | AstTypePackGeneric | AstTypePackVariadic)

export type AstNode = { location: span? } & (AstExpr | AstStat | AstType | AstTypePack | AstLocal | AstAttribute)
export type AstNode = { location: span } & (AstExpr | AstStat | AstType | AstTypePack | AstLocal | AstAttribute)

export type ParseResult = {
root: AstStatBlock,
Expand Down