mirror of
https://github.com/danog/parser.git
synced 2024-11-30 04:29:13 +01:00
parser: start supporting reserved non modifiers as method names
This commit is contained in:
parent
56310906a8
commit
06cbbeff40
@ -215,6 +215,7 @@ impl Display for TokenKind {
|
||||
Self::Finally => "finally",
|
||||
Self::Float(_) => "float",
|
||||
Self::Fn => "fn",
|
||||
Self::For => "for",
|
||||
Self::FullyQualifiedIdentifier(id) => &id[..],
|
||||
Self::Function => "function",
|
||||
Self::GreaterThan => ">",
|
||||
|
@ -21,4 +21,17 @@ impl Parser {
|
||||
pub(crate) fn var(&mut self) -> ParseResult<String> {
|
||||
Ok(expect!(self, TokenKind::Variable(v), v, "expected variable name"))
|
||||
}
|
||||
|
||||
pub(crate) fn ident_maybe_reserved(&mut self) -> ParseResult<String> {
|
||||
match self.current.kind {
|
||||
TokenKind::Static | TokenKind::Abstract | TokenKind::Final | TokenKind::For |
|
||||
TokenKind::Private | TokenKind::Protected | TokenKind::Public | TokenKind::Require |
|
||||
TokenKind::RequireOnce | TokenKind::New | TokenKind::Clone | TokenKind::If | TokenKind::Else | TokenKind::ElseIf => {
|
||||
let string = self.current.kind.to_string();
|
||||
self.next();
|
||||
Ok(string)
|
||||
},
|
||||
_ => self.ident()
|
||||
}
|
||||
}
|
||||
}
|
@ -1361,13 +1361,13 @@ impl Parser {
|
||||
|
||||
Expression::StaticPropertyFetch { target: Box::new(lhs), property: Box::new(var) }
|
||||
},
|
||||
TokenKind::Class | TokenKind::Identifier(_) => {
|
||||
_ => {
|
||||
let ident = if self.current.kind == TokenKind::Class {
|
||||
self.next();
|
||||
|
||||
String::from("class")
|
||||
} else {
|
||||
self.ident()?
|
||||
self.ident_maybe_reserved()?
|
||||
};
|
||||
|
||||
if self.current.kind == TokenKind::LeftParen {
|
||||
@ -1389,12 +1389,11 @@ impl Parser {
|
||||
Expression::ConstFetch { target: Box::new(lhs), constant: ident.into() }
|
||||
}
|
||||
},
|
||||
_ => return Err(ParseError::UnexpectedToken(self.current.kind.to_string(), self.current.span))
|
||||
}
|
||||
},
|
||||
TokenKind::Arrow => {
|
||||
// TODO: Add support for dynamic property fetch or method call here.
|
||||
let property = self.ident()?;
|
||||
let property = self.ident_maybe_reserved()?;
|
||||
|
||||
if self.current.kind == TokenKind::LeftParen {
|
||||
self.next();
|
||||
|
Loading…
Reference in New Issue
Block a user