From cb362626f326a565aca34c1a11c95dcb7152b798 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 1 Jan 2018 18:58:46 +0300 Subject: Parser: guess what? Groundwork! --- src/lexer/mod.rs | 3 +++ src/lexer/ptr.rs | 5 +++++ 2 files changed, 8 insertions(+) (limited to 'src/lexer') diff --git a/src/lexer/mod.rs b/src/lexer/mod.rs index 7c4259763..bc5344b5f 100644 --- a/src/lexer/mod.rs +++ b/src/lexer/mod.rs @@ -187,6 +187,9 @@ fn scan_ident(c: char, ptr: &mut Ptr) -> SyntaxKind { return if c == '_' { UNDERSCORE } else { IDENT }; } ptr.bump_while(is_ident_continue); + if let Some(kind) = ident_to_keyword(ptr.current_token_text()) { + return kind; + } IDENT } diff --git a/src/lexer/ptr.rs b/src/lexer/ptr.rs index 2f759119a..ff6ef11fc 100644 --- a/src/lexer/ptr.rs +++ b/src/lexer/ptr.rs @@ -59,6 +59,11 @@ impl<'s> Ptr<'s> { } } + pub fn current_token_text(&self) -> &str { + let len: u32 = self.len.into(); + &self.text[..len as usize] + } + fn chars(&self) -> Chars { let len: u32 = self.len.into(); self.text[len as usize ..].chars() -- cgit v1.2.3