From 0b5d39f2a204e5ec6cd6205440e4cdc763162814 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 20 Jan 2018 23:25:34 +0300 Subject: Markers API --- src/tree/file_builder.rs | 8 +++++--- src/tree/mod.rs | 15 +++++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'src/tree') diff --git a/src/tree/file_builder.rs b/src/tree/file_builder.rs index 37bd5b2c8..35702ddd7 100644 --- a/src/tree/file_builder.rs +++ b/src/tree/file_builder.rs @@ -48,7 +48,9 @@ impl Sink for FileBuilder { } fn finish_internal(&mut self) { - let (id, _) = self.in_progress.pop().unwrap(); + let (id, _) = self.in_progress.pop().expect( + "trying to complete a node, but there are no in-progress nodes" + ); if !self.in_progress.is_empty() { self.add_len(id); } @@ -77,8 +79,8 @@ impl FileBuilder { self.in_progress.iter().map(|&(idx, _)| self.nodes[idx].kind) .collect::>() ); - assert!( - self.pos == (self.text.len() as u32).into(), + assert_eq!( + self.pos, (self.text.len() as u32).into(), "nodes in FileBuilder do not cover the whole file" ); File { diff --git a/src/tree/mod.rs b/src/tree/mod.rs index d8f843737..3315b926e 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs @@ -10,17 +10,24 @@ pub use self::file_builder::{FileBuilder, Sink}; #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct SyntaxKind(pub(crate) u32); -pub(crate) const EOF: SyntaxKind = SyntaxKind(10000); +pub(crate) const EOF: SyntaxKind = SyntaxKind(!0); pub(crate) const EOF_INFO: SyntaxInfo = SyntaxInfo { name: "EOF" }; +pub(crate) const TOMBSTONE: SyntaxKind = SyntaxKind(!0 - 1); +pub(crate) const TOMBSTONE_INFO: SyntaxInfo = SyntaxInfo { + name: "TOMBSTONE" +}; + + impl SyntaxKind { fn info(self) -> &'static SyntaxInfo { - if self == EOF { - return &EOF_INFO; + match self { + EOF => &EOF_INFO, + TOMBSTONE => &TOMBSTONE_INFO, + _ => syntax_info(self), } - syntax_info(self) } } -- cgit v1.2.3