diff options
Diffstat (limited to 'src/lexer.rs')
| -rw-r--r-- | src/lexer.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/lexer.rs b/src/lexer.rs index 04be350..902bb64 100644 --- a/src/lexer.rs +++ b/src/lexer.rs | |||
| @@ -1,15 +1,16 @@ | |||
| 1 | use std::iter::Iterator; | 1 | use std::iter::Iterator; |
| 2 | //use core::error::Error; | 2 | //use core::error::Error; |
| 3 | use std::str::CharIndices; | 3 | use std::str::CharIndices; |
| 4 | use std::fmt; | ||
| 4 | 5 | ||
| 5 | use crate::Position; | 6 | use crate::Position; |
| 6 | 7 | ||
| 7 | #[derive(Debug,Copy,Clone)] | 8 | #[derive(Debug,Copy,Clone,PartialEq)] |
| 8 | pub enum ErrorType { | 9 | pub enum ErrorType { |
| 9 | UnexpectedChar(char), | 10 | UnexpectedChar(char), |
| 10 | } | 11 | } |
| 11 | 12 | ||
| 12 | #[derive(Debug,Copy,Clone)] | 13 | #[derive(Debug,Copy,Clone,PartialEq)] |
| 13 | pub enum SymbolType<'a> { | 14 | pub enum SymbolType<'a> { |
| 14 | StartFlat, | 15 | StartFlat, |
| 15 | StartPoint, | 16 | StartPoint, |
| @@ -26,13 +27,19 @@ pub enum SymbolType<'a> { | |||
| 26 | EOS, | 27 | EOS, |
| 27 | } | 28 | } |
| 28 | 29 | ||
| 29 | #[derive(Debug,Copy,Clone)] | 30 | #[derive(Copy,Clone)] |
| 30 | pub struct Symbol<'a> { | 31 | pub struct Symbol<'a> { |
| 31 | symbol: SymbolType<'a>, | 32 | symbol: SymbolType<'a>, |
| 32 | start: Position, | 33 | start: Position, |
| 33 | end: Position, | 34 | end: Position, |
| 34 | } | 35 | } |
| 35 | 36 | ||
| 37 | impl<'a> fmt::Debug for Symbol<'a> { | ||
| 38 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| 39 | write!(f, "{:?} @ {}:{}", self.symbol, self.start.line, self.start.column ) | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 36 | impl<'a> Symbol<'a> { | 43 | impl<'a> Symbol<'a> { |
| 37 | pub fn new( symbol: SymbolType<'a>, start: Position, end: Position ) -> Self { | 44 | pub fn new( symbol: SymbolType<'a>, start: Position, end: Position ) -> Self { |
| 38 | Self { | 45 | Self { |
