lexer: Add ::
and #!
tokens
This commit is contained in:
parent
c3e02d21ad
commit
9b7cf9c017
@ -100,13 +100,13 @@ impl<'t> Lexer<'t> {
|
||||
'\\' => self.consume()?.produce(Type::Backslash, ()),
|
||||
'!' => self.consume()?.bang(),
|
||||
'|' => self.consume()?.bar(),
|
||||
':' => self.consume()?.produce(Type::Colon, ()),
|
||||
':' => self.consume()?.colon(),
|
||||
',' => self.consume()?.produce(Type::Comma, ()),
|
||||
'.' => self.consume()?.dot(),
|
||||
'=' => self.consume()?.equal(),
|
||||
'`' => self.consume()?.produce(Type::Grave, ()),
|
||||
'>' => self.consume()?.greater(),
|
||||
'#' => self.consume()?.produce(Type::Hash, ()),
|
||||
'#' => self.consume()?.hash(),
|
||||
'<' => self.consume()?.less(),
|
||||
'-' => self.consume()?.minus(),
|
||||
'+' => self.consume()?.plus(),
|
||||
@ -203,6 +203,12 @@ impl<'t> Lexer<'t> {
|
||||
_ => self.produce(Type::Bar, ()),
|
||||
}
|
||||
}
|
||||
fn colon(&mut self) -> LResult<Token> {
|
||||
match self.peek() {
|
||||
Ok(':') => self.consume()?.produce(Type::ColonColon, ()),
|
||||
_ => self.produce(Type::Colon, ()),
|
||||
}
|
||||
}
|
||||
fn dot(&mut self) -> LResult<Token> {
|
||||
match self.peek() {
|
||||
Ok('.') => {
|
||||
@ -235,6 +241,12 @@ impl<'t> Lexer<'t> {
|
||||
_ => self.produce(Type::Gt, ()),
|
||||
}
|
||||
}
|
||||
fn hash(&mut self) -> LResult<Token> {
|
||||
match self.peek() {
|
||||
Ok('!') => self.consume()?.produce(Type::HashBang, ()),
|
||||
_ => self.produce(Type::Hash, ()),
|
||||
}
|
||||
}
|
||||
fn less(&mut self) -> LResult<Token> {
|
||||
match self.peek() {
|
||||
Ok('=') => self.consume()?.produce(Type::LtEq, ()),
|
||||
|
@ -36,6 +36,7 @@ pub enum Type {
|
||||
BarBar, // ||
|
||||
BarEq, // |=
|
||||
Colon, // :
|
||||
ColonColon, // ::
|
||||
Comma, // ,
|
||||
Dot, // .
|
||||
DotDot, // ..
|
||||
@ -49,6 +50,7 @@ pub enum Type {
|
||||
GtGt, // >>
|
||||
GtGtEq, // >>=
|
||||
Hash, // #
|
||||
HashBang, // #!
|
||||
Lt, // <
|
||||
LtEq, // <=
|
||||
LtLt, // <<
|
||||
@ -119,6 +121,7 @@ impl Display for Type {
|
||||
Type::BarBar => "or-or".fmt(f),
|
||||
Type::BarEq => "or-assign".fmt(f),
|
||||
Type::Colon => "colon".fmt(f),
|
||||
Type::ColonColon => "path separator".fmt(f),
|
||||
Type::Comma => "comma".fmt(f),
|
||||
Type::Dot => "dot".fmt(f),
|
||||
Type::DotDot => "exclusive range".fmt(f),
|
||||
@ -132,6 +135,7 @@ impl Display for Type {
|
||||
Type::GtGt => "shift right".fmt(f),
|
||||
Type::GtGtEq => "shift right-assign".fmt(f),
|
||||
Type::Hash => "hash".fmt(f),
|
||||
Type::HashBang => "shebang".fmt(f),
|
||||
Type::Lt => "less than".fmt(f),
|
||||
Type::LtEq => "less than or equal to".fmt(f),
|
||||
Type::LtLt => "shift left".fmt(f),
|
||||
|
Loading…
Reference in New Issue
Block a user