Advertisement

Provide engine function to parse string from script into in-memory representation

Started by February 27, 2020 02:19 PM
5 comments, last by WitchLord 4 years, 9 months ago

Currently, trying to parse script code manually to for instance parse metadata requires you to manually parse strings including the various forms (single quotes, double quotes, heredoc) which duplicates engine logic.

It would be helpful if we could simply call an engine function to parse it instead. Provide an input buffer to store the result (or null to query the buffer size required) and return the result with all syntax resolved, including escape sequences.

This function could look like this:

size_t ParseScriptString(char* buffer, size_t bufferSize, const char* string, size_t stringLength = 0) const;

Does asIScriptEngine::ParseToken work for you?

It doesn't produce a syntax tree for you, but at least it helps you identify each token so you need not bother with interpreting string tokens with escape sequences, etc.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement

@WitchLord I'm already using that function to parse out the type, but the actual string being extracted still contains unescaped quotes, unescaped escape sequences and unicode code points.

So what you want is basically to have the asCCompiler::ProcessStringConstant and ProcessHeredocStringConstant exposed to the application in the interface?

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

@WitchLord Pretty much, yes.

That should be do-able.

I've added the suggestion to the to-do list.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement