From fa2ff9e8ce62930ffca01fcf68998555a6d56acc Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Fri, 23 Dec 2016 17:38:33 -0700 Subject: [PATCH] chars are Lexable --- src/characters.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/characters.rs b/src/characters.rs index 8b705d6..5e943b1 100644 --- a/src/characters.rs +++ b/src/characters.rs @@ -42,6 +42,39 @@ pub fn identifier_subsequents() -> CharSet { subsequents } +// +// char +// + +pub trait Lexable { + fn is_left_paren(&self) -> bool; + fn is_right_paren(&self) -> bool; + fn is_identifier_initial(&self) -> bool; + fn is_identifier_subsequent(&self) -> bool; +} + +impl Lexable for char { + fn is_left_paren(&self) -> bool { + self == &'(' + } + + fn is_right_paren(&self) -> bool { + self == &')' + } + + fn is_identifier_initial(&self) -> bool { + identifier_initials().contains(&self) + } + + fn is_identifier_subsequent(&self) -> bool { + identifier_subsequents().contains(&self) + } +} + +// +// str and String +// + pub trait RelativeIndexable { fn index_before(&self, &usize) -> Option; fn index_after(&self, &usize) -> Option;