From 5db789df9c767985a564a31cc593ce7f5964100e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 6 Nov 2020 22:52:22 +0100 Subject: Cleanup API --- crates/syntax/src/validation.rs | 57 +++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'crates/syntax/src/validation.rs') diff --git a/crates/syntax/src/validation.rs b/crates/syntax/src/validation.rs index 62a37c50a..6f45149bf 100644 --- a/crates/syntax/src/validation.rs +++ b/crates/syntax/src/validation.rs @@ -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) { 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)); - } - }) - } - } - } - 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)); - } - }) + 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)); + } + }) + } } } - } - - match token.kind() { - BYTE => { - if let Some(Err(e)) = unquote(text, 2, '\'').map(unescape_byte) { - push_err(2, e); + 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)); + } + }) + } } } - 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(_) => {} } } -- cgit v1.2.3