Cleanup API

This commit is contained in:
Aleksey Kladov 2020-11-06 22:52:22 +01:00
parent 7f12a1f225
commit 5db789df9c
5 changed files with 84 additions and 96 deletions

View file

@ -4,7 +4,7 @@ mod block;
use crate::{
algo, ast, match_ast, AstNode, SyntaxError,
SyntaxKind::{BYTE, CHAR, CONST, FN, INT_NUMBER, TYPE_ALIAS},
SyntaxKind::{CONST, FN, INT_NUMBER, TYPE_ALIAS},
SyntaxNode, SyntaxToken, TextSize, T,
};
use rowan::Direction;
@ -121,41 +121,42 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
acc.push(SyntaxError::new_at_offset(rustc_unescape_error_to_string(err), off));
};
if let Some(s) = literal.as_string() {
if !s.is_raw() {
if let Some(without_quotes) = unquote(text, 1, '"') {
unescape_literal(without_quotes, Mode::Str, &mut |range, char| {
if let Err(err) = char {
push_err(1, (range.start, err));
}
})
match literal.kind() {
ast::LiteralKind::String(s) => {
if !s.is_raw() {
if let Some(without_quotes) = unquote(text, 1, '"') {
unescape_literal(without_quotes, Mode::Str, &mut |range, char| {
if let Err(err) = char {
push_err(1, (range.start, err));
}
})
}
}
}
}
if let Some(s) = literal.as_byte_string() {
if !s.is_raw() {
if let Some(without_quotes) = unquote(text, 2, '"') {
unescape_byte_literal(without_quotes, Mode::ByteStr, &mut |range, char| {
if let Err(err) = char {
push_err(2, (range.start, err));
}
})
ast::LiteralKind::ByteString(s) => {
if !s.is_raw() {
if let Some(without_quotes) = unquote(text, 2, '"') {
unescape_byte_literal(without_quotes, Mode::ByteStr, &mut |range, char| {
if let Err(err) = char {
push_err(2, (range.start, err));
}
})
}
}
}
}
match token.kind() {
BYTE => {
if let Some(Err(e)) = unquote(text, 2, '\'').map(unescape_byte) {
push_err(2, e);
}
}
CHAR => {
ast::LiteralKind::Char => {
if let Some(Err(e)) = unquote(text, 1, '\'').map(unescape_char) {
push_err(1, e);
}
}
_ => (),
ast::LiteralKind::Byte => {
if let Some(Err(e)) = unquote(text, 2, '\'').map(unescape_byte) {
push_err(2, e);
}
}
ast::LiteralKind::IntNumber(_)
| ast::LiteralKind::FloatNumber(_)
| ast::LiteralKind::Bool(_) => {}
}
}