ArgScript::FormatParser class

This class contains all the parsers necessary to process a certain ArgScript format.

Check ArgScript for more information.

Constructors, destructors, conversion operators

~FormatParser() virtual

Public functions

auto AddRef() -> int virtual
auto Release() -> int virtual
auto Initialize() -> bool virtual
auto Dispose() -> bool virtual
void SetData(void* pData) virtual
Sets the object that is being parsed in this format parser.
void AddParser(const char* pKeyword, IParser* pParser) virtual
Adds the given IParser to this format; it will be used when a line with the specified keyword is found.
void AddParser(const char* pKeyword, ParseLine_t pParseLine)
void AddParser(const char* pKeyword, ParseLine_t pParseLine, GetDescription_t pGetDescription)
void AddParser(const char* pKeyword, ParseLine_t pParseLine, SetData_t pSetData)
auto RemoveParser(const char* pKeyword) -> bool virtual
Removes the IParser mapped to the specified keyword.
auto RemoveParserByObject(IParser* pParser) -> bool virtual
Removes the specified IParser from this format.
auto GetParser(const char* pKeyword) const -> IParser* virtual
Returns the IParser mapped to the given keyword, or nullptr if no parser is mapped to that keyword.
void SetFlag(int flag, bool bValue) virtual
void SetVersionRange(int nMinVersion, int nMaxVerison) virtual
Sets the minimum and maximum version that the script can have.
auto GetVersion() const -> int virtual
Gets the version of the current script.
void func30h() virtual
void Close(bool = false) virtual
Closes all blocks and special blocks and exits the current scope.
void ProcessFile(const char* pPath) virtual
Reads an ArgScript file in the specified physical path (that is, in the disk).
void ProcessStream(IO::IStream* pInputStream) virtual
Reads an ArgScript file from the IStream given.
void ProcessLine(const char* pString) virtual
Converts the given string into a ArgScript::Line and it process it using the correct IParser, determined by the keyword (the first word in the line).
void CreateDefinition(const char* pName, const Line& argumentsLine) virtual
Creates an instance of a definition of the given name using the specified parameters.
auto ProcessFileSafe(const char* pFilePath) -> bool virtual
Reads an ArgScript file from the file path given, without throwing any exceptions.
auto ProcessStreamSafe(IO::IStream* pStream) -> bool virtual
Reads an ArgScript file from the IStream given, without throwing any exceptions.
auto ProcessLineSafe(const char* pString) -> bool virtual
Converts the given string into a ArgScript::Line and it process it using the correct IParser, determined by the keyword (the first word in the line), without throwing any exceptions.
auto CreateDefinitionSafe(const char* pName, const Line& argumentsLine) -> bool virtual
Creates an instance of a definition of the given name using the specified parameters.
auto func58h() -> int virtual
auto func5Ch() -> int virtual
auto func60h(int, int) -> int virtual
auto HasParser(const char* pName) const -> int virtual
Tells whether this format parser has a parser assigned to the given keyword.
auto HasDefinition(const char* pName) const -> bool virtual
Tells whether this format parser has a definition with the given name.
void SetVariable(const char* pName, const char* pValue) virtual
Sets the value of a variable.
auto GetVariable(const char* pVariableName) -> const char* virtual
Returns the string value of the specified variable, or nullptr if the variable is not mapped.
void SetGlobalVariable(const char* pName, const char* pValue) virtual
Sets the value of a global variable.
void func78h(int) virtual
void StartScope(const char* pName) virtual
Starts a scope with the given name.
void EndScope() virtual
Ends the current scope.
void PurgeScope(const char* pScope) virtual
Removes all the variables definitions from the given namespace scope.
auto GetCurrentScope() const -> const char* virtual
Returns the string used by the current scope, for example, 'App:'.
void AddBlock(IBlock* pBlock) virtual
Adds the given block to this parser.
auto AddSpecialBlock(ISpecialBlock* pSpecialBlock, const char* pEndKeyword) -> int virtual
Adds the given special block to this parser; the block will end when the specified keyword is found.
auto ParseBool(const char* pString) const -> bool virtual
Converts the specified string representation of a logical expression to its bool equivalent.
auto ParseFloat(const char* pString) const -> float virtual
Converts the specified string representation of a real number expression to its float equivalent.
auto ParseInt(const char* pString) const -> int virtual
Converts the specified string representation of an integer number expression to its int equivalent.
auto ParseUInt(const char* pString) const -> unsigned int virtual
Same as ParseInt(const char*).
auto ParseVector2(const char* pString) const -> Math::Vector2 virtual
Parses two real numbers separated with commas and puts them into a Vector2.
auto ParseVector3(const char* pString) const -> Math::Vector3 virtual
Parses three real numbers separated with commas and puts them into a Vector3.
auto ParseVector4(const char* pString) const -> Math::Vector4 virtual
Parses four real numbers separated with commas and puts them into a Vector4.
auto ParseColorRGB(const char* pString) const -> Math::ColorRGB virtual
Parses three real numbers separated with commas and puts them into a ColorRGB.
auto ParseColorRGBA(const char* pString) const -> Math::ColorRGBA virtual
Parses three or four real numbers separated with commas and puts them into a ColorRGBA.
auto GetLexer() -> Lexer& virtual
Returns the Lexer instance of this format parser.
void SetTraceStream(ITraceStream* pTraceStream) virtual
Sets the ITraceStream where the text can be output from this ArgScript instance.
void funcC0h(int) virtual
auto GetTraceStream() -> ITraceStream* virtual
Gets the ITraceStream where the text can be output from this ArgScript instance.
auto funcC8h() -> int virtual

