parser: support multiple unions and intersections

This commit is contained in:
Ryan Chandler 2022-09-12 12:45:31 +01:00
parent 2e450cea70
commit c4fdc85d64
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA

View File

@ -132,6 +132,8 @@ impl Parser {
if self.current.kind != TokenKind::Pipe { if self.current.kind != TokenKind::Pipe {
break; break;
} else {
self.next();
} }
} }
@ -149,6 +151,8 @@ impl Parser {
if self.current.kind != TokenKind::Ampersand { if self.current.kind != TokenKind::Ampersand {
break; break;
} else {
self.next();
} }
} }
@ -2861,6 +2865,22 @@ mod tests {
return_type: None, return_type: None,
}], }],
); );
assert_ast(
"<?php function foo(string|int|float $b) {}", &[
Statement::Function {
name: "foo".to_string().into(),
params: vec![Param {
name: Expression::Variable { name: "b".into() },
r#type: Some(Type::Union(vec!["string".into(), "int".into(), "float".into()])),
variadic: false,
default: None,
flag: None,
}],
body: vec![],
return_type: None,
}
]);
} }
#[test] #[test]
@ -2880,6 +2900,22 @@ mod tests {
return_type: None, return_type: None,
}], }],
); );
assert_ast(
"<?php function foo(Foo&Bar&Baz $b) {}",
&[Statement::Function {
name: "foo".to_string().into(),
params: vec![Param {
name: Expression::Variable { name: "b".into() },
r#type: Some(Type::Intersection(vec!["Foo".into(), "Bar".into(), "Baz".into()])),
variadic: false,
default: None,
flag: None,
}],
body: vec![],
return_type: None,
}],
);
} }
#[test] #[test]