mirror of
https://github.com/danog/parser.git
synced 2025-01-22 13:01:32 +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),
|
InlineHtml(String),
|
||||||
Var {
|
Var {
|
||||||
var: String,
|
var: String,
|
||||||
|
r#type: Option<Type>,
|
||||||
},
|
},
|
||||||
Property {
|
Property {
|
||||||
var: String,
|
var: String,
|
||||||
|
r#type: Option<Type>,
|
||||||
},
|
},
|
||||||
Function {
|
Function {
|
||||||
name: Identifier,
|
name: Identifier,
|
||||||
|
@ -261,11 +261,17 @@ impl Parser {
|
|||||||
TokenKind::Var => {
|
TokenKind::Var => {
|
||||||
self.next();
|
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");
|
let var = expect!(self, TokenKind::Variable(i), i, "expected variable name");
|
||||||
|
|
||||||
expect!(self, TokenKind::SemiColon, "expected semi-colon");
|
expect!(self, TokenKind::SemiColon, "expected semi-colon");
|
||||||
|
|
||||||
Statement::Var { var }
|
Statement::Var { var, r#type: var_type }
|
||||||
},
|
},
|
||||||
TokenKind::SemiColon => {
|
TokenKind::SemiColon => {
|
||||||
self.next();
|
self.next();
|
||||||
@ -316,8 +322,8 @@ impl Parser {
|
|||||||
Statement::Function { name, params, body, .. } => {
|
Statement::Function { name, params, body, .. } => {
|
||||||
Statement::Method { name, params, body, flags: vec![] }
|
Statement::Method { name, params, body, flags: vec![] }
|
||||||
},
|
},
|
||||||
Statement::Var { var } => {
|
Statement::Var { var, r#type } => {
|
||||||
Statement::Property { var }
|
Statement::Property { var, r#type }
|
||||||
},
|
},
|
||||||
Statement::Method { .. } | Statement::Comment { .. } => s,
|
Statement::Method { .. } | Statement::Comment { .. } => s,
|
||||||
_ => {
|
_ => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user