Protected variables

uint32_t field_04
int mnRefCount
bool field_0C
int mnFlags
intrusive_ptr<ITraceStream> mpTraceStream
int field_18
int mnMinVersion
int mnMaxVersion
int mnVersion
void* mpData
hash_map<string, intrusive_ptr<IParser>> mParsers
Lexer mLexer
hash_map<string, int> mDefinitions
hash_map<string, string> mVariables
hash_map<string, string> mGlobalVariables
int field_CC
string field_D0
string field_E0
int field_F0
string field_F4
int field_104
vector<IBlock*> mBlocks
vector<pair<ISpecialBlock*, const char*>> mSpecialBlocks
string mCurrentScope
vector<size_t> mScopeLenghts
string field_154
bool field_164
int field_168
ArgScript::Line mTempLine
string mTempString

Function documentation

void ArgScript::FormatParser::SetData(void* pData) virtual

Sets the object that is being parsed in this format parser.

Parameters
pData A pointer to the object.

Commands and blocks can use this data object to set all the information parsed somewhere. The data can be of any type, since it won't be used directly by any default implementation.

void ArgScript::FormatParser::AddParser(const char* pKeyword, IParser* pParser) virtual

Adds the given IParser to this format; it will be used when a line with the specified keyword is found.

Parameters
pKeyword The keyword that is used to call this parser. It is not case sensitive.
pParser

The IParser::SetData() method will be called, passing the current data object of the format parser as a parameter.

bool ArgScript::FormatParser::RemoveParser(const char* pKeyword) virtual

Removes the IParser mapped to the specified keyword.

Parameters
pKeyword The keyword that is used to call the parser. It is not case sensitive.
Returns True if the parser was removed, false if no parser was mapped to that keyword.

bool ArgScript::FormatParser::RemoveParserByObject(IParser* pParser) virtual

Removes the specified IParser from this format.

Parameters
pParser The IParser to remove.
Returns True if the parser was removed, false if no parser was mapped.

IParser* ArgScript::FormatParser::GetParser(const char* pKeyword) const virtual

Returns the IParser mapped to the given keyword, or nullptr if no parser is mapped to that keyword.

Parameters
pKeyword The keyword used to call the parser.

void ArgScript::FormatParser::SetVersionRange(int nMinVersion, int nMaxVerison) virtual

Sets the minimum and maximum version that the script can have.

The script version is specified using the 'version' command; if the version is out of range, an exception will be thrown when parsing that command.

void ArgScript::FormatParser::Close(bool = false) virtual

Closes all blocks and special blocks and exits the current scope.

