chore: format

This commit is contained in:
Ryan Chandler 2022-09-15 00:48:59 +01:00
parent 4338b83254
commit 17a48e3ce2
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA

View File

@ -936,14 +936,25 @@ impl Parser {
ret ret
} }
} }
TokenKind::Function if matches!(self.peek.kind, TokenKind::Identifier(_) | TokenKind::Ampersand) => { TokenKind::Function
if matches!(
self.peek.kind,
TokenKind::Identifier(_) | TokenKind::Ampersand
) =>
{
// FIXME: This is incredibly hacky but we don't have a way to look at // FIXME: This is incredibly hacky but we don't have a way to look at
// the next N tokens right now. We could probably do with a `peek_buf()` // the next N tokens right now. We could probably do with a `peek_buf()`
// method like the Lexer has. // method like the Lexer has.
if self.peek.kind == TokenKind::Ampersand { if self.peek.kind == TokenKind::Ampersand {
let mut cloned = self.iter.clone(); let mut cloned = self.iter.clone();
for (index, _) in self.iter.clone().enumerate() { for (index, _) in self.iter.clone().enumerate() {
if ! matches!(cloned.nth(index), Some(Token { kind: TokenKind::Identifier(_), .. })) { if !matches!(
cloned.nth(index),
Some(Token {
kind: TokenKind::Identifier(_),
..
})
) {
let expr = self.expression(Precedence::Lowest)?; let expr = self.expression(Precedence::Lowest)?;
self.semi()?; self.semi()?;
@ -1405,14 +1416,14 @@ impl Parser {
params, params,
body, body,
return_type, return_type,
by_ref by_ref,
} => Ok(Statement::Method { } => Ok(Statement::Method {
name, name,
params, params,
body, body,
flags: vec![], flags: vec![],
return_type, return_type,
by_ref by_ref,
}), }),
_ => unreachable!(), _ => unreachable!(),
}, },
@ -3881,7 +3892,9 @@ mod tests {
#[test] #[test]
fn function_returning_ref() { fn function_returning_ref() {
assert_ast("<?php function &a($b) {}", &[Statement::Function { assert_ast(
"<?php function &a($b) {}",
&[Statement::Function {
name: "a".into(), name: "a".into(),
params: vec![Param { params: vec![Param {
name: Expression::Variable { name: "b".into() }, name: Expression::Variable { name: "b".into() },
@ -3894,47 +3907,51 @@ mod tests {
body: vec![], body: vec![],
return_type: None, return_type: None,
by_ref: true, by_ref: true,
}]); }],
);
} }
#[test] #[test]
fn closure_returning_ref() { fn closure_returning_ref() {
assert_ast("<?php function &() {};", &[ assert_ast(
expr!(Expression::Closure { "<?php function &() {};",
&[expr!(Expression::Closure {
params: vec![], params: vec![],
body: vec![], body: vec![],
return_type: None, return_type: None,
r#static: false, r#static: false,
uses: vec![], uses: vec![],
by_ref: true, by_ref: true,
}) })],
]); );
} }
#[test] #[test]
fn static_closures_returning_by_ref() { fn static_closures_returning_by_ref() {
assert_ast("<?php static function &() {};", &[ assert_ast(
expr!(Expression::Closure { "<?php static function &() {};",
&[expr!(Expression::Closure {
params: vec![], params: vec![],
body: vec![], body: vec![],
return_type: None, return_type: None,
r#static: true, r#static: true,
uses: vec![], uses: vec![],
by_ref: true, by_ref: true,
}) })],
]); );
} }
#[test] #[test]
fn arrow_functions_returning_by_ref() { fn arrow_functions_returning_by_ref() {
assert_ast("<?php fn &() => null;", &[ assert_ast(
expr!(Expression::ArrowFunction { "<?php fn &() => null;",
&[expr!(Expression::ArrowFunction {
params: vec![], params: vec![],
expr: Box::new(Expression::Null), expr: Box::new(Expression::Null),
return_type: None, return_type: None,
by_ref: true, by_ref: true,
}) })],
]); );
} }
fn assert_ast(source: &str, expected: &[Statement]) { fn assert_ast(source: &str, expected: &[Statement]) {