parser: support /=

This commit is contained in:
Ryan Chandler 2022-08-10 00:50:04 +01:00
parent a83f1b80bb
commit 0627e05642
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA
4 changed files with 10 additions and 2 deletions

View File

@ -575,9 +575,13 @@ impl Lexer {
} else {
TokenKind::Comment(buffer)
}
} else if let Some('=') = self.peek {
self.col += 1;
self.next();
TokenKind::SlashEquals
} else if char == '/' && let Some(t) = self.peek && t != '/' {
TokenKind::Slash
} else if char == '#' && let Some(t) = self.peek && t == '[' {
} else if char == '#' && let Some('[') = self.peek {
TokenKind::Attribute
} else {
self.next();

View File

@ -129,6 +129,7 @@ pub enum TokenKind {
RightParen,
SemiColon,
Slash,
SlashEquals,
Static,
StringCast,
Switch,
@ -276,6 +277,7 @@ impl Display for TokenKind {
Self::RightParen => ")",
Self::SemiColon => ";",
Self::Slash => "/",
Self::SlashEquals => "/=",
Self::Static => "static",
Self::StringCast => "(string)",
Self::Switch => "switch",

View File

@ -521,6 +521,7 @@ pub enum InfixOp {
CoalesceAssign,
MulAssign,
SubAssign,
DivAssign,
}
impl From<TokenKind> for InfixOp {
@ -549,6 +550,7 @@ impl From<TokenKind> for InfixOp {
TokenKind::CoalesceEqual => Self::CoalesceAssign,
TokenKind::AsteriskEqual => Self::MulAssign,
TokenKind::MinusEquals => Self::SubAssign,
TokenKind::SlashEquals => Self::DivAssign,
_ => unreachable!()
}
}

View File

@ -1664,7 +1664,7 @@ fn infix_binding_power(t: &TokenKind) -> Option<(u8, u8)> {
TokenKind::Question | TokenKind::QuestionColon => (6, 7),
TokenKind::BooleanAnd => (4, 5),
TokenKind::BooleanOr => (2, 3),
TokenKind::Equals | TokenKind::PlusEquals | TokenKind::MinusEquals | TokenKind::DotEquals | TokenKind::CoalesceEqual | TokenKind::AsteriskEqual => (0, 1),
TokenKind::Equals | TokenKind::PlusEquals | TokenKind::MinusEquals | TokenKind::DotEquals | TokenKind::CoalesceEqual | TokenKind::AsteriskEqual | TokenKind::SlashEquals => (0, 1),
_ => return None,
})
}