Unit CastleScriptParser

Classes, Interfaces, Objects and Records
Constants
Variables

Description

Parser for CastleScript language, see [https://castle-engine.io/castle_script.php].

Can parse whole program in CastleScript language, is also prepared to parse only a single expression (usefull for cases when I need to input only a mathematical expression, like for glplotter function expression).

Uses

Overview

Functions and Procedures

function ParseFloatExpression(const S: string; const Variables: array of TCasScriptValue): TCasScriptExpression;
function ParseIntExpression(const S: string; const Variables: array of TCasScriptValue): TCasScriptExpression;
function ParseStringExpression(const S: string; const Variables: array of TCasScriptValue): TCasScriptExpression;
function ParseBoolExpression(const S: string; const Variables: array of TCasScriptValue): TCasScriptExpression;
function ParseExpression(const S: string; const Variables: array of TCasScriptValue): TCasScriptExpression;
function ParseConstantFloatExpression(const S: string): Float;
function ParseProgram(const S: string; const Variables: array of TCasScriptValue): TCasScriptProgram; overload;
function ParseProgram(const S: string; const Variables: TCasScriptValueList): TCasScriptProgram; overload;

Types

ECasScriptSyntaxError = CastleScriptLexer.ECasScriptSyntaxError;

Description

Functions and Procedures

function ParseFloatExpression(const S: string; const Variables: array of TCasScriptValue): TCasScriptExpression;

Parse a CastleScript expression that should be calculated to a float value. The easiest way to evaluate such expression is to call TCasScriptExpression.AsFloat method.

This creates and returns an instance of TCasScriptExpression, that represents parsed tree of expression in S, casted to float. This parses a subset of CastleScript language, that allows you to define only one expression without any assignments. Also the end result is always casted to the float() type (just like it would be wrapped inside float() function call — in fact this is exactly what happens.)

The end result is that this is perfect for describing things like function expressions, ideal e.g. for [https://castle-engine.io/glplotter_and_gen_function.php].

Parameters
Variables
contains a list of named values you want to allow in this expression.

Important: They will all have OwnedByParentExpression set to False, and you will have to free them yourself. That's because given expression may use the same variable more than once (so freeing it twice would cause bugs), or not use it at all (so it will be automatically freed at all).

So setting OwnedByParentExpression and freeing it yourself is the only sensible thing to do.

Exceptions raised
ECasScriptSyntaxError
in case of error when parsing expression.
function ParseIntExpression(const S: string; const Variables: array of TCasScriptValue): TCasScriptExpression;

Parse a CastleScript expression that should be calculated to a float value. The easiest way to evaluate such expression is to call TCasScriptExpression.AsInt method.

See ParseFloatExpression for more details, this procedure is equivalent but it operates on floats.

function ParseStringExpression(const S: string; const Variables: array of TCasScriptValue): TCasScriptExpression;

Parse a CastleScript expression that should be calculated to a string value. The easiest way to evaluate such expression is to call TCasScriptExpression.AsString method.

See ParseFloatExpression for more details, this procedure is equivalent but it operates on strings.

function ParseBoolExpression(const S: string; const Variables: array of TCasScriptValue): TCasScriptExpression;

Parse a CastleScript expression that should be calculated to a boolean value. The easiest way to evaluate such expression is to call TCasScriptExpression.AsBool method.

See ParseFloatExpression for more details, this procedure is equivalent but it operates on booleans.

function ParseExpression(const S: string; const Variables: array of TCasScriptValue): TCasScriptExpression;

Creates and returns instance of TCasScriptExpression, that represents parsed tree of expression in S.

Parameters
Variables
contains a list of named values you want to allow in this expression. See ParseFloatExpression for description.
Exceptions raised
ECasScriptSyntaxError
in case of error when parsing expression.
function ParseConstantFloatExpression(const S: string): Float;

Parse constant float expression. This can be used as a drop-in replacement for StrToFloatDot. Takes a string with any constant mathematical expression, according to CastleScript syntax, parses it and calculates.

Exceptions raised
ECasScriptSyntaxError
in case of error when parsing expression.
function ParseProgram(const S: string; const Variables: array of TCasScriptValue): TCasScriptProgram; overload;

Parse CastleScript program.

Variable list works like for ParseFloatExpression, see there for description.

Exceptions raised
ECasScriptSyntaxError
in case of error when parsing expression.
function ParseProgram(const S: string; const Variables: TCasScriptValueList): TCasScriptProgram; overload;
 

Types

ECasScriptSyntaxError = CastleScriptLexer.ECasScriptSyntaxError;

Error when parsing CastleScript expression.


Generated by PasDoc 0.15.0.