File modules/dsl/ast/DslFunction.class.php
Last commit: Sun Jun 26 15:46:54 2022 +0200 Jan Dankert Fix: Another, little better, hack for parameterless functions. Shunting yard seems to be unable to handle empty parentheses.
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 }
Downloadmodules/dsl/ast/DslFunction.class.php
History Sun, 26 Jun 2022 15:46:54 +0200 Jan Dankert Fix: Another, little better, hack for parameterless functions. Shunting yard seems to be unable to handle empty parentheses. Tue, 31 May 2022 00:30:18 +0200 Jan Dankert New: DSL with support for parameterless functions. Sun, 29 May 2022 16:56:40 +0200 Jan Dankert New: DSL with support for functions with return values, full arithmetic, object properties Sun, 29 May 2022 01:13:27 +0200 Jan Dankert New: DSL with support for functions Sat, 28 May 2022 18:00:13 +0200 Jan Dankert New: DSL with a much better syntax parsing and support for assignments, conditions, ... Wed, 25 May 2022 22:47:17 +0200 Jan Dankert New: DSL (domain specific language) for code elements. The old way with PHP code ist not sandboxed and unsecure. This approach is a minimalistic, javascript-like, scripting engine. For now only simple function calls are possible, for example: alert("example");