From 9d0cda4bc84350961f3884e75a1c20e62c449ede Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 Feb 2019 15:03:31 +0300 Subject: slightly better name --- crates/ra_syntax/src/grammar/expressions.rs | 4 ++-- crates/ra_syntax/src/parser_api.rs | 24 ++++++++++++++++-------- crates/ra_syntax/src/parser_impl.rs | 4 ++-- 3 files changed, 20 insertions(+), 12 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/grammar/expressions.rs b/crates/ra_syntax/src/grammar/expressions.rs index 28fcb1f7d..d5a4f4d7b 100644 --- a/crates/ra_syntax/src/grammar/expressions.rs +++ b/crates/ra_syntax/src/grammar/expressions.rs @@ -138,7 +138,7 @@ enum Op { } fn current_op(p: &Parser) -> (u8, Op) { - if let Some(t) = p.next3() { + if let Some(t) = p.current3() { match t { (L_ANGLE, L_ANGLE, EQ) => return (1, Op::Composite(SHLEQ, 3)), (R_ANGLE, R_ANGLE, EQ) => return (1, Op::Composite(SHREQ, 3)), @@ -146,7 +146,7 @@ fn current_op(p: &Parser) -> (u8, Op) { } } - if let Some(t) = p.next2() { + if let Some(t) = p.current2() { match t { (PLUS, EQ) => return (1, Op::Composite(PLUSEQ, 2)), (MINUS, EQ) => return (1, Op::Composite(MINUSEQ, 2)), diff --git a/crates/ra_syntax/src/parser_api.rs b/crates/ra_syntax/src/parser_api.rs index 504df753e..dc556190d 100644 --- a/crates/ra_syntax/src/parser_api.rs +++ b/crates/ra_syntax/src/parser_api.rs @@ -25,6 +25,22 @@ impl<'t> Parser<'t> { self.nth(0) } + /// Returns the kinds of the current two tokens, if they are not separated + /// by trivia. + /// + /// Useful for parsing things like `>>`. + pub(crate) fn current2(&self) -> Option<(SyntaxKind, SyntaxKind)> { + self.0.current2() + } + + /// Returns the kinds of the current three tokens, if they are not separated + /// by trivia. + /// + /// Useful for parsing things like `=>>`. + pub(crate) fn current3(&self) -> Option<(SyntaxKind, SyntaxKind, SyntaxKind)> { + self.0.current3() + } + /// Lookahead operation: returns the kind of the next nth /// token. pub(crate) fn nth(&self, n: u32) -> SyntaxKind { @@ -41,14 +57,6 @@ impl<'t> Parser<'t> { kinds.contains(self.current()) } - pub(crate) fn next2(&self) -> Option<(SyntaxKind, SyntaxKind)> { - self.0.next2() - } - - pub(crate) fn next3(&self) -> Option<(SyntaxKind, SyntaxKind, SyntaxKind)> { - self.0.next3() - } - /// Checks if the current token is contextual keyword with text `t`. pub(crate) fn at_contextual_kw(&self, t: &str) -> bool { self.0.at_kw(t) diff --git a/crates/ra_syntax/src/parser_impl.rs b/crates/ra_syntax/src/parser_impl.rs index 1f43aa9f9..01d156899 100644 --- a/crates/ra_syntax/src/parser_impl.rs +++ b/crates/ra_syntax/src/parser_impl.rs @@ -82,7 +82,7 @@ impl<'t> ParserImpl<'t> { self.events } - pub(super) fn next2(&self) -> Option<(SyntaxKind, SyntaxKind)> { + pub(super) fn current2(&self) -> Option<(SyntaxKind, SyntaxKind)> { let c1 = self.parser_input.kind(self.pos); let c2 = self.parser_input.kind(self.pos + 1); if self.parser_input.token_start_at(self.pos + 1) @@ -94,7 +94,7 @@ impl<'t> ParserImpl<'t> { } } - pub(super) fn next3(&self) -> Option<(SyntaxKind, SyntaxKind, SyntaxKind)> { + pub(super) fn current3(&self) -> Option<(SyntaxKind, SyntaxKind, SyntaxKind)> { let c1 = self.parser_input.kind(self.pos); let c2 = self.parser_input.kind(self.pos + 1); let c3 = self.parser_input.kind(self.pos + 2); -- cgit v1.2.3