This will call IBlock::OnBlockEnd() on all blocks and ISpecialBlock::OnEnd() on all special blocks.

void ArgScript::FormatParser::ProcessFile(const char* pPath) virtual

Reads an ArgScript file in the specified physical path (that is, in the disk).

Parameters
pPath The file path to the file to process.
Exceptions
ArgScriptException If there is a problem while reading or the format is incorrect.

void ArgScript::FormatParser::ProcessStream(IO::IStream* pInputStream) virtual

Reads an ArgScript file from the IStream given.

Parameters
pInputStream The input IStream with the data to process.
Exceptions
ArgScriptException If there is a problem while reading or the format is incorrect.

void ArgScript::FormatParser::ProcessLine(const char* pString) virtual

Converts the given string into a ArgScript::Line and it process it using the correct IParser, determined by the keyword (the first word in the line).

Parameters
pString The input line string.
Exceptions
ArgScriptException If the keyword is not mapped.
ArgScriptException If the format is not correct.

If the keyword is not mapped to any parser, an exception will be thrown.

void ArgScript::FormatParser::CreateDefinition(const char* pName, const Line& argumentsLine) virtual

Creates an instance of a definition of the given name using the specified parameters.

Parameters
pName The name of the definition.
argumentsLine The line that contains the arguments (separated by spaces, not commas)
Exceptions
ArgScriptException If no definition with that name exists.
ArgScriptException If the number of arguments is not correct.
ArgScriptException If a keyword of the code in the definition is not mapped.
ArgScriptException If the format is not correct.

Definitions are pieces of text with parameters that can be replaced; definitions can be created using the 'define' keyword.

bool ArgScript::FormatParser::ProcessFileSafe(const char* pFilePath) virtual

Reads an ArgScript file from the file path given, without throwing any exceptions.

Parameters
pFilePath The file path to the file to process.
Returns True if there were no exceptions, false otherwise.

This calls ProcessFile(const char*) inside a try-catch block.

bool ArgScript::FormatParser::ProcessStreamSafe(IO::IStream* pStream) virtual

Reads an ArgScript file from the IStream given, without throwing any exceptions.

Returns True if there were no exceptions, false otherwise.

This calls ProcessStream(IO::IStream*) inside a try-catch block.

bool ArgScript::FormatParser::ProcessLineSafe(const char* pString) virtual

Converts the given string into a ArgScript::Line and it process it using the correct IParser, determined by the keyword (the first word in the line), without throwing any exceptions.

Parameters
pString The input line string.
Returns True if no exceptions were thrown, false otherwise.

This calls ProcessLine(const char*) inside a try-catch block.

bool ArgScript::FormatParser::CreateDefinitionSafe(const char* pName, const Line& argumentsLine) virtual

Creates an instance of a definition of the given name using the specified parameters.

Parameters
pName The name of the definition.
argumentsLine The line that contains the arguments (separated by spaces, not commas)
Returns True if no exceptions were thrown, false otherwise.

Definitions are pieces of text with parameters that can be replaced; definitions can be created using the 'define' keyword. This calls ProcessDefinition() inside a try-catch block, so that no exceptions are thrown.

int ArgScript::FormatParser::HasParser(const char* pName) const virtual

Tells whether this format parser has a parser assigned to the given keyword.

Parameters
pName The keyword mapped to the parser (not case sensitive).
Returns True if there is an IParser with this name.

bool ArgScript::FormatParser::HasDefinition(const char* pName) const virtual

Tells whether this format parser has a definition with the given name.

Parameters
pName The name of the definition (not case sensitive).
Returns True if there is a definition with this name.

void ArgScript::FormatParser::SetVariable(const char* pName, const char* pValue) virtual

Sets the value of a variable.

Parameters
pName The name of the variable.
pValue The c-string value of the variable.

The value is always a string, which can contain other variables, referencing them with $ (and usually {} too; for example, to get the value of variable 'version', one would use '${version}' or '$version'). This variable will be added to the current scope.

const char* ArgScript::FormatParser::GetVariable(const char* pVariableName) virtual

