mirror of
https://github.com/danog/parser.git
synced 2025-01-22 04:51:13 +01:00
parser: support types on class var statements
This commit is contained in:
parent
a1a00c6f8f
commit
2948a2e0af
6
phpast/samples/full-class-defs.php
Normal file
6
phpast/samples/full-class-defs.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
class Foo {
|
||||
var $bar;
|
||||
var string $baz;
|
||||
}
|
@ -72,9 +72,11 @@ pub enum Statement {
|
||||
InlineHtml(String),
|
||||
Var {
|
||||
var: String,
|
||||
r#type: Option<Type>,
|
||||
},
|
||||
Property {
|
||||
var: String,
|
||||
r#type: Option<Type>,
|
||||
},
|
||||
Function {
|
||||
name: Identifier,
|
||||
|
@ -261,11 +261,17 @@ impl Parser {
|
||||
TokenKind::Var => {
|
||||
self.next();
|
||||
|
||||
let mut var_type = None;
|
||||
|
||||
if ! matches!(self.current.kind, TokenKind::Variable(_)) {
|
||||
var_type = Some(self.type_string()?);
|
||||
}
|
||||
|
||||
let var = expect!(self, TokenKind::Variable(i), i, "expected variable name");
|
||||
|
||||
expect!(self, TokenKind::SemiColon, "expected semi-colon");
|
||||
|
||||
Statement::Var { var }
|
||||
Statement::Var { var, r#type: var_type }
|
||||
},
|
||||
TokenKind::SemiColon => {
|
||||
self.next();
|
||||
@ -316,8 +322,8 @@ impl Parser {
|
||||
Statement::Function { name, params, body, .. } => {
|
||||
Statement::Method { name, params, body, flags: vec![] }
|
||||
},
|
||||
Statement::Var { var } => {
|
||||
Statement::Property { var }
|
||||
Statement::Var { var, r#type } => {
|
||||
Statement::Property { var, r#type }
|
||||
},
|
||||
Statement::Method { .. } | Statement::Comment { .. } => s,
|
||||
_ => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user