Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit fb2e63d

Browse files
committed
Merge pull request #3290 from montegoulding/lcidlc_use_clause_bug
lcidlc: Resolve regression to to use clause
2 parents fbe6476 + 47c8961 commit fb2e63d

1 file changed

Lines changed: 23 additions & 14 deletions

File tree

lcidlc/src/Parser.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,23 +157,29 @@ static void ParserMark(ParserRef self)
157157

158158
////////////////////////////////////////////////////////////////////////////////
159159

160-
static bool ParserWillMatchToken(ParserRef self, TokenType p_type)
160+
static bool ParserWillMatchToken(ParserRef self, TokenType p_type, bool p_same_row = false)
161161
{
162162
const Token *t_token;
163163
if (!ScannerRetrieve(self -> scanner, t_token))
164164
return false;
165165

166-
if (t_token -> type != p_type)
166+
if (p_same_row && PositionGetRow(self -> position) != PositionGetRow(t_token -> start))
167+
return false;
168+
169+
if (t_token -> type != p_type)
167170
return false;
168171

169172
return true;
170173
}
171174

172-
static bool ParserWillMatchKeyword(ParserRef self, ParserKeyword p_keyword)
175+
static bool ParserWillMatchKeyword(ParserRef self, ParserKeyword p_keyword, bool p_same_row = false)
173176
{
174-
const Token *t_token;
177+
const Token *t_token;
175178
if (!ScannerRetrieve(self -> scanner, t_token))
176179
return false;
180+
181+
if (p_same_row && PositionGetRow(self -> position) != PositionGetRow(t_token -> start))
182+
return false;
177183

178184
if (t_token -> type != kTokenTypeIdentifier ||
179185
!NameEqualToCString(t_token -> value, s_parser_keyword_strings[p_keyword]))
@@ -182,10 +188,10 @@ static bool ParserWillMatchKeyword(ParserRef self, ParserKeyword p_keyword)
182188
return true;
183189
}
184190

185-
static bool ParserWillMatchKeywords(ParserRef self, ParserKeyword *p_keywords)
191+
static bool ParserWillMatchKeywords(ParserRef self, ParserKeyword *p_keywords, bool p_same_row = false)
186192
{
187193
for(uint32_t i = 0; p_keywords[i] != kParserKeyword__None; i++)
188-
if (ParserWillMatchKeyword(self, p_keywords[i]))
194+
if (ParserWillMatchKeyword(self, p_keywords[i], p_same_row))
189195
return true;
190196

191197
return false;
@@ -331,9 +337,9 @@ static bool ParserMatchKeyword(ParserRef self, ParserKeyword p_keyword)
331337
return true;
332338
}
333339

334-
static bool ParserSkipKeyword(ParserRef self, ParserKeyword p_keyword, bool& r_skipped)
340+
static bool ParserSkipKeyword(ParserRef self, ParserKeyword p_keyword, bool& r_skipped, bool p_same_row = false)
335341
{
336-
if (ParserWillMatchKeyword(self, p_keyword))
342+
if (ParserWillMatchKeyword(self, p_keyword, p_same_row))
337343
{
338344
if (!ParserMatchKeyword(self, p_keyword))
339345
return false;
@@ -346,9 +352,9 @@ static bool ParserSkipKeyword(ParserRef self, ParserKeyword p_keyword, bool& r_s
346352
return true;
347353
}
348354

349-
static bool ParserSkipToken(ParserRef self, TokenType p_token, bool& r_skipped)
355+
static bool ParserSkipToken(ParserRef self, TokenType p_token, bool& r_skipped, bool p_same_row = false)
350356
{
351-
if (ParserWillMatchToken(self, p_token))
357+
if (ParserWillMatchToken(self, p_token, p_same_row))
352358
{
353359
const Token *t_token;
354360
if (!ScannerRetrieve(self -> scanner, t_token))
@@ -400,7 +406,6 @@ static bool ParserMatchKeywords(ParserRef self, ParserKeyword *p_keywords, Parse
400406
////////////////////////////////////////////////////////////////////////////////
401407

402408
static bool ParserReduceInterface(ParserRef self);
403-
static bool ParserReduceUseClause(ParserRef self);
404409
static bool ParserReduceHookClause(ParserRef self);
405410
static bool ParserReduceDefinition(ParserRef self);
406411
static bool ParserReduceEnumDefinition(ParserRef self);
@@ -599,9 +604,13 @@ static bool ParserReduceUseDefinition(ParserRef self)
599604
if (!ParserMatchIdentifier(self, t_type_name))
600605
return false;
601606

602-
if (!ParserMatchKeyword(self, kParserKeywordOn))
603-
return InterfaceDefineUse(self -> interface, t_position, t_type_name);
607+
bool t_skipped;
608+
if (!ParserSkipKeyword(self, kParserKeywordOn, t_skipped, true))
609+
return false;
604610

611+
if (!t_skipped)
612+
return InterfaceDefineUse(self -> interface, t_position, t_type_name);
613+
605614
for(;;)
606615
{
607616
NameRef t_platform_name;
@@ -612,7 +621,7 @@ static bool ParserReduceUseDefinition(ParserRef self)
612621
return false;
613622

614623
bool t_skipped_comma;
615-
if (!ParserSkipToken(self, kTokenTypeComma, t_skipped_comma))
624+
if (!ParserSkipToken(self, kTokenTypeComma, t_skipped_comma, true))
616625
return false;
617626

618627
if (!t_skipped_comma)

0 commit comments

Comments
 (0)