parser: allow using array & callable at type strings

This commit is contained in:
Ryan Chandler 2022-08-09 11:54:47 +01:00
parent 626af3e31c
commit 5309451588
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA
2 changed files with 15 additions and 4 deletions

View File

@ -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 |

View File

@ -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 {