mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:27:44 +00:00
LibCpp: Parse character literals
This commit is contained in:
parent
3295609aea
commit
68e9a05472
1 changed files with 6 additions and 3 deletions
|
@ -455,6 +455,8 @@ bool Parser::match_literal()
|
||||||
switch (peek().type()) {
|
switch (peek().type()) {
|
||||||
case Token::Type::Integer:
|
case Token::Type::Integer:
|
||||||
return true;
|
return true;
|
||||||
|
case Token::Type::SingleQuotedString:
|
||||||
|
return true;
|
||||||
case Token::Type::DoubleQuotedString:
|
case Token::Type::DoubleQuotedString:
|
||||||
return true;
|
return true;
|
||||||
case Token::Type::Float:
|
case Token::Type::Float:
|
||||||
|
@ -516,9 +518,10 @@ NonnullRefPtr<Expression> Parser::parse_literal(ASTNode& parent)
|
||||||
auto token = consume();
|
auto token = consume();
|
||||||
return create_ast_node<NumericLiteral>(parent, token.start(), token.end(), text_of_token(token));
|
return create_ast_node<NumericLiteral>(parent, token.start(), token.end(), text_of_token(token));
|
||||||
}
|
}
|
||||||
case Token::Type::DoubleQuotedString: {
|
case Token::Type::SingleQuotedString:
|
||||||
|
[[fallthrough]];
|
||||||
|
case Token::Type::DoubleQuotedString:
|
||||||
return parse_string_literal(parent);
|
return parse_string_literal(parent);
|
||||||
}
|
|
||||||
case Token::Type::Keyword: {
|
case Token::Type::Keyword: {
|
||||||
if (match_boolean_literal())
|
if (match_boolean_literal())
|
||||||
return parse_boolean_literal(parent);
|
return parse_boolean_literal(parent);
|
||||||
|
@ -935,7 +938,7 @@ NonnullRefPtr<StringLiteral> Parser::parse_string_literal(ASTNode& parent)
|
||||||
Optional<size_t> end_token_index;
|
Optional<size_t> end_token_index;
|
||||||
while (!eof()) {
|
while (!eof()) {
|
||||||
auto token = peek();
|
auto token = peek();
|
||||||
if (token.type() != Token::Type::DoubleQuotedString && token.type() != Token::Type::EscapeSequence) {
|
if (token.type() != Token::Type::DoubleQuotedString && token.type() != Token::Type::SingleQuotedString && token.type() != Token::Type::EscapeSequence) {
|
||||||
VERIFY(start_token_index.has_value());
|
VERIFY(start_token_index.has_value());
|
||||||
end_token_index = m_state.token_index - 1;
|
end_token_index = m_state.token_index - 1;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue