Compiles script code without running it and returns any compiler errors.
This function is exported by the KS module.
Errors := ParseScript(Code)
Type: String
Either the path of a script file or the script source itself. If a file of that name exists it is parsed, otherwise the value is parsed as source.
Type: String
Returns an empty string if the code compiles. Otherwise returns the compiler error text, which is suitable for display.
Only compilation is performed: the code is never executed, no hotkeys are registered and the auto-execute section does not run. This makes ParseScript suitable for validating code a script generated or received before writing it to disk.
The --validate command-line option performs the same check on a file from outside a script.
Validates generated code before saving it.
#Import "Ks" { ParseScript }
Code := "MsgBox 'hello'"
if (Errs := ParseScript(Code))
MsgBox "Generated code is invalid:`n" Errs
else
FileAppend Code, A_ScriptDir "\generated.ks"
#Import "Ks" { ParseScript }
MsgBox ParseScript(A_ScriptDir "\other.ks") || "No errors"