openrat-cms

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

commit ba7a3af9627e90af3fc1a99a881a36cb2ca47acc
parent cd753080a36ba39c814db237f1716ccd60b18615
Author: Jan Dankert <develop@jandankert.de>
Date:   Tue,  7 Jun 2022 23:30:20 +0200

New: DSL is now supporting throw statements.

Diffstat:
Mmodules/dsl/DslLexer.class.php | 1+
Mmodules/dsl/DslToken.class.php | 1+
Mmodules/dsl/ast/DslStatementList.class.php | 5+++++
Amodules/dsl/ast/DslThrow.class.php | 29+++++++++++++++++++++++++++++
4 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/modules/dsl/DslLexer.class.php b/modules/dsl/DslLexer.class.php @@ -16,6 +16,7 @@ class DslLexer 'var' => DslToken::T_LET, 'return' => DslToken::T_RETURN, 'new' => DslToken::T_NEW, + 'throw' => DslToken::T_THROW, ]; const UNUSED_KEYWORDS = [ diff --git a/modules/dsl/DslToken.class.php b/modules/dsl/DslToken.class.php @@ -25,6 +25,7 @@ class DslToken const T_NEGATION = 18; const T_COMMA = 19; const T_NEW = 20; + const T_THROW = 21; public $lineNumber; public $type; diff --git a/modules/dsl/ast/DslStatementList.class.php b/modules/dsl/ast/DslStatementList.class.php @@ -123,6 +123,11 @@ class DslStatementList extends DslElement implements DslStatement $this->statements[] = new DslReturn( $returnTokens ); break; + case DslToken::T_THROW: + $returnTokens = $this->getSingleStatement($tokens ); + $this->statements[] = new DslThrow( $returnTokens ); + break; + case DslToken::T_TEXT: case DslToken::T_STRING: array_unshift( $tokens, $token ); diff --git a/modules/dsl/ast/DslThrow.class.php b/modules/dsl/ast/DslThrow.class.php @@ -0,0 +1,28 @@ +<?php + +namespace dsl\ast; + +use dsl\DslRuntimeException; + +class DslThrow implements DslStatement +{ + private $value; + + public function __construct( $expressionTokens ) + { + $this->value = new DslExpression( $expressionTokens ); + } + + /** + * @throws DslRuntimeException + */ + public function execute(& $context ) { + + $value = $this->value->execute( $context ); + throw new DslRuntimeException( $value ); + } + + public function parse($tokens) + { + } +} +\ No newline at end of file