Skip to content

Commit df81e58

Browse files
committed
v0.15.6+luau688
1 parent 2497bb7 commit df81e58

31 files changed

+774
-133
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "luau0-src"
3-
version = "0.15.5+luau686"
3+
version = "0.15.6+luau688"
44
authors = ["Aleksandr Orlenko <[email protected]>"]
55
edition = "2021"
66
repository = "https://github.com/mlua-rs/luau-src-rs"

luau/Ast/include/Luau/Ast.h

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,14 @@ class AstAttr : public AstNode
197197
Deprecated,
198198
};
199199

200-
AstAttr(const Location& location, Type type);
200+
struct DeprecatedInfo
201+
{
202+
bool deprecated = false;
203+
std::optional<std::string> use;
204+
std::optional<std::string> reason;
205+
};
206+
207+
AstAttr(const Location& location, Type type, AstArray<AstExpr*> args);
201208

202209
AstAttr* asAttr() override
203210
{
@@ -206,7 +213,10 @@ class AstAttr : public AstNode
206213

207214
void visit(AstVisitor* visitor) override;
208215

216+
DeprecatedInfo deprecatedInfo() const;
217+
209218
Type type;
219+
AstArray<AstExpr*> args;
210220
};
211221

212222
class AstExpr : public AstNode
@@ -329,9 +339,28 @@ class AstExprConstantString : public AstExpr
329339

330340
enum QuoteStyle
331341
{
342+
// A string created using double quotes or an interpolated string,
343+
// as in:
344+
//
345+
// "foo", `My name is {protagonist}! / And I'm {antagonist}!`
346+
//
332347
QuotedSimple,
348+
// A string created using single quotes, as in:
349+
//
350+
// 'bar'
351+
//
352+
QuotedSingle,
353+
// A string created using `[[ ... ]]` as in:
354+
//
355+
// [[ Gee, this sure is a long string.
356+
// it even has a new line in it! ]]
357+
//
333358
QuotedRaw,
334-
Unquoted
359+
// A "string" in the context of a table literal, as in:
360+
//
361+
// { foo = 42 } -- `foo` here is a "constant string"
362+
//
363+
Unquoted,
335364
};
336365

337366
AstExprConstantString(const Location& location, const AstArray<char>& value, QuoteStyle quoteStyle);
@@ -455,6 +484,7 @@ class AstExprFunction : public AstExpr
455484

456485
bool hasNativeAttribute() const;
457486
bool hasAttribute(AstAttr::Type attributeType) const;
487+
AstAttr* getAttribute(AstAttr::Type attributeType) const;
458488

459489
AstArray<AstAttr*> attributes;
460490
AstArray<AstGenericType*> generics;
@@ -499,6 +529,8 @@ class AstExprTable : public AstExpr
499529

500530
void visit(AstVisitor* visitor) override;
501531

532+
std::optional<AstExpr*> getRecord(const char* key) const;
533+
502534
AstArray<Item> items;
503535
};
504536

@@ -960,6 +992,7 @@ class AstStatDeclareFunction : public AstStat
960992

961993
bool isCheckedFunction() const;
962994
bool hasAttribute(AstAttr::Type attributeType) const;
995+
AstAttr* getAttribute(AstAttr::Type attributeType) const;
963996

964997
AstArray<AstAttr*> attributes;
965998
AstName name;
@@ -1117,6 +1150,7 @@ class AstTypeFunction : public AstType
11171150

11181151
bool isCheckedFunction() const;
11191152
bool hasAttribute(AstAttr::Type attributeType) const;
1153+
AstAttr* getAttribute(AstAttr::Type attributeType) const;
11201154

11211155
AstArray<AstAttr*> attributes;
11221156
AstArray<AstGenericType*> generics;
@@ -1561,6 +1595,8 @@ class AstVisitor
15611595
};
15621596

15631597
bool isLValue(const AstExpr*);
1598+
bool isConstantLiteral(const AstExpr*);
1599+
bool isLiteralTable(const AstExpr*);
15641600
AstName getIdentifier(AstExpr*);
15651601
Location getLocation(const AstTypeList& typeList);
15661602

luau/Ast/include/Luau/Lexer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct Lexeme
5555
BlockComment,
5656

5757
Attribute,
58+
AttributeOpen,
5859

5960
BrokenString,
6061
BrokenComment,

luau/Ast/include/Luau/Parser.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,13 @@ class Parser
130130
// function funcname funcbody
131131
LUAU_FORCEINLINE AstStat* parseFunctionStat(const AstArray<AstAttr*>& attributes = {nullptr, 0});
132132

133-
std::optional<AstAttr::Type> validateAttribute(const char* attributeName, const TempVector<AstAttr*>& attributes);
133+
std::optional<AstAttr::Type> validateAttribute(
134+
Location loc,
135+
const char* attributeName,
136+
const TempVector<AstAttr*>& attributes,
137+
const AstArray<AstExpr*>& args
138+
);
139+
std::optional<AstAttr::Type> validateAttribute_DEPRECATED(const char* attributeName, const TempVector<AstAttr*>& attributes);
134140