Returns the string value of the specified variable, or nullptr if the variable is not mapped.

Parameters
pVariableName The name of the variable.

The variable is searched within the current scope and its parent scopes, unless another scope is specified (for example, Intel:card1 would search 'card1' inside the 'Intel' scope). If the name is prefixed with ':', the variable will be searched as a global variable first.

void ArgScript::FormatParser::SetGlobalVariable(const char* pName, const char* pValue) virtual

Sets the value of a global variable.

Parameters
pName The name of the variable.
pValue The c-string value of the variable.

The value is always a string, which can contain other variables, referencing them with $ (and usually {} too; for example, to get the value of variable 'version', one would use '${version}' or '$version'). To access global variables, their name must be prefixed with ':'. For example, to get the global variable 'build', one would use '$:build'.

void ArgScript::FormatParser::StartScope(const char* pName) virtual

Starts a scope with the given name.

Parameters
pName The name of the scope.

The scope will be inside the current scope. All the variables inside a scope can only be used within that scope; to use them from outside, they must be referenced using ':'. For example, to get the variable 'card1' inside the scope 'Intel', use 'Intel:card1'.

void ArgScript::FormatParser::PurgeScope(const char* pScope) virtual

Removes all the variables definitions from the given namespace scope.

Exceptions
ArgScriptException If the name of the scope is not valid.

The scope name must finish with ':' to be valid.

const char* ArgScript::FormatParser::GetCurrentScope() const virtual

Returns the string used by the current scope, for example, 'App:'.

The string is made by appending ':' after all the scope parents and the scope name. Variable names are the result of appending this string with the variable name.

void ArgScript::FormatParser::AddBlock(IBlock* pBlock) virtual

Adds the given block to this parser.

Parameters
pBlock The block that is currently being parsed.

This will allow the block to be notified when the 'end' keyword is reached. Blocks must do this on the IBlock::ParseLine() method in order to work properly. This does not start a new scope.

int ArgScript::FormatParser::AddSpecialBlock(ISpecialBlock* pSpecialBlock, const char* pEndKeyword) virtual

Adds the given special block to this parser; the block will end when the specified keyword is found.

Parameters
pSpecialBlock The special block.
pEndKeyword The keyword that ends the block.

Special blocks can process each line inside the block individually; for more information, check ISpecialBlock.

bool ArgScript::FormatParser::ParseBool(const char* pString) const virtual

Converts the specified string representation of a logical expression to its bool equivalent.

Parameters
pString The string to parse.
Exceptions
ArgScriptException If the boolean expression is not valid.

Values 'true', 'on' and '1' are evaluated as true, and 'false', 'off' and '0' are evaluated as false. Logical operators 'or', 'and', 'not' are allowed, as well as the use of boolean functions.

float ArgScript::FormatParser::ParseFloat(const char* pString) const virtual

Converts the specified string representation of a real number expression to its float equivalent.

Parameters
pString The string to parse.
Exceptions
ArgScriptException If the real expression is not valid.

Numerical expressions like + - * /, % (modulus), ^ (power) can be used, as well as the 'pi' constant. These functions are also supported:

  • sqrt(x): Returns the square root of the x.
  • exp(x): Returns e^x, where e is Euler's number.
  • log(x): Returns the natural logarithm (base e) of x.
  • abs(x): Returns the absolute value of x, that is, the value if no sign.
  • sin(x), cos(x), tan(x), asin(x), acos(x), atan(x): Trigonometical functions that work in radians.
  • sind(x), cosd(x), tand(x), dasin(x), dacos(x), datan(x): Trigonometical functions that work in degrees.
  • floor(x): Returns the largest integer less than or equal to x.
  • ceil(x): Returns the smallest integer greater than or equal to x.
  • sqr(x): Returns x^2.
  • pow(x, y): Returns x to the power of y, x^y.
  • atan2(x, y): Returns the arctangent of the quotient of its arguments, in radians.
  • datan2(x, y): Returns the arctangent of the quotient of its arguments, in degrees.
  • Any other function mapped in the lexer.

int ArgScript::FormatParser::ParseInt(const char* pString) const virtual

