From 85c42fba1291f1cc41fb7bfec63117895b394fc5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 4 Feb 2018 16:46:26 +0300 Subject: Support contextual tokens --- src/parser/parser.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/parser/parser.rs') diff --git a/src/parser/parser.rs b/src/parser/parser.rs index bb775c4a5..7e1b22ee5 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -1,6 +1,6 @@ use super::Event; use super::input::{InputPosition, ParserInput}; -use SyntaxKind::{self, EOF, TOMBSTONE}; +use SyntaxKind::{self, EOF, TOMBSTONE, IDENT}; pub(crate) struct Marker { pos: u32, @@ -145,14 +145,31 @@ impl<'t> Parser<'t> { }); } + pub(crate) fn bump_remap(&mut self, kind: SyntaxKind) { + if self.current() == EOF { + // TODO: panic!? + return; + } + self.pos += 1; + self.event(Event::Token { + kind, + n_raw_tokens: 1, + }); + } + pub(crate) fn nth(&self, n: u32) -> SyntaxKind { self.inp.kind(self.pos + n) } + pub(crate) fn at_kw(&self, n: u32, t: &str) -> bool { + self.nth(n) == IDENT && self.inp.text(self.pos + n) == t + } + pub(crate) fn current(&self) -> SyntaxKind { self.nth(0) } + fn event(&mut self, event: Event) { self.events.push(event) } -- cgit v1.2.3 From c119e8fd8b0106bb2e031e76ac1be89bd10a0674 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 4 Feb 2018 17:06:00 +0300 Subject: G: unsafe fn --- src/parser/parser.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/parser/parser.rs') diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 7e1b22ee5..53a116fb7 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -1,6 +1,6 @@ use super::Event; use super::input::{InputPosition, ParserInput}; -use SyntaxKind::{self, EOF, TOMBSTONE, IDENT}; +use SyntaxKind::{self, EOF, TOMBSTONE}; pub(crate) struct Marker { pos: u32, @@ -161,8 +161,8 @@ impl<'t> Parser<'t> { self.inp.kind(self.pos + n) } - pub(crate) fn at_kw(&self, n: u32, t: &str) -> bool { - self.nth(n) == IDENT && self.inp.text(self.pos + n) == t + pub(crate) fn at_kw(&self, t: &str) -> bool { + self.inp.text(self.pos) == t } pub(crate) fn current(&self) -> SyntaxKind { -- cgit v1.2.3 From 351107d0b143e2c3497bd0f424f0d76bc51df0c0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 4 Feb 2018 17:06:43 +0300 Subject: Reformat --- src/parser/parser.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'src/parser/parser.rs') diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 53a116fb7..752d532d0 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -169,7 +169,6 @@ impl<'t> Parser<'t> { self.nth(0) } - fn event(&mut self, event: Event) { self.events.push(event) } -- cgit v1.2.3