openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

DslFunction.class.php (1321B)


      1 <?php
      2 
      3 namespace dsl\ast;
      4 
      5 use dsl\DslParserException;
      6 use dsl\DslRuntimeException;
      7 use dsl\DslToken;
      8 
      9 class DslFunction extends DslElement implements DslStatement
     10 {
     11 	/**
     12 	 * @var String[]
     13 	 */
     14 	public $parameters;
     15 
     16 	/**
     17 	 * @var DslStatementList
     18 	 */
     19 	public $body;
     20 
     21 	/**
     22 	 * creates the function.
     23 	 *
     24 	 * @param array $context
     25 	 * @return mixed|void
     26 	 * @throws DslRuntimeException
     27 	 */
     28 	public function execute( & $context ) {
     29 
     30 		$clonedContext = $context;
     31 		return $this->body->execute( $context );
     32 	}
     33 
     34 	/**
     35 	 * DslFunction constructor.
     36 	 *
     37 	 * @param $functionParameter DslToken[]
     38 	 * @param $functionBody DslStatement
     39 	 * @throws DslParserException
     40 	 */
     41 	public function __construct( $functionParameter, $functionBody )
     42 	{
     43 		$this->parameters = [];
     44 		foreach( $this->splitByComma( $functionParameter ) as $parameter ) {
     45 			if   ( sizeof($parameter) != 1 )
     46 				throw new DslParserException('function parameter must be a single name');
     47 			$nameToken = $parameter[0];
     48 			if   ( $nameToken->type == DslToken::T_NONE ) // no parameter
     49 				continue;
     50 			if   ( $nameToken->type != DslToken::T_STRING )
     51 				throw new DslParserException('function parameter must be a name');
     52 
     53 			$this->parameters[] = $nameToken->value;
     54 		}
     55 
     56 		$this->body = new DslStatementList( $functionBody );
     57 	}
     58 
     59 	public function parse($tokens)
     60 	{
     61 	}
     62 
     63 }