@@ -1452,9 +1452,11 @@ AstStat* Parser::parseDeclaration(const Location& start, const AstArray<AstAttr*
14521452
14531453 if (chars && !containsNull)
14541454 {
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+ );
14581460 }
14591461 else
14601462 {
@@ -1485,9 +1487,9 @@ AstStat* Parser::parseDeclaration(const Location& start, const AstArray<AstAttr*
14851487
14861488 expectAndConsume (' :' , " property type annotation" );
14871489 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+ );
14911493 }
14921494 }
14931495
@@ -2118,16 +2120,18 @@ AstType* Parser::parseTableType(bool inDeclarationContext)
21182120 {
21192121 props.push_back (AstTableProp{AstName (chars->data ), begin.location , type, access, accessLocation});
21202122 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+ );
21312135 }
21322136 else
21332137 report (begin.location , " String literal contains malformed escape sequence or \\ 0" );
@@ -2148,14 +2152,16 @@ AstType* Parser::parseTableType(bool inDeclarationContext)
21482152 auto tableIndexerResult = parseTableIndexer (access, accessLocation, begin);
21492153 indexer = tableIndexerResult.node ;
21502154 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+ );
21592165 }
21602166 }
21612167 }
@@ -2184,14 +2190,16 @@ AstType* Parser::parseTableType(bool inDeclarationContext)
21842190
21852191 props.push_back (AstTableProp{name->name , name->location , type, access, accessLocation});
21862192 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+ );
21952203 }
21962204
21972205 if (lexer.current ().type == ' ,' || lexer.current ().type == ' ;' )
@@ -3859,9 +3867,8 @@ AstExpr* Parser::parseString()
38593867 style = AstExprConstantString::QuotedRaw;
38603868 break ;
38613869 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;
38653872 break ;
38663873 default :
38673874 LUAU_ASSERT (false && " Invalid string type" );
@@ -4092,28 +4099,29 @@ bool Parser::expectAndConsume(char value, const char* context)
40924099bool Parser::expectAndConsume (Lexeme::Type type, const char * context)
40934100{
40944101 if (lexer.current ().type != type)
4095- {
4096- expectAndConsumeFail (type, context);
4102+ return expectAndConsumeFailWithLookahead (type, context);
40974103
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+ }
41054107
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)
41094115 {
4116+ // skip invalid and consume expected
4117+ nextLexeme ();
41104118 nextLexeme ();
4111- return true ;
41124119 }
4120+
4121+ return false ;
41134122}
41144123
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
41174125LUAU_NOINLINE void Parser::expectAndConsumeFail (Lexeme::Type type, const char * context)
41184126{
41194127 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
41434151 }
41444152}
41454153
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
41464155LUAU_NOINLINE bool Parser::expectMatchAndConsumeRecover (char value, const MatchLexeme& begin, bool searchForMissing)
41474156{
41484157 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
41854194 return false ;
41864195}
41874196
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
41904198LUAU_NOINLINE void Parser::expectMatchAndConsumeFail (Lexeme::Type type, const MatchLexeme& begin, const char * extra)
41914199{
41924200 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
42174225bool Parser::expectMatchEndAndConsume (Lexeme::Type type, const MatchLexeme& begin)
42184226{
42194227 if (lexer.current ().type != type)
4220- {
4221- expectMatchEndAndConsumeFail (type, begin);
4228+ return expectMatchEndAndConsumeFailWithLookahead (type, begin);
42224229
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
42364234 {
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+ }
42444237
4245- nextLexeme ();
4238+ nextLexeme ();
42464239
4247- return true ;
4248- }
4240+ return true ;
42494241}
42504242
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)
42544245{
42554246 if (endMismatchSuspect.type != Lexeme::Eof && endMismatchSuspect.position .line > begin.position .line )
42564247 {
@@ -4263,6 +4254,18 @@ LUAU_NOINLINE void Parser::expectMatchEndAndConsumeFail(Lexeme::Type type, const
42634254 {
42644255 expectMatchAndConsumeFail (type, begin);
42654256 }
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 ;
42664269}
42674270
42684271template <typename T>
0 commit comments