From 1e1e2e83c462b7efacaa0e33812beed72a88ab5f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 5 Aug 2018 16:09:25 +0300 Subject: compound ops --- src/parser_impl/input.rs | 17 ++++++++++++++++- src/parser_impl/mod.rs | 19 ++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) (limited to 'src/parser_impl') diff --git a/src/parser_impl/input.rs b/src/parser_impl/input.rs index db76364b2..c0fe4d488 100644 --- a/src/parser_impl/input.rs +++ b/src/parser_impl/input.rs @@ -36,7 +36,22 @@ impl<'t> ParserInput<'t> { self.tokens[idx].kind } - #[allow(unused)] + pub fn len(&self, pos: InputPosition) -> TextUnit { + let idx = pos.0 as usize; + if !(idx < self.tokens.len()) { + return 0.into(); + } + self.tokens[idx].len + } + + pub fn start(&self, pos: InputPosition) -> TextUnit { + let idx = pos.0 as usize; + if !(idx < self.tokens.len()) { + return 0.into(); + } + self.start_offsets[idx] + } + pub fn text(&self, pos: InputPosition) -> &'t str { let idx = pos.0 as usize; if !(idx < self.tokens.len()) { diff --git a/src/parser_impl/mod.rs b/src/parser_impl/mod.rs index 2791c8da5..d640a7784 100644 --- a/src/parser_impl/mod.rs +++ b/src/parser_impl/mod.rs @@ -65,6 +65,11 @@ impl<'t> ParserImpl<'t> { self.events } + pub(super) fn at_compound2(&self, c1: SyntaxKind, c2: SyntaxKind) -> bool { + self.inp.kind(self.pos) == c1 && self.inp.kind(self.pos + 1) == c2 + && self.inp.start(self.pos + 1) == self.inp.start(self.pos) + self.inp.len(self.pos) + } + pub(super) fn nth(&self, n: u32) -> SyntaxKind { self.inp.kind(self.pos + n) } @@ -87,7 +92,7 @@ impl<'t> ParserImpl<'t> { if kind == EOF { return; } - self.do_bump(kind); + self.do_bump(kind, 1); } pub(super) fn bump_remap(&mut self, kind: SyntaxKind) { @@ -95,14 +100,18 @@ impl<'t> ParserImpl<'t> { // TODO: panic!? return; } - self.do_bump(kind); + self.do_bump(kind, 1); + } + + pub(super) fn bump_compound(&mut self, kind: SyntaxKind, n: u8) { + self.do_bump(kind, n); } - fn do_bump(&mut self, kind: SyntaxKind) { - self.pos += 1; + fn do_bump(&mut self, kind: SyntaxKind, n_raw_tokens: u8) { + self.pos += u32::from(n_raw_tokens); self.event(Event::Token { kind, - n_raw_tokens: 1, + n_raw_tokens, }); } -- cgit v1.2.3