lexer: produce shorthand ternary tokens

This commit is contained in:
Ryan Chandler 2022-08-09 11:58:22 +01:00
parent dc4cb10ac3
commit 0ae93c2ea1
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA
2 changed files with 6 additions and 0 deletions

View File

@ -225,6 +225,10 @@ impl Lexer {
} else {
TokenKind::Coalesce
}
} else if let Some(':') = self.peek {
self.col += 1;
self.next();
TokenKind::QuestionColon
} else {
TokenKind::Question
}

View File

@ -117,6 +117,7 @@ pub enum TokenKind {
Public,
QualifiedIdentifier(String),
Question,
QuestionColon,
Require,
RequireOnce,
Return,
@ -258,6 +259,7 @@ impl Display for TokenKind {
Self::Public => "public",
Self::QualifiedIdentifier(id) => &id[..],
Self::Question => "?",
Self::QuestionColon => "?:",
Self::Require => "require",
Self::RequireOnce => "require_once",
Self::Return => "return",