File modules/dsl/standard/Script.class.php

Last commit: Fri Jul 1 18:09:05 2022 +0200	Jan Dankert	New: Bugfixes and much more string and array functions for the DSL.
1 <?php 2 3 namespace dsl\standard; 4 5 use dsl\ast\DslStatement; 6 use dsl\context\BaseScriptableObject; 7 use dsl\DslToken; 8 9 class Script extends BaseScriptableObject 10 { 11 /** 12 * @var DslToken[] 13 */ 14 private $tokens; 15 16 /** 17 * @var DslStatement 18 */ 19 private $ast; 20 21 /** 22 * @param $tokens DslToken[] 23 * @param $ast DslStatement 24 */ 25 public function __construct($tokens, $ast ) 26 { 27 $this->tokens = $tokens; 28 $this->ast = $ast; 29 } 30 31 public function getToken() 32 { 33 return implode("\n",$this->tokens); 34 } 35 36 37 public function getSource() 38 { 39 $line = 0; 40 $source = ''; 41 42 foreach( $this->tokens as $token ) { 43 44 $source .= ($line != $token->lineNumber ? "\n" . str_pad($token->lineNumber, 4, '0', STR_PAD_LEFT).': ' : '') . $token->value; 45 $line = $token->lineNumber; 46 } 47 48 return $source."\n"; 49 } 50 51 52 public function getSyntaxTree() 53 { 54 return print_r($this->ast,true); 55 } 56 57 public function dump( $value ) 58 { 59 return print_r($value,true); 60 } 61 62 public function __toString() 63 { 64 return "Script Info, call help() for help."; 65 } 66 }
Download modules/dsl/standard/Script.class.php
History Fri, 1 Jul 2022 18:09:05 +0200 Jan Dankert New: Bugfixes and much more string and array functions for the DSL. Mon, 27 Jun 2022 00:40:42 +0200 Jan Dankert New: Marker interface 'Scriptable', Proxy class for MQTT, help() method in Scripts. Sun, 26 Jun 2022 13:18:47 +0200 Jan Dankert New: DSL ouput the parsed source. Sun, 26 Jun 2022 12:51:07 +0200 Jan Dankert New: DSL can be controlled by flags; support for error messages; support for negativ numbers.