Struct php_parser_rs::parser::ast::modifiers::PropertyModifierGroup
source · #[repr(transparent)]pub struct PropertyModifierGroup {
pub modifiers: Vec<PropertyModifier>,
}
Fields§
§modifiers: Vec<PropertyModifier>
Implementations§
source§impl PropertyModifierGroup
impl PropertyModifierGroup
pub fn is_empty(&self) -> bool
sourcepub fn has_readonly(&self) -> bool
pub fn has_readonly(&self) -> bool
Examples found in repository?
src/parser/internal/properties.rs (line 29)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
pub fn parse(
state: &mut State,
class_name: &str,
modifiers: PropertyModifierGroup,
) -> ParseResult<Property> {
let ty = data_type::optional_data_type(state)?;
let mut entries = vec![];
let mut type_checked = false;
loop {
let current = state.stream.current();
let variable = variables::simple_variable(state)?;
if !type_checked {
type_checked = true;
if modifiers.has_readonly() && modifiers.has_static() {
return Err(ParseError::StaticPropertyUsingReadonlyModifier(
class_name.to_owned(),
variable.to_string(),
current.span,
));
}
match &ty {
Some(ty) => {
if ty.includes_callable() || ty.is_bottom() {
return Err(ParseError::ForbiddenTypeUsedInProperty(
class_name.to_owned(),
variable.to_string(),
ty.clone(),
current.span,
));
}
}
None => {
if modifiers.has_readonly() {
return Err(ParseError::MissingTypeForReadonlyProperty(
class_name.to_owned(),
variable.to_string(),
current.span,
));
}
}
}
}
let current = state.stream.current();
if current.kind == TokenKind::Equals {
if modifiers.has_readonly() {
return Err(ParseError::ReadonlyPropertyHasDefaultValue(
class_name.to_owned(),
variable.to_string(),
current.span,
));
}
state.stream.next();
let value = expressions::create(state)?;
entries.push(PropertyEntry::Initialized {
variable,
span: current.span,
value,
});
} else {
entries.push(PropertyEntry::Uninitialized { variable });
}
if state.stream.current().kind == TokenKind::Comma {
state.stream.next();
} else {
break;
}
}
let end = utils::skip_semicolon(state)?;
Ok(Property {
r#type: ty,
modifiers,
attributes: state.get_attributes(),
entries,
end,
})
}
sourcepub fn has_static(&self) -> bool
pub fn has_static(&self) -> bool
Examples found in repository?
src/parser/internal/properties.rs (line 29)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
pub fn parse(
state: &mut State,
class_name: &str,
modifiers: PropertyModifierGroup,
) -> ParseResult<Property> {
let ty = data_type::optional_data_type(state)?;
let mut entries = vec![];
let mut type_checked = false;
loop {
let current = state.stream.current();
let variable = variables::simple_variable(state)?;
if !type_checked {
type_checked = true;
if modifiers.has_readonly() && modifiers.has_static() {
return Err(ParseError::StaticPropertyUsingReadonlyModifier(
class_name.to_owned(),
variable.to_string(),
current.span,
));
}
match &ty {
Some(ty) => {
if ty.includes_callable() || ty.is_bottom() {
return Err(ParseError::ForbiddenTypeUsedInProperty(
class_name.to_owned(),
variable.to_string(),
ty.clone(),
current.span,
));
}
}
None => {
if modifiers.has_readonly() {
return Err(ParseError::MissingTypeForReadonlyProperty(
class_name.to_owned(),
variable.to_string(),
current.span,
));
}
}
}
}
let current = state.stream.current();
if current.kind == TokenKind::Equals {
if modifiers.has_readonly() {
return Err(ParseError::ReadonlyPropertyHasDefaultValue(
class_name.to_owned(),
variable.to_string(),
current.span,
));
}
state.stream.next();
let value = expressions::create(state)?;
entries.push(PropertyEntry::Initialized {
variable,
span: current.span,
value,
});
} else {
entries.push(PropertyEntry::Uninitialized { variable });
}
if state.stream.current().kind == TokenKind::Comma {
state.stream.next();
} else {
break;
}
}
let end = utils::skip_semicolon(state)?;
Ok(Property {
r#type: ty,
modifiers,
attributes: state.get_attributes(),
entries,
end,
})
}
pub fn visibility(&self) -> Visibility
Trait Implementations§
source§impl Clone for PropertyModifierGroup
impl Clone for PropertyModifierGroup
source§fn clone(&self) -> PropertyModifierGroup
fn clone(&self) -> PropertyModifierGroup
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for PropertyModifierGroup
impl Debug for PropertyModifierGroup
source§impl<'de> Deserialize<'de> for PropertyModifierGroup
impl<'de> Deserialize<'de> for PropertyModifierGroup
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl JsonSchema for PropertyModifierGroup
impl JsonSchema for PropertyModifierGroup
source§fn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
Whether JSON Schemas generated for this type should be re-used where possible using the
$ref
keyword. Read moresource§impl PartialEq<PropertyModifierGroup> for PropertyModifierGroup
impl PartialEq<PropertyModifierGroup> for PropertyModifierGroup
source§fn eq(&self, other: &PropertyModifierGroup) -> bool
fn eq(&self, other: &PropertyModifierGroup) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.