mirror of
https://github.com/danog/parser.git
synced 2024-11-27 04:14:55 +01:00
parser: basic support for trait uses in classes
This commit is contained in:
parent
a9ced4460a
commit
d20e35d1a8
9
phpast/samples/class-use.php
Normal file
9
phpast/samples/class-use.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
trait Foo {
|
||||
|
||||
}
|
||||
|
||||
class Bar {
|
||||
use Foo;
|
||||
}
|
@ -113,6 +113,8 @@ impl From<TokenKind> for ClassFlag {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Serialize)]
|
||||
pub enum Statement {
|
||||
InlineHtml(String),
|
||||
@ -150,6 +152,9 @@ pub enum Statement {
|
||||
name: Identifier,
|
||||
body: Block,
|
||||
},
|
||||
TraitUse {
|
||||
traits: Vec<Identifier>,
|
||||
},
|
||||
Interface {
|
||||
name: Identifier,
|
||||
extends: Vec<Identifier>,
|
||||
|
@ -483,6 +483,24 @@ impl Parser {
|
||||
|
||||
fn class_statement(&mut self) -> ParseResult<Statement> {
|
||||
match self.current.kind {
|
||||
TokenKind::Use => {
|
||||
self.next();
|
||||
|
||||
let mut traits = Vec::new();
|
||||
|
||||
while self.current.kind != TokenKind::SemiColon {
|
||||
if self.current.kind == TokenKind::Comma {
|
||||
self.next();
|
||||
}
|
||||
|
||||
let t = expect!(self, TokenKind::Identifier(i) | TokenKind::QualifiedIdentifier(i) | TokenKind::FullyQualifiedIdentifier(i), i, "expected identifier");
|
||||
traits.push(t.into());
|
||||
}
|
||||
|
||||
expect!(self, TokenKind::SemiColon, "expected semi-colon");
|
||||
|
||||
Ok(Statement::TraitUse { traits })
|
||||
},
|
||||
TokenKind::Const => {
|
||||
self.next();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user