Properly lex ?
, |
, \f
, and =
This commit is contained in:
parent
37ad341f91
commit
0824a019c2
@ -62,6 +62,10 @@ pub enum Symbol {
|
||||
DoubleQuote,
|
||||
/// '
|
||||
SingleQuote,
|
||||
/// ?
|
||||
QuestionMark,
|
||||
/// \
|
||||
BackSlash,
|
||||
}
|
||||
|
||||
impl Display for Symbol {
|
||||
@ -94,6 +98,8 @@ impl Display for Symbol {
|
||||
Self::Percent => write!(f, "%"),
|
||||
Self::DoubleQuote => write!(f, "\""),
|
||||
Self::SingleQuote => write!(f, "'"),
|
||||
Self::QuestionMark => write!(f, "?"),
|
||||
Self::BackSlash => write!(f, "\\"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -130,6 +136,8 @@ impl TryFrom<char> for Symbol {
|
||||
'%' => Ok(Self::Percent),
|
||||
'"' => Ok(Self::DoubleQuote),
|
||||
'\'' => Ok(Self::SingleQuote),
|
||||
'?' => Ok(Self::QuestionMark),
|
||||
'\\' => Ok(Self::BackSlash),
|
||||
_ => Err("invalid symbol"),
|
||||
}
|
||||
}
|
||||
|
@ -43,12 +43,15 @@ impl<'a> Iterator for Lexer<'a> {
|
||||
'(' => symbol!(self, OpenParen),
|
||||
')' => symbol!(self, CloseParen),
|
||||
'+' => symbol!(self, Plus),
|
||||
'=' => symbol!(self, Equal),
|
||||
'?' => symbol!(self, QuestionMark),
|
||||
'\\' => symbol!(self, BackSlash),
|
||||
'~' => symbol!(self, Tilde),
|
||||
'\'' => symbol!(self, SingleQuote),
|
||||
'"' => symbol!(self, DoubleQuote),
|
||||
' ' => whitespace!(self, Space),
|
||||
'\t' => whitespace!(self, Tab),
|
||||
'\n' => {
|
||||
'\n' | '\x0C' => {
|
||||
self.buf.next();
|
||||
self.pos.newline();
|
||||
TokenKind::Whitespace(Whitespace::Newline)
|
||||
@ -62,6 +65,7 @@ impl<'a> Iterator for Lexer<'a> {
|
||||
'*' => symbol!(self, Mul),
|
||||
'}' => symbol!(self, CloseCurlyBrace),
|
||||
'&' => symbol!(self, BitAnd),
|
||||
'|' => symbol!(self, BitOr),
|
||||
'/' => self.lex_forward_slash(),
|
||||
'%' => {
|
||||
self.buf.next();
|
||||
|
Loading…
x
Reference in New Issue
Block a user