135141
// attribute ::= '@' NAME
136142
void parseAttribute(TempVector<AstAttr*>& attribute);
@@ -287,6 +293,7 @@ class Parser
287293
// simpleexp -> NUMBER | STRING | NIL | true | false | ... | constructor | [attributes] FUNCTION body | primaryexp
288294
AstExpr* parseSimpleExpr();
289295

296+
std::tuple<AstArray<AstExpr*>, Location, Location> parseCallList(TempVector<Position>* commaPositions);
290297
// args ::= `(' [explist] `)' | tableconstructor | String
291298
AstExpr* parseFunctionArgs(AstExpr* func, bool self);
292299

luau/Ast/src/Ast.cpp

Lines changed: 105 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,40 @@
22
#include "Luau/Ast.h"
33

44
#include "Luau/Common.h"
5+
#include "Luau/StringUtils.h"
6+
7+
LUAU_FASTFLAG(LuauParametrizedAttributeSyntax)
58

69
namespace Luau
710
{
811

9-
static bool hasAttributeInArray(const AstArray<AstAttr*> attributes, AstAttr::Type attributeType)
12+
static AstAttr* findAttributeInArray(const AstArray<AstAttr*> attributes, AstAttr::Type attributeType)
1013
{
1114
for (const auto attribute : attributes)
1215
{
1316
if (attribute->type == attributeType)
14-
return true;
17+
return attribute;
1518
}
1619

17-
return false;
20+
return nullptr;
21+
}
22+
23+
static bool hasAttributeInArray(const AstArray<AstAttr*> attributes, AstAttr::Type attributeType)
24+
{
25+
if (FFlag::LuauParametrizedAttributeSyntax)
26+
{
27+
return findAttributeInArray(attributes, attributeType) != nullptr;
28+
}
29+
else
30+
{
31+
for (const auto attribute : attributes)
32+
{
33+
if (attribute->type == attributeType)
34+
return true;
35+
}
36+
37+
return false;
38+
}
1839
}
1940

2041
static void visitTypeList(AstVisitor* visitor, const AstTypeList& list)
@@ -26,9 +47,10 @@ static void visitTypeList(AstVisitor* visitor, const AstTypeList& list)
2647
list.tailType->visit(visitor);
2748
}
2849

29-
AstAttr::AstAttr(const Location& location, Type type)
50+
AstAttr::AstAttr(const Location& location, Type type, AstArray<AstExpr*> args)
3051
: AstNode(ClassIndex(), location)
3152
, type(type)
53+
, args(args)
3254
{
3355
}
3456

@@ -37,6 +59,29 @@ void AstAttr::visit(AstVisitor* visitor)
3759
visitor->visit(this);
3860
}
3961

62+
AstAttr::DeprecatedInfo AstAttr::deprecatedInfo() const
63+
{
64+
AstAttr::DeprecatedInfo info;
65+
info.deprecated = type == AstAttr::Type::Deprecated;
66+
67+
if (info.deprecated && args.size > 0)
68+
{
69+
AstExprTable* table = args.data[0]->as<AstExprTable>();
70+
if (auto useValue = table->getRecord("use"))
71+
{
72+
AstArray<char> use = (*useValue)->as<AstExprConstantString>()->value;
73+
info.use = {{use.data, use.size}};
74+
}
75+
if (auto reasonValue = table->getRecord("reason"))
76+
{
77+
AstArray<char> reason = (*reasonValue)->as<AstExprConstantString>()->value;
78+
info.reason = {{reason.data, reason.size}};
79+
}
80+
}
81+
82+
return info;
83+
}
84+
4085
int gAstRttiIndex = 0;
4186

4287
AstGenericType::AstGenericType(const Location& location, AstName name, AstType* defaultValue)
@@ -293,6 +338,11 @@ bool AstExprFunction::hasAttribute(const AstAttr::Type attributeType) const
293338
return hasAttributeInArray(attributes, attributeType);
294339
}
295340

341+
AstAttr* AstExprFunction::getAttribute(const AstAttr::Type attributeType) const
342+
{
343+
return findAttributeInArray(attributes, attributeType);
344+
}
345+
296346
AstExprTable::AstExprTable(const Location& location, const AstArray<Item>& items)
297347
: AstExpr(ClassIndex(), location)
298348
, items(items)
@@ -313,6 +363,19 @@ void AstExprTable::visit(AstVisitor* visitor)
313363
}
314364
}
315365