Converts the specified string representation of an integer number expression to its int equivalent.

Parameters
pString The string to parse.
Exceptions
ArgScriptException If the integer expression is not valid.

The integer operator + - * / % ^ can be used, as well as some functions from ParseFloat(const char*): 'abs', 'floor', 'ceil', 'sqr' and any function mapped in the lexer. The function 'round(x)' which rounds the real number x to the closest integer is also supported. All the supported functions can take real expressions (the ones used in ParseFloat(const char*)). Hexadecimal numbers, prefixed by 0x, are also supported. 'true' and 'on' are interpreted as 1, 'false' and 'off' are interpreted as 0.

unsigned int ArgScript::FormatParser::ParseUInt(const char* pString) const virtual

Same as ParseInt(const char*).

Parameters
pString The string to parse.
Exceptions
ArgScriptException If the integer expression is not valid.

Math::Vector2 ArgScript::FormatParser::ParseVector2(const char* pString) const virtual

Parses two real numbers separated with commas and puts them into a Vector2.

Parameters
pString The string to parse.
Exceptions
ArgScriptException If the real expression is not valid.

The numbers are parsed using the ParseFloat(const char*) function. If only one number is specified, the vector will be filled with that number.

Examples:

  • string '3.4, sqr(4)' will return Vector2(3.4, 16).
  • string '8' will return Vector2(8.0, 8.0).

Math::Vector3 ArgScript::FormatParser::ParseVector3(const char* pString) const virtual

Parses three real numbers separated with commas and puts them into a Vector3.

Parameters
pString The string to parse.
Exceptions
ArgScriptException If the real expression is not valid or only two numbers are specified.

The numbers are parsed using the ParseFloat(const char*) function. If only one number is specified, the vector will be filled with that number.

Examples:

  • string '3.4, sqr(4), 1.0 + 2' will return Vector3(3.4, 16.0, 3.0).
  • string '8' will return Vector3(8.0, 8.0, 8.0).

Math::Vector4 ArgScript::FormatParser::ParseVector4(const char* pString) const virtual

Parses four real numbers separated with commas and puts them into a Vector4.

Parameters
pString The string to parse.
Exceptions
ArgScriptException If the real expression is not valid or only two or three numbers are specified.

The numbers are parsed using the ParseFloat(const char*) function. If only one number is specified, the vector will be filled with that number.

Examples:

  • string '3.4, sqr(4), 1.0 + 2, 0' will return Vector4(3.4, 16.0, 3.0, 0.0).
  • string '8' will return Vector4(8.0, 8.0, 8.0, 8.0).

Math::ColorRGB ArgScript::FormatParser::ParseColorRGB(const char* pString) const virtual

Parses three real numbers separated with commas and puts them into a ColorRGB.

Parameters
pString The string to parse.
Exceptions
ArgScriptException If the real expression is not valid or only two numbers are specified.

The numbers are parsed using the ParseFloat(const char*) function. If only one number is specified, the color values will be filled with that number. This is equivalent to ParseVector3(const char*). Color numbers are usually in the range [0.0, 1.0].

Examples:

  • string '0.4, sqr(0.5), 0.5 * 2' will return ColorRGB(0.4, 0.25, 1.0).
  • string '0.2' will return ColorRGB(0.2, 0.2, 0.2).

Math::ColorRGBA ArgScript::FormatParser::ParseColorRGBA(const char* pString) const virtual

Parses three or four real numbers separated with commas and puts them into a ColorRGBA.

Parameters
pString The string to parse.
Exceptions
ArgScriptException If the real expression is not valid or only one or two numbers are specified.

The numbers are parsed using the ParseFloat(const char*) function. If only three numbers are specified, the alpha value will be assigned to 1.0. Color numbers are usually in the range [0.0, 1.0].

Examples:

  • string '0.4, sqr(0.5), 0.5 * 2' will return ColorRGB(0.4, 0.25, 1.0, 1.0).

void ArgScript::FormatParser::SetTraceStream(ITraceStream* pTraceStream) virtual

Sets the ITraceStream where the text can be output from this ArgScript instance.

Parameters
pTraceStream