Struct tagua_parser::ast::AnonymousFunction [] [src]

pub struct AnonymousFunction<'a> {
    pub declaration_scope: Scope,
    pub inputs: Arity<'a>,
    pub output: Ty<'a>,
    pub enclosing_scope: Option<Vec<Expression<'a>>>,
    pub body: Vec<Statement<'a>>,
}

An anonymous function.

An anonymous function is defined like, and behaves like, a named function Function except that the former has no name, and an enclosed scope.

Examples

use tagua_parser::Result;
use tagua_parser::ast::{
    AnonymousFunction,
    Arity,
    Expression,
    Name,
    Parameter,
    Scope,
    Statement,
    Ty,
    Variable
};
use tagua_parser::rules::expressions::primaries::anonymous_function;

assert_eq!(
    anonymous_function(b"static function &(I ...$x) use (&$y, $z): O { return; }"),
    Result::Done(
        &b""[..],
        Expression::AnonymousFunction(
            AnonymousFunction {
                declaration_scope: Scope::Static,
                inputs           : Arity::Infinite(vec![
                    Parameter {
                        ty   : Ty::Copy(Some(Name::Unqualified(&b"I"[..]))),
                        name : Variable(&b"x"[..]),
                        value: None
                    }
                ]),
                output         : Ty::Reference(Some(Name::Unqualified(&b"O"[..]))),
                enclosing_scope: Some(vec![
                    Expression::Reference(
                        Box::new(
                            Expression::Variable(Variable(&b"y"[..]))
                        )
                    ),
                    Expression::Variable(Variable(&b"z"[..]))
                ]),
                body: vec![Statement::Return]
            }
        )
    )
);Run

Fields

Declaration scope of the anonymous function.

Inputs, aka parameters, of the anonymous function.

Output type of the anonymous function.

Enclosed scope (list of variables to be accessible from the body) of the anonymous function.

Body of the anonymous function, i.e. a set of statements.

Trait Implementations

impl<'a> Debug for AnonymousFunction<'a>
[src]

Formats the value using the given formatter.

impl<'a> PartialEq for AnonymousFunction<'a>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.