#[repr(transparent)]
pub struct MethodModifierGroup { pub modifiers: Vec<MethodModifier>, }

Fields§

§modifiers: Vec<MethodModifier>

Implementations§

Examples found in repository?
src/parser/internal/functions.rs (line 253)
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
pub fn method(
    state: &mut State,
    r#type: MethodType,
    modifiers: MethodModifierGroup,
    class_name: &str,
) -> ParseResult<Method> {
    let comments = state.stream.comments();
    let attributes = state.get_attributes();
    let function = utils::skip(state, TokenKind::Function)?;

    let current = state.stream.current();
    let ampersand = if current.kind == TokenKind::Ampersand {
        state.stream.next();

        Some(current.span)
    } else {
        None
    };

    let name = identifiers::identifier_maybe_reserved(state)?;
    let has_body = match r#type {
        MethodType::Abstract => false,
        MethodType::Concrete => true,
        MethodType::DependingOnModifiers => !modifiers.has_abstract(),
    };

    if name.to_string().to_lowercase() == "__construct" {
        if has_body {
            let parameters = parameters::constructor_parameter_list(state, class_name)?;
            let body = MethodBody {
                comments: state.stream.comments(),
                left_brace: utils::skip_left_brace(state)?,
                statements: blocks::multiple_statements_until(state, &TokenKind::RightBrace)?,
                right_brace: utils::skip_right_brace(state)?,
            };

            return Ok(Method::ConcreteConstructor(ConcreteConstructor {
                comments,
                attributes,
                modifiers,
                function,
                ampersand,
                name,
                parameters,
                body,
            }));
        } else {
            let parameters = parameters::function_parameter_list(state)?;
            let semicolon = utils::skip_semicolon(state)?;

            return Ok(Method::AbstractConstructor(AbstractConstructor {
                comments,
                attributes,
                modifiers,
                function,
                ampersand,
                name,
                parameters,
                semicolon,
            }));
        }
    }

    let parameters = parameters::function_parameter_list(state)?;
    let return_type = if state.stream.current().kind == TokenKind::Colon {
        Some(ReturnType {
            colon: utils::skip_colon(state)?,
            data_type: data_type::data_type(state)?,
        })
    } else {
        None
    };

    if has_body {
        Ok(Method::Concrete(ConcreteMethod {
            comments,
            attributes,
            modifiers,
            function,
            ampersand,
            name,
            parameters,
            return_type,
            body: MethodBody {
                comments: state.stream.comments(),
                left_brace: utils::skip_left_brace(state)?,
                statements: blocks::multiple_statements_until(state, &TokenKind::RightBrace)?,
                right_brace: utils::skip_right_brace(state)?,
            },
        }))
    } else {
        Ok(Method::Abstract(AbstractMethod {
            comments,
            attributes,
            modifiers,
            function,
            ampersand,
            name,
            parameters,
            return_type,
            semicolon: utils::skip_semicolon(state)?,
        }))
    }
}
Examples found in repository?
src/parser/internal/classes.rs (line 197)
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
fn member(state: &mut State, abstract_class: bool, class_name: &str) -> ParseResult<ClassMember> {
    let has_attributes = attributes::gather_attributes(state)?;

    if !has_attributes && state.stream.current().kind == TokenKind::Use {
        return traits::usage(state).map(ClassMember::TraitUsage);
    }

    if state.stream.current().kind == TokenKind::Var {
        return properties::parse_var(state, class_name).map(ClassMember::VariableProperty);
    }

    let modifiers = modifiers::collect(state)?;

    if state.stream.current().kind == TokenKind::Const {
        return classish(state, modifiers::constant_group(modifiers)?).map(ClassMember::Constant);
    }

    if state.stream.current().kind == TokenKind::Function {
        let method = method(
            state,
            MethodType::DependingOnModifiers,
            modifiers::method_group(modifiers)?,
            class_name,
        )?;

        match method {
            Method::Abstract(method) => {
                if !abstract_class {
                    return Err(ParseError::AbstractModifierOnNonAbstractClassMethod(
                        method.modifiers.get_abstract().unwrap().span(),
                    ));
                }

                return Ok(ClassMember::AbstractMethod(method));
            }
            Method::Concrete(method) => {
                return Ok(ClassMember::ConcreteMethod(method));
            }
            Method::AbstractConstructor(ctor) => {
                if !abstract_class {
                    return Err(ParseError::AbstractModifierOnNonAbstractClassMethod(
                        ctor.modifiers.get_abstract().unwrap().span(),
                    ));
                }

                return Ok(ClassMember::AbstractConstructor(ctor));
            }
            Method::ConcreteConstructor(ctor) => {
                return Ok(ClassMember::ConcreteConstructor(ctor));
            }
        }
    }

    // e.g: public static
    let modifiers = modifiers::property_group(modifiers)?;

    properties::parse(state, class_name, modifiers).map(ClassMember::Property)
}

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
The name of the generated JSON Schema. Read more
Generates a JSON Schema for this type. Read more
Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.