From f3ee5a15090d8ba6ec220e1f907ed3af27e57734 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 9 Aug 2019 12:16:47 +0200 Subject: Move numeric names inside of `NameRef` --- crates/ra_syntax/src/validation.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'crates/ra_syntax/src/validation.rs') diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs index 1f904434e..2bb3c0a03 100644 --- a/crates/ra_syntax/src/validation.rs +++ b/crates/ra_syntax/src/validation.rs @@ -1,13 +1,12 @@ mod block; -mod field_expr; use ra_rustc_lexer::unescape; use crate::{ algo::visit::{visitor_ctx, VisitorCtx}, - ast, SyntaxError, SyntaxErrorKind, - SyntaxKind::{BYTE, BYTE_STRING, CHAR, STRING}, - SyntaxNode, TextUnit, T, + ast, AstNode, SyntaxError, SyntaxErrorKind, + SyntaxKind::{BYTE, BYTE_STRING, CHAR, INT_NUMBER, STRING}, + SyntaxNode, SyntaxToken, TextUnit, T, }; #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -101,7 +100,8 @@ pub(crate) fn validate(root: &SyntaxNode) -> Vec { let _ = visitor_ctx(&mut errors) .visit::(validate_literal) .visit::(block::validate_block_node) - .visit::(field_expr::validate_field_expr_node) + .visit::(|it, errors| validate_numeric_name(it.name_ref(), errors)) + .visit::(|it, errors| validate_numeric_name(it.name_ref(), errors)) .accept(&node); } errors @@ -189,3 +189,18 @@ pub(crate) fn validate_block_structure(root: &SyntaxNode) { } } } + +fn validate_numeric_name(name_ref: Option, errors: &mut Vec) { + if let Some(int_token) = int_token(name_ref) { + if int_token.text().chars().any(|c| !c.is_digit(10)) { + errors.push(SyntaxError::new( + SyntaxErrorKind::InvalidTupleIndexFormat, + int_token.text_range(), + )); + } + } + + fn int_token(name_ref: Option) -> Option { + name_ref?.syntax().first_child_or_token()?.into_token().filter(|it| it.kind() == INT_NUMBER) + } +} -- cgit v1.2.3