From d436ab05810c208b41a1b61896d3d87691cd9e99 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sun, 28 Apr 2019 23:46:03 +0800 Subject: Refactor parser handle mult-char punct internally --- crates/ra_syntax/src/parsing/lexer.rs | 71 ++++++----------------------------- 1 file changed, 12 insertions(+), 59 deletions(-) (limited to 'crates/ra_syntax/src/parsing') diff --git a/crates/ra_syntax/src/parsing/lexer.rs b/crates/ra_syntax/src/parsing/lexer.rs index 3ae42912c..a3791b503 100644 --- a/crates/ra_syntax/src/parsing/lexer.rs +++ b/crates/ra_syntax/src/parsing/lexer.rs @@ -88,65 +88,18 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind { } match c { - // Multi-byte tokens. - '.' => { - return match (ptr.current(), ptr.nth(1)) { - (Some('.'), Some('.')) => { - ptr.bump(); - ptr.bump(); - DOTDOTDOT - } - (Some('.'), Some('=')) => { - ptr.bump(); - ptr.bump(); - DOTDOTEQ - } - (Some('.'), _) => { - ptr.bump(); - DOTDOT - } - _ => DOT, - }; - } - ':' => { - return match ptr.current() { - Some(':') => { - ptr.bump(); - COLONCOLON - } - _ => COLON, - }; - } - '=' => { - return match ptr.current() { - Some('=') => { - ptr.bump(); - EQEQ - } - Some('>') => { - ptr.bump(); - FAT_ARROW - } - _ => EQ, - }; - } - '!' => { - return match ptr.current() { - Some('=') => { - ptr.bump(); - NEQ - } - _ => EXCL, - }; - } - '-' => { - return if ptr.at('>') { - ptr.bump(); - THIN_ARROW - } else { - MINUS - }; - } + // Possiblily multi-byte tokens, + // but we only produce single byte token now + // DOTDOTDOT, DOTDOT, DOTDOTEQ, DOT + '.' => return DOT, + // COLONCOLON COLON + ':' => return COLON, + // EQEQ FATARROW EQ + '=' => return EQ, + // NEQ EXCL + '!' => return EXCL, + // THIN_ARROW MINUS + '-' => return MINUS, // If the character is an ident start not followed by another single // quote, then this is a lifetime name: -- cgit v1.2.3