@@ -1452,9 +1452,11 @@ AstStat* Parser::parseDeclaration(const Location& start, const AstArray<AstAttr*
1452
1452
1453
1453
if (chars && !containsNull)
1454
1454
{
1455
- props.push_back (AstDeclaredExternTypeProperty{
1456
- AstName (chars->data ), Location (nameBegin, nameEnd), type, false , Location (begin.location , lexer.previousLocation ())
1457
- });
1455
+ props.push_back (
1456
+ AstDeclaredExternTypeProperty{
1457
+ AstName (chars->data ), Location (nameBegin, nameEnd), type, false , Location (begin.location , lexer.previousLocation ())
1458
+ }
1459
+ );
1458
1460
}
1459
1461
else
1460
1462
{
@@ -1485,9 +1487,9 @@ AstStat* Parser::parseDeclaration(const Location& start, const AstArray<AstAttr*
1485
1487
1486
1488
expectAndConsume (' :' , " property type annotation" );
1487
1489
AstType* propType = parseType ();
1488
- props.push_back (AstDeclaredExternTypeProperty{
1489
- propName->name , propName->location , propType, false , Location (propStart, lexer.previousLocation ())
1490
- } );
1490
+ props.push_back (
1491
+ AstDeclaredExternTypeProperty{ propName->name , propName->location , propType, false , Location (propStart, lexer.previousLocation ())}
1492
+ );
1491
1493
}
1492
1494
}
1493
1495
@@ -2118,16 +2120,18 @@ AstType* Parser::parseTableType(bool inDeclarationContext)
2118
2120
{
2119
2121
props.push_back (AstTableProp{AstName (chars->data ), begin.location , type, access, accessLocation});
2120
2122
if (options.storeCstData )
2121
- cstItems.push_back (CstTypeTable::Item{
2122
- CstTypeTable::Item::Kind::StringProperty,
2123
- begin.location .begin ,
2124
- indexerClosePosition,
2125
- colonPosition,
2126
- tableSeparator (),
2127
- lexer.current ().location .begin ,
2128
- allocator.alloc <CstExprConstantString>(sourceString, style, blockDepth),
2129
- stringPosition
2130
- });
2123
+ cstItems.push_back (
2124
+ CstTypeTable::Item{
2125
+ CstTypeTable::Item::Kind::StringProperty,
2126
+ begin.location .begin ,
2127
+ indexerClosePosition,
2128
+ colonPosition,
2129
+ tableSeparator (),
2130
+ lexer.current ().location .begin ,
2131
+ allocator.alloc <CstExprConstantString>(sourceString, style, blockDepth),
2132
+ stringPosition
2133
+ }
2134
+ );
2131
2135
}
2132
2136
else
2133
2137
report (begin.location , " String literal contains malformed escape sequence or \\ 0" );
@@ -2148,14 +2152,16 @@ AstType* Parser::parseTableType(bool inDeclarationContext)
2148
2152
auto tableIndexerResult = parseTableIndexer (access, accessLocation, begin);
2149
2153
indexer = tableIndexerResult.node ;
2150
2154
if (options.storeCstData )
2151
- cstItems.push_back (CstTypeTable::Item{
2152
- CstTypeTable::Item::Kind::Indexer,
2153
- tableIndexerResult.indexerOpenPosition ,
2154
- tableIndexerResult.indexerClosePosition ,
2155
- tableIndexerResult.colonPosition ,
2156
- tableSeparator (),
2157
- lexer.current ().location .begin ,
2158
- });
2155
+ cstItems.push_back (
2156
+ CstTypeTable::Item{
2157
+ CstTypeTable::Item::Kind::Indexer,
2158
+ tableIndexerResult.indexerOpenPosition ,
2159
+ tableIndexerResult.indexerClosePosition ,
2160
+ tableIndexerResult.colonPosition ,
2161
+ tableSeparator (),
2162
+ lexer.current ().location .begin ,
2163
+ }
2164
+ );
2159
2165
}
2160
2166
}
2161
2167
}
@@ -2184,14 +2190,16 @@ AstType* Parser::parseTableType(bool inDeclarationContext)
2184
2190
2185
2191
props.push_back (AstTableProp{name->name , name->location , type, access, accessLocation});
2186
2192
if (options.storeCstData )
2187
- cstItems.push_back (CstTypeTable::Item{
2188
- CstTypeTable::Item::Kind::Property,
2189
- Position{0 , 0 },
2190
- Position{0 , 0 },
2191
- colonPosition,
2192
- tableSeparator (),
2193
- lexer.current ().location .begin
2194
- });
2193
+ cstItems.push_back (
2194
+ CstTypeTable::Item{
2195
+ CstTypeTable::Item::Kind::Property,
2196
+ Position{0 , 0 },
2197
+ Position{0 , 0 },
2198
+ colonPosition,
2199
+ tableSeparator (),
2200
+ lexer.current ().location .begin
2201
+ }
2202
+ );
2195
2203
}
2196
2204
2197
2205
if (lexer.current ().type == ' ,' || lexer.current ().type == ' ;' )
@@ -3859,9 +3867,8 @@ AstExpr* Parser::parseString()
3859
3867
style = AstExprConstantString::QuotedRaw;
3860
3868
break ;
3861
3869
case Lexeme::QuotedString:
3862
- style = lexer.current ().getQuoteStyle () == Lexeme::QuoteStyle::Single
3863
- ? AstExprConstantString::QuotedSingle
3864
- : AstExprConstantString::QuotedSimple;
3870
+ style = lexer.current ().getQuoteStyle () == Lexeme::QuoteStyle::Single ? AstExprConstantString::QuotedSingle
3871
+ : AstExprConstantString::QuotedSimple;
3865
3872
break ;
3866
3873
default :
3867
3874
LUAU_ASSERT (false && " Invalid string type" );
@@ -4092,28 +4099,29 @@ bool Parser::expectAndConsume(char value, const char* context)
4092
4099
bool Parser::expectAndConsume (Lexeme::Type type, const char * context)
4093
4100
{
4094
4101
if (lexer.current ().type != type)
4095
- {
4096
- expectAndConsumeFail (type, context);
4102
+ return expectAndConsumeFailWithLookahead (type, context);
4097
4103
4098
- // check if this is an extra token and the expected token is next
4099
- if (lexer.lookahead ().type == type)
4100
- {
4101
- // skip invalid and consume expected
4102
- nextLexeme ();
4103
- nextLexeme ();
4104
- }
4104
+ nextLexeme ();
4105
+ return true ;
4106
+ }
4105
4107
4106
- return false ;
4107
- }
4108
- else
4108
+ // LUAU_NOINLINE is used to limit the stack cost due to std::string objects, and to increase caller performance since this code is cold
4109
+ LUAU_NOINLINE bool Parser::expectAndConsumeFailWithLookahead (Lexeme::Type type, const char * context)
4110
+ {
4111
+ expectAndConsumeFail (type, context);
4112
+
4113
+ // check if this is an extra token and the expected token is next
4114
+ if (lexer.lookahead ().type == type)
4109
4115
{
4116
+ // skip invalid and consume expected
4117
+ nextLexeme ();
4110
4118
nextLexeme ();
4111
- return true ;
4112
4119
}
4120
+
4121
+ return false ;
4113
4122
}
4114
4123
4115
- // LUAU_NOINLINE is used to limit the stack cost of this function due to std::string objects, and to increase caller performance since this code is
4116
- // cold
4124
+ // LUAU_NOINLINE is used to limit the stack cost due to std::string objects, and to increase caller performance since this code is cold
4117
4125
LUAU_NOINLINE void Parser::expectAndConsumeFail (Lexeme::Type type, const char * context)
4118
4126
{
4119
4127
std::string typeString = Lexeme (Location (Position (0 , 0 ), 0 ), type).toString ();
@@ -4143,6 +4151,7 @@ bool Parser::expectMatchAndConsume(char value, const MatchLexeme& begin, bool se
4143
4151
}
4144
4152
}
4145
4153
4154
+ // LUAU_NOINLINE is used to limit the stack cost due to std::string objects, and to increase caller performance since this code is cold
4146
4155
LUAU_NOINLINE bool Parser::expectMatchAndConsumeRecover (char value, const MatchLexeme& begin, bool searchForMissing)
4147
4156
{
4148
4157
Lexeme::Type type = static_cast <Lexeme::Type>(static_cast <unsigned char >(value));
@@ -4185,8 +4194,7 @@ LUAU_NOINLINE bool Parser::expectMatchAndConsumeRecover(char value, const MatchL
4185
4194
return false ;
4186
4195
}
4187
4196
4188
- // LUAU_NOINLINE is used to limit the stack cost of this function due to std::string objects, and to increase caller performance since this code is
4189
- // cold
4197
+ // LUAU_NOINLINE is used to limit the stack cost due to std::string objects, and to increase caller performance since this code is cold
4190
4198
LUAU_NOINLINE void Parser::expectMatchAndConsumeFail (Lexeme::Type type, const MatchLexeme& begin, const char * extra)
4191
4199
{
4192
4200
std::string typeString = Lexeme (Location (Position (0 , 0 ), 0 ), type).toString ();
@@ -4217,40 +4225,23 @@ LUAU_NOINLINE void Parser::expectMatchAndConsumeFail(Lexeme::Type type, const Ma
4217
4225
bool Parser::expectMatchEndAndConsume (Lexeme::Type type, const MatchLexeme& begin)
4218
4226
{
4219
4227
if (lexer.current ().type != type)
4220
- {
4221
- expectMatchEndAndConsumeFail (type, begin);
4228
+ return expectMatchEndAndConsumeFailWithLookahead (type, begin);
4222
4229
4223
- // check if this is an extra token and the expected token is next
4224
- if (lexer.lookahead ().type == type)
4225
- {
4226
- // skip invalid and consume expected
4227
- nextLexeme ();
4228
- nextLexeme ();
4229
-
4230
- return true ;
4231
- }
4232
-
4233
- return false ;
4234
- }
4235
- else
4230
+ // If the token matches on a different line and a different column, it suggests misleading indentation
4231
+ // This can be used to pinpoint the problem location for a possible future *actual* mismatch
4232
+ if (lexer.current ().location .begin .line != begin.position .line && lexer.current ().location .begin .column != begin.position .column &&
4233
+ endMismatchSuspect.position .line < begin.position .line ) // Only replace the previous suspect with more recent suspects
4236
4234
{
4237
- // If the token matches on a different line and a different column, it suggests misleading indentation
4238
- // This can be used to pinpoint the problem location for a possible future *actual* mismatch
4239
- if (lexer.current ().location .begin .line != begin.position .line && lexer.current ().location .begin .column != begin.position .column &&
4240
- endMismatchSuspect.position .line < begin.position .line ) // Only replace the previous suspect with more recent suspects
4241
- {
4242
- endMismatchSuspect = begin;
4243
- }
4235
+ endMismatchSuspect = begin;
4236
+ }
4244
4237
4245
- nextLexeme ();
4238
+ nextLexeme ();
4246
4239
4247
- return true ;
4248
- }
4240
+ return true ;
4249
4241
}
4250
4242
4251
- // LUAU_NOINLINE is used to limit the stack cost of this function due to std::string objects, and to increase caller performance since this code is
4252
- // cold
4253
- LUAU_NOINLINE void Parser::expectMatchEndAndConsumeFail (Lexeme::Type type, const MatchLexeme& begin)
4243
+ // LUAU_NOINLINE is used to limit the stack cost due to std::string objects, and to increase caller performance since this code is cold
4244
+ LUAU_NOINLINE bool Parser::expectMatchEndAndConsumeFailWithLookahead (Lexeme::Type type, const MatchLexeme& begin)
4254
4245
{
4255
4246
if (endMismatchSuspect.type != Lexeme::Eof && endMismatchSuspect.position .line > begin.position .line )
4256
4247
{
@@ -4263,6 +4254,18 @@ LUAU_NOINLINE void Parser::expectMatchEndAndConsumeFail(Lexeme::Type type, const
4263
4254
{
4264
4255
expectMatchAndConsumeFail (type, begin);
4265
4256
}
4257
+
4258
+ // check if this is an extra token and the expected token is next
4259
+ if (lexer.lookahead ().type == type)
4260
+ {
4261
+ // skip invalid and consume expected
4262
+ nextLexeme ();
4263
+ nextLexeme ();
4264
+
4265
+ return true ;
4266
+ }
4267
+
4268
+ return false ;
4266
4269
}
4267
4270
4268
4271
template <typename T>
0 commit comments