Enum tagua_parser::ast::Expression
[−]
[src]
pub enum Expression<'a> {
AnonymousFunction(AnonymousFunction<'a>),
Array(Vec<(Option<Expression<'a>>, Expression<'a>)>),
Echo(Vec<Expression<'a>>),
Empty(Box<Expression<'a>>),
Eval(Box<Expression<'a>>),
Exit(Option<Box<Expression<'a>>>),
Isset(Vec<Expression<'a>>),
List(Vec<Option<(Option<Expression<'a>>, Expression<'a>)>>),
Literal(Literal),
Name(Name<'a>),
Print(Box<Expression<'a>>),
Reference(Box<Expression<'a>>),
Unset(Vec<Expression<'a>>),
Variable(Variable<'a>),
}An expression.
Variants
AnonymousFunction(AnonymousFunction<'a>)An anonymous function is defined like, and behaves like, a named 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::expression; assert_eq!( expression(b"function (I $x, J &$y) use ($z): O { return; }"), Result::Done( &b""[..], Expression::AnonymousFunction( AnonymousFunction { declaration_scope: Scope::Dynamic, inputs : Arity::Finite(vec![ Parameter { ty : Ty::Copy(Some(Name::Unqualified(&b"I"[..]))), name : Variable(&b"x"[..]), value: None }, Parameter { ty : Ty::Reference(Some(Name::Unqualified(&b"J"[..]))), name : Variable(&b"y"[..]), value: None } ]), output : Ty::Copy(Some(Name::Unqualified(&b"O"[..]))), enclosing_scope: Some(vec![Expression::Variable(Variable(&b"z"[..]))]), body : vec![Statement::Return] } ) ) );Run
Array(Vec<(Option<Expression<'a>>, Expression<'a>)>)A collection of heterogeneous pairs (key, value). The key is optional.
Examples
use tagua_parser::Result; use tagua_parser::ast::{Expression, Literal, Variable}; use tagua_parser::rules::expressions::expression; assert_eq!( expression(b"['foo', 42 => 'bar', 'baz' => $qux]"), Result::Done( &b""[..], Expression::Array(vec![ ( None, Expression::Literal(Literal::String(b"foo".to_vec())) ), ( Some(Expression::Literal(Literal::Integer(42i64))), Expression::Literal(Literal::String(b"bar".to_vec())) ), ( Some(Expression::Literal(Literal::String(b"baz".to_vec()))), Expression::Variable(Variable(&b"qux"[..])) ) ]) ) );Run
Echo(Vec<Expression<'a>>)Echo converts each of its expression's values into strings, concatenates them in order given, and writes the result to the output stream.
Examples
use tagua_parser::Result; use tagua_parser::ast::{Expression, Literal, Variable}; use tagua_parser::rules::expressions::expression; assert_eq!( expression(b"echo 'foobar', $bazqux, 42"), Result::Done( &b""[..], Expression::Echo(vec![ Expression::Literal(Literal::String(b"foobar".to_vec())), Expression::Variable(Variable(&b"bazqux"[..])), Expression::Literal(Literal::Integer(42i64)) ]) ) );Run
Empty(Box<Expression<'a>>)Returns TRUE if the variable or value designated by the
expression is empty.
Examples
use tagua_parser::Result; use tagua_parser::ast::{Expression, Literal}; use tagua_parser::rules::expressions::expression; assert_eq!( expression(b"empty('')"), Result::Done( &b""[..], Expression::Empty( Box::new( Expression::Literal( Literal::String(b"".to_vec()) ) ) ) ) );Run
Eval(Box<Expression<'a>>)Late evaluation of a PHP program represented as a string.
Examples
use tagua_parser::Result; use tagua_parser::ast::{Expression, Literal}; use tagua_parser::rules::expressions::expression; assert_eq!( expression(b"eval('1 + 2;')"), Result::Done( &b""[..], Expression::Eval( Box::new( Expression::Literal( Literal::String(b"1 + 2;".to_vec()) ) ) ) ) );Run
Exit(Option<Box<Expression<'a>>>)Terminate the current script.
Examples
use tagua_parser::Result; use tagua_parser::ast::{Expression, Literal}; use tagua_parser::rules::expressions::expression; assert_eq!( expression(b"exit(42)"), Result::Done( &b""[..], Expression::Exit( Some( Box::new( Expression::Literal( Literal::Integer(42i64) ) ) ) ) ) );Run
Isset(Vec<Expression<'a>>)Return TRUE if all expressions set and their values are not
NULL. Otherwise, it returns FALSE.
Examples
use tagua_parser::Result; use tagua_parser::ast::{Expression, Variable}; use tagua_parser::rules::expressions::expression; assert_eq!( expression(b"isset($foo, $bar)"), Result::Done( &b""[..], Expression::Isset(vec![ Expression::Variable(Variable(&b"foo"[..])), Expression::Variable(Variable(&b"bar"[..])) ]) ) );Run
List(Vec<Option<(Option<Expression<'a>>, Expression<'a>)>>)Match and assign one or more elements of the source array to the target variables.
Examples
A keyed list:
use tagua_parser::Result; use tagua_parser::ast::{Expression, Literal, Variable}; use tagua_parser::rules::expressions::expression; assert_eq!( expression(b"list('foo' => $foo, 'bar' => $bar, 'baz' => $baz)"), Result::Done( &b""[..], Expression::List(vec![ Some(( Some(Expression::Literal(Literal::String(b"foo".to_vec()))), Expression::Variable(Variable(&b"foo"[..])) )), Some(( Some(Expression::Literal(Literal::String(b"bar".to_vec()))), Expression::Variable(Variable(&b"bar"[..])) )), Some(( Some(Expression::Literal(Literal::String(b"baz".to_vec()))), Expression::Variable(Variable(&b"baz"[..])) )) ]) ) );Run
An unkeyed list:
use tagua_parser::Result; use tagua_parser::ast::{Expression, Variable}; use tagua_parser::rules::expressions::expression; assert_eq!( expression(b"list($foo, , , $bar, $baz)"), Result::Done( &b""[..], Expression::List(vec![ Some(( None, Expression::Variable(Variable(&b"foo"[..])) )), None, None, Some(( None, Expression::Variable(Variable(&b"bar"[..])) )), Some(( None, Expression::Variable(Variable(&b"baz"[..])) )) ]) ) );Run
Literal(Literal)A literal.
Examples
use tagua_parser::Result; use tagua_parser::ast::{Expression, Literal}; use tagua_parser::rules::expressions::expression; assert_eq!( expression(b"'Hello, World!'"), Result::Done(&b""[..], Expression::Literal(Literal::String(b"Hello, World!".to_vec()))) );Run
Name(Name<'a>)A name.
Examples
use tagua_parser::Result; use tagua_parser::ast::{Expression, Name}; use tagua_parser::rules::expressions::expression; assert_eq!( expression(b"Foo\\Bar"), Result::Done(&b""[..], Expression::Name(Name::Qualified(vec![&b"Foo"[..], &b"Bar"[..]]))) );Run
Print(Box<Expression<'a>>)Unlike echo, print can be used in any context allowing an
expression. It always returns the value 1.
Examples
use tagua_parser::Result; use tagua_parser::ast::{Expression, Variable}; use tagua_parser::rules::expressions::expression; assert_eq!( expression(b"print $foo"), Result::Done( &b""[..], Expression::Print( Box::new( Expression::Variable(Variable(&b"foo"[..])), ) ) ) );Run
Reference(Box<Expression<'a>>)Describe an expression assignment by reference.
Examples
use tagua_parser::Result; use tagua_parser::ast::{Expression, Literal, Variable}; use tagua_parser::rules::expressions::expression; assert_eq!( expression(b"[7 => &$foo]"), Result::Done( &b""[..], Expression::Array(vec![ ( Some(Expression::Literal(Literal::Integer(7i64))), Expression::Reference( Box::new(Expression::Variable(Variable(&b"foo"[..]))) ) ) ]) ) );Run
Unset(Vec<Expression<'a>>)Unset the variables designated by each expression.
Examples
use tagua_parser::Result; use tagua_parser::ast::{Expression, Variable}; use tagua_parser::rules::expressions::expression; assert_eq!( expression(b"unset($foo, $bar)"), Result::Done( &b""[..], Expression::Unset(vec![ Expression::Variable(Variable(&b"foo"[..])), Expression::Variable(Variable(&b"bar"[..])) ]) ) );Run
Variable(Variable<'a>)A variable.
Examples
use tagua_parser::Result; use tagua_parser::ast::{Expression, Variable}; use tagua_parser::rules::expressions::expression; assert_eq!( expression(b"$foo"), Result::Done(&b""[..], Expression::Variable(Variable(&b"foo"[..]))) );Run
Trait Implementations
impl<'a> Debug for Expression<'a>[src]
impl<'a> PartialEq for Expression<'a>[src]
fn eq(&self, __arg_0: &Expression<'a>) -> bool
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, __arg_0: &Expression<'a>) -> bool
This method tests for !=.