mirror of
https://github.com/danog/parser.git
synced 2024-11-26 20:04:57 +01:00
parser: support throw
expressions
It's worth noting that a `throw` will always be an expression in the Trunk parser. PHP-Parser will convert standalone `throw` expressions into a dedicated `throw` statement for backwards-compatibility reasons.
This commit is contained in:
parent
06cbbeff40
commit
9ab82059a1
@ -749,6 +749,7 @@ fn identifier_to_keyword(ident: &str) -> Option<TokenKind> {
|
||||
"return" => TokenKind::Return,
|
||||
"static" => TokenKind::Static,
|
||||
"switch" => TokenKind::Switch,
|
||||
"throw" => TokenKind::Throw,
|
||||
"trait" => TokenKind::Trait,
|
||||
"true" | "TRUE" => TokenKind::True,
|
||||
"try" => TokenKind::Try,
|
||||
|
@ -125,6 +125,7 @@ pub enum TokenKind {
|
||||
Slash,
|
||||
Static,
|
||||
Switch,
|
||||
Throw,
|
||||
Trait,
|
||||
TripleEquals,
|
||||
True,
|
||||
@ -261,6 +262,7 @@ impl Display for TokenKind {
|
||||
Self::Slash => "/",
|
||||
Self::Static => "static",
|
||||
Self::Switch => "switch",
|
||||
Self::Throw => "throw",
|
||||
Self::Trait => "trait",
|
||||
Self::TripleEquals => "===",
|
||||
Self::True => "true",
|
||||
|
@ -394,6 +394,9 @@ pub enum Expression {
|
||||
condition: Box<Self>,
|
||||
arms: Vec<MatchArm>,
|
||||
},
|
||||
Throw {
|
||||
value: Box<Expression>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Serialize)]
|
||||
|
@ -959,6 +959,13 @@ impl Parser {
|
||||
self.skip_comments();
|
||||
|
||||
let mut lhs = match &self.current.kind {
|
||||
TokenKind::Throw => {
|
||||
self.next();
|
||||
|
||||
let value = self.expression(0)?;
|
||||
|
||||
Expression::Throw { value: Box::new(value) }
|
||||
},
|
||||
TokenKind::Clone => {
|
||||
self.next();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user