366+
std::optional<AstExpr*> AstExprTable::getRecord(const char* key) const
367+
{
368+
for (const AstExprTable::Item& item : items)
369+
{
370+
if (item.kind == AstExprTable::Item::Kind::Record)
371+
{
372+
if (strcmp(item.key->as<AstExprConstantString>()->value.data, key) == 0)
373+
return item.value;
374+
}
375+
}
376+
return {};
377+
}
378+
316379
AstExprUnary::AstExprUnary(const Location& location, Op op, AstExpr* expr)
317380
: AstExpr(ClassIndex(), location)
318381
, op(op)
@@ -917,6 +980,11 @@ bool AstStatDeclareFunction::hasAttribute(AstAttr::Type attributeType) const
917980
return hasAttributeInArray(attributes, attributeType);
918981
}
919982

983+
AstAttr* AstStatDeclareFunction::getAttribute(const AstAttr::Type attributeType) const
984+
{
985+
return findAttributeInArray(attributes, attributeType);
986+
}
987+
920988
AstStatDeclareExternType::AstStatDeclareExternType(
921989
const Location& location,
922990
const AstName& name,
@@ -1085,6 +1153,11 @@ bool AstTypeFunction::hasAttribute(AstAttr::Type attributeType) const
10851153
return hasAttributeInArray(attributes, attributeType);
10861154
}
10871155

1156+
AstAttr* AstTypeFunction::getAttribute(AstAttr::Type attributeType) const
1157+
{
1158+
return findAttributeInArray(attributes, attributeType);
1159+
}
1160+
10881161
AstTypeTypeof::AstTypeTypeof(const Location& location, AstExpr* expr)
10891162
: AstType(ClassIndex(), location)
10901163
, expr(expr)
@@ -1234,6 +1307,34 @@ bool isLValue(const AstExpr* expr)
12341307
return expr->is<AstExprLocal>() || expr->is<AstExprGlobal>() || expr->is<AstExprIndexName>() || expr->is<AstExprIndexExpr>();
12351308
}
12361309

1310+
bool isConstantLiteral(const AstExpr* expr)
1311+
{
1312+
return expr->is<AstExprConstantNil>() || expr->is<AstExprConstantBool>() || expr->is<AstExprConstantNumber>() ||
1313+
expr->is<AstExprConstantString>();
1314+
}
1315+
1316+
bool isLiteralTable(const AstExpr* expr)
1317+
{
1318+
if (!expr->is<AstExprTable>())
1319+
return false;
1320+
1321+
for (const AstExprTable::Item& item : expr->as<AstExprTable>()->items)
1322+
{
1323+
switch (item.kind)
1324+
{
1325+
case AstExprTable::Item::Kind::General:
1326+
return false;
1327+
break;
1328+
case AstExprTable::Item::Kind::Record:
1329+
case AstExprTable::Item::Kind::List:
1330+
if (!isConstantLiteral(item.value) && !isLiteralTable(item.value))
1331+
return false;
1332+
break;
1333+
}
1334+
}
1335+
return true;
1336+
}
1337+
12371338
AstName getIdentifier(AstExpr* node)
12381339
{
12391340
if (AstExprGlobal* expr = node->as<AstExprGlobal>())

luau/Ast/src/Lexer.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <limits.h>
1010

11+
LUAU_FASTFLAG(LuauParametrizedAttributeSyntax)
12+
1113
namespace Luau
1214
{
1315

@@ -147,6 +149,9 @@ std::string Lexeme::toString() const
147149
case Attribute:
148150
return name ? format("'%s'", name) : "attribute";
149151

152+
case AttributeOpen:
153+
return "'@['";
154+
150155
case BrokenString:
151156
return "malformed string";
152157

@@ -981,8 +986,36 @@ Lexeme Lexer::readNext()
981986
}
982987
case '@':
983988
{
984-
std::pair<AstName, Lexeme::Type> attribute = readName();
985-
return Lexeme(Location(start, position()), Lexeme::Attribute, attribute.first.value);
989+
if (FFlag::LuauParametrizedAttributeSyntax)
990+
{
991+
if (peekch(1) == '[')
992+
{
993+
consume();
994+
consume();
995+
996+
return Lexeme(Location(start, 2), Lexeme::AttributeOpen);
997+
}
998+
else
999+
{
1000+
// consume @ first
1001+
consume();
1002+
1003+
if (isAlpha(peekch()) || peekch() == '_')
1004+
{
1005+
std::pair<AstName, Lexeme::Type> attribute = readName();
1006+
return Lexeme(Location(start, position()), Lexeme::Attribute, attribute.first.value);
1007+
}
1008+
else
1009+
{
1010+
return Lexeme(Location(start, position()), Lexeme::Attribute, "");
1011+
}
1012+
}
1013+
}
1014+
else
1015+
{
1016+
std::pair<AstName, Lexeme::Type> attribute = readName();
1017+
return Lexeme(Location(start, position()), Lexeme::Attribute, attribute.first.value);
1018+
}
9861019
}
9871020
default:
9881021
if (isDigit(peekch()))

0 commit comments

Comments
 (0)