Castle Game Engine: CastleScriptParser

# Unit CastleScriptParser
Description | Uses | Classes, Interfaces, Objects and Records | Functions and Procedures | Types | Constants | Variables
## Description Parser for CastleScript language, see [http://castle-engine.sourceforge.net/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 CastleScript CastleScriptLexer Math ## Overview ### Functions and Procedures
`function ParseFloatExpression(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;`
Creates and returns instance of TCasScriptExpression, that represents parsed tree of expression in S, casted to float. The easiest way to evaluate such expression is to call TCasScriptExpression.AsFloat method. 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 [http://castle-engine.sourceforge.net/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 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 StrToFloat. 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;`
Reexported in this unit, so that the identifier `ECasScriptSyntaxError` will be visible when using this unit.
Generated by PasDoc 0.13.0 on 2015-06-15 04:43:11