mirror of
https://github.com/danog/parser.git
synced 2024-11-30 04:29:13 +01:00
parser: allow using array & callable at type strings
This commit is contained in:
parent
626af3e31c
commit
5309451588
@ -22,6 +22,17 @@ impl Parser {
|
||||
Ok(expect!(self, TokenKind::Variable(v), v, "expected variable name"))
|
||||
}
|
||||
|
||||
pub(crate) fn full_name_maybe_type_keyword(&mut self) -> ParseResult<String> {
|
||||
match self.current.kind {
|
||||
TokenKind::Array | TokenKind::Callable => {
|
||||
let r = Ok(self.current.kind.to_string());
|
||||
self.next();
|
||||
r
|
||||
},
|
||||
_ => self.full_name()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn ident_maybe_reserved(&mut self) -> ParseResult<String> {
|
||||
match self.current.kind {
|
||||
TokenKind::Static | TokenKind::Abstract | TokenKind::Final | TokenKind::For |
|
||||
|
@ -89,11 +89,11 @@ impl Parser {
|
||||
fn type_string(&mut self) -> ParseResult<Type> {
|
||||
if self.current.kind == TokenKind::Question {
|
||||
self.next();
|
||||
let t = self.full_name()?;
|
||||
let t = self.full_name_maybe_type_keyword()?;
|
||||
return Ok(Type::Nullable(t));
|
||||
}
|
||||
|
||||
let id = self.full_name()?;
|
||||
let id = self.full_name_maybe_type_keyword()?;
|
||||
|
||||
if self.current.kind == TokenKind::Pipe {
|
||||
self.next();
|
||||
@ -101,7 +101,7 @@ impl Parser {
|
||||
let mut types = vec![id];
|
||||
|
||||
while ! self.is_eof() {
|
||||
let id = self.full_name()?;
|
||||
let id = self.full_name_maybe_type_keyword()?;
|
||||
types.push(id);
|
||||
|
||||
if self.current.kind != TokenKind::Pipe {
|
||||
@ -118,7 +118,7 @@ impl Parser {
|
||||
let mut types = vec![id];
|
||||
|
||||
while ! self.is_eof() {
|
||||
let id = self.full_name()?;
|
||||
let id = self.full_name_maybe_type_keyword()?;
|
||||
types.push(id);
|
||||
|
||||
if self.current.kind != TokenKind::Ampersand {
|
||||
|
Loading…
Reference in New Issue
Block a user