File modules/dsl/ast/DslFor.class.php

Last commit: Tue Jul 19 00:10:00 2022 +0200	Jan Dankert	New: Scripting language: Ignore Keyword "new"; Support for Calling object constructors; Splitting objects into an instance and a wrapper.
1 <?php 2 3 namespace dsl\ast; 4 5 use dsl\DslRuntimeException; 6 use dsl\DslToken; 7 use dsl\standard\ArrayInstance; 8 9 class DslFor implements DslStatement 10 { 11 private $name; 12 private $list; 13 private $statements; 14 15 /** 16 * DslFor constructor. 17 * 18 * @param $name String 19 * @param $list DslToken[] 20 * @param $statements DslToken[] 21 */ 22 public function __construct($name, $list, $statements) 23 { 24 $this->name = $name; 25 $this->list = new DslExpression( $list ); 26 $this->statements = new DslStatementList( $statements ); 27 } 28 29 30 public function execute( & $context ) { 31 32 $list = $this->list->execute( $context ); 33 34 if ( ! $list instanceof ArrayInstance ) 35 throw new DslRuntimeException('for value is not an array'); 36 37 $copiedContext = $context; 38 foreach( $list->getInternalValue() as $loopVar ) { 39 40 // copy loop var to current loop context 41 $copiedContext[ $this->name ] = $loopVar; 42 43 // Execute "for" block 44 $this->statements->execute( $copiedContext ); 45 } 46 } 47 48 public function parse($tokens) 49 { 50 } 51 }
Download modules/dsl/ast/DslFor.class.php
History Tue, 19 Jul 2022 00:10:00 +0200 Jan Dankert New: Scripting language: Ignore Keyword "new"; Support for Calling object constructors; Splitting objects into an instance and a wrapper. Fri, 1 Jul 2022 18:09:05 +0200 Jan Dankert New: Bugfixes and much more string and array functions for the DSL. 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");