summaryrefslogtreecommitdiff
path: root/src/lexer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lexer.rs')
-rw-r--r--src/lexer.rs13
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 @@
1use std::iter::Iterator; 1use std::iter::Iterator;
2//use core::error::Error; 2//use core::error::Error;
3use std::str::CharIndices; 3use std::str::CharIndices;
4use std::fmt;
4 5
5use crate::Position; 6use crate::Position;
6 7
7#[derive(Debug,Copy,Clone)] 8#[derive(Debug,Copy,Clone,PartialEq)]
8pub enum ErrorType { 9pub enum ErrorType {
9 UnexpectedChar(char), 10 UnexpectedChar(char),
10} 11}
11 12
12#[derive(Debug,Copy,Clone)] 13#[derive(Debug,Copy,Clone,PartialEq)]
13pub enum SymbolType<'a> { 14pub 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)]
30pub struct Symbol<'a> { 31pub 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
37impl<'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
36impl<'a> Symbol<'a> { 43impl<'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 {