@@ -183,36 +183,22 @@ ASTNodeUP DILParser::ParsePostfixExpression() {
183183// "(" expression ")"
184184//
185185ASTNodeUP DILParser::ParsePrimaryExpression () {
186- if (CurToken ().IsOneOf ({Token::coloncolon, Token::identifier})) {
186+ if (CurToken ().IsOneOf (
187+ {Token::coloncolon, Token::identifier, Token::l_paren})) {
187188 // Save the source location for the diagnostics message.
188189 uint32_t loc = CurToken ().GetLocation ();
189- auto identifier = ParseIdExpression ();
190+ std::string identifier = ParseIdExpression ();
190191
191- return std::make_unique<IdentifierNode>(loc, identifier);
192+ if (!identifier.empty ())
193+ return std::make_unique<IdentifierNode>(loc, identifier);
192194 }
193195
194- uint32_t loc = CurToken ().GetLocation ();
195- std::string nested_name_specifier;
196-
197196 if (CurToken ().Is (Token::l_paren)) {
198- nested_name_specifier = ParseNestedNameSpecifier ();
199-
200- if (!nested_name_specifier.empty ()) {
201- if (!CurToken ().Is (Token::identifier)) {
202- BailOut (" Expected an identifier, but not found." ,
203- CurToken ().GetLocation (), CurToken ().GetSpelling ().length ());
204- }
205-
206- std::string unqualified_id = ParseUnqualifiedId ();
207- return std::make_unique<IdentifierNode>(loc, nested_name_specifier +
208- unqualified_id);
209- } else {
210- m_dil_lexer.Advance ();
211- auto expr = ParseExpression ();
212- Expect (Token::r_paren);
213- m_dil_lexer.Advance ();
214- return expr;
215- }
197+ m_dil_lexer.Advance ();
198+ auto expr = ParseExpression ();
199+ Expect (Token::r_paren);
200+ m_dil_lexer.Advance ();
201+ return expr;
216202 }
217203
218204 BailOut (llvm::formatv (" Unexpected token: {0}" , CurToken ()),
@@ -251,9 +237,8 @@ std::string DILParser::ParseNestedNameSpecifier() {
251237 Expect (Token::coloncolon);
252238 m_dil_lexer.Advance ();
253239 if (!CurToken ().Is (Token::identifier) && !CurToken ().Is (Token::l_paren)) {
254- BailOut (
255- " Expected an identifier or anonymous namespeace, but not found." ,
256- CurToken ().GetLocation (), CurToken ().GetSpelling ().length ());
240+ BailOut (" Expected an identifier or anonymous namespace, but not found." ,
241+ CurToken ().GetLocation (), CurToken ().GetSpelling ().length ());
257242 }
258243 // Continue parsing the nested_namespace_specifier.
259244 std::string identifier2 = ParseNestedNameSpecifier ();
@@ -317,6 +302,9 @@ std::string DILParser::ParseIdExpression() {
317302 nested_name_specifier, unqualified_id);
318303 }
319304
305+ if (!CurToken ().Is (Token::identifier))
306+ return " " ;
307+
320308 // No nested_name_specifier, but with global scope -- this is also a
321309 // qualified_id production. Follow the second production rule.
322310 if (global_scope) {
0 commit comments