Support c string literals

This commit is contained in:
Lukas Wirth 2023-05-18 11:06:05 +02:00
parent 099b5b3b15
commit 4b577e2bc8
21 changed files with 176 additions and 34 deletions

View file

@ -9,7 +9,7 @@ use rustc_lexer::unescape::{self, unescape_literal, Mode};
use crate::{
algo,
ast::{self, HasAttrs, HasVisibility},
ast::{self, HasAttrs, HasVisibility, IsString},
match_ast, AstNode, SyntaxError,
SyntaxKind::{CONST, FN, INT_NUMBER, TYPE_ALIAS},
SyntaxNode, SyntaxToken, TextSize, T,
@ -156,6 +156,17 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
}
}
}
ast::LiteralKind::CString(s) => {
if !s.is_raw() {
if let Some(without_quotes) = unquote(text, 2, '"') {
unescape_literal(without_quotes, Mode::ByteStr, &mut |range, char| {
if let Err(err) = char {
push_err(1, range.start, err);
}
});
}
}
}
ast::LiteralKind::Char(_) => {
if let Some(without_quotes) = unquote(text, 1, '\'') {
unescape_literal(without_quotes, Mode::Char, &mut |range, char| {