mirror of
https://github.com/danog/parser.git
synced 2025-01-22 13:01:32 +01:00
parser: support multiple unions and intersections
This commit is contained in:
parent
2e450cea70
commit
c4fdc85d64
@ -132,6 +132,8 @@ impl Parser {
|
||||
|
||||
if self.current.kind != TokenKind::Pipe {
|
||||
break;
|
||||
} else {
|
||||
self.next();
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,6 +151,8 @@ impl Parser {
|
||||
|
||||
if self.current.kind != TokenKind::Ampersand {
|
||||
break;
|
||||
} else {
|
||||
self.next();
|
||||
}
|
||||
}
|
||||
|
||||
@ -2861,6 +2865,22 @@ mod tests {
|
||||
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]
|
||||
@ -2880,6 +2900,22 @@ mod tests {
|
||||
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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user