@@ -180,12 +180,15 @@ ASTNodeUP DILParser::ParsePostfixExpression() {
180180//
181181// primary_expression:
182182// numeric_literal
183+ // boolean_literal
183184// id_expression
184185// "(" expression ")"
185186//
186187ASTNodeUP DILParser::ParsePrimaryExpression () {
187188 if (CurToken ().IsOneOf ({Token::integer_constant, Token::float_constant}))
188189 return ParseNumericLiteral ();
190+ if (CurToken ().IsOneOf ({Token::kw_true, Token::kw_false}))
191+ return ParseBooleanLiteral ();
189192 if (CurToken ().IsOneOf (
190193 {Token::coloncolon, Token::identifier, Token::l_paren})) {
191194 // Save the source location for the diagnostics message.
@@ -336,6 +339,20 @@ std::string DILParser::ParseUnqualifiedId() {
336339 return identifier;
337340}
338341
342+ // Parse an boolean_literal.
343+ //
344+ // boolean_literal:
345+ // "true"
346+ // "false"
347+ //
348+ ASTNodeUP DILParser::ParseBooleanLiteral () {
349+ ExpectOneOf (std::vector<Token::Kind>{Token::kw_true, Token::kw_false});
350+ uint32_t loc = CurToken ().GetLocation ();
351+ bool literal_value = CurToken ().Is (Token::kw_true);
352+ m_dil_lexer.Advance ();
353+ return std::make_unique<BooleanLiteralNode>(loc, literal_value);
354+ }
355+
339356void DILParser::BailOut (const std::string &error, uint32_t loc,
340357 uint16_t err_len) {
341358 if (m_error)
@@ -444,4 +461,12 @@ void DILParser::Expect(Token::Kind kind) {
444461 }
445462}
446463
464+ void DILParser::ExpectOneOf (std::vector<Token::Kind> kinds_vec) {
465+ if (!CurToken ().IsOneOf (kinds_vec)) {
466+ BailOut (llvm::formatv (" expected any of ({0}), got: {1}" ,
467+ llvm::iterator_range (kinds_vec), CurToken ()),
468+ CurToken ().GetLocation (), CurToken ().GetSpelling ().length ());
469+ }
470+ }
471+
447472} // namespace lldb_private::dil
0 commit comments