Closed state-developer closed 1 week ago
SourceProgramOptions is a reasonable way to validate a file, but you can make it more efficient by skipping the compilation step. All you need is to parse and resolve:
isPredeclared := StringDict{"foo": nil}.Has // defines the additional name "foo"
f, err := opts.Parse(filename, src, 0)
if err != nil { ... } // syntax error
err := resolve.File(f, isPredeclared, Universe.Has)
if err != nil { ... } // semantic error
Currently, I am using SourceProgramOptions to validate a script that is passed in via an API. There are several "keywords" I want to use and make sure they exist to allow for parsing to pass and say the source is valid. I just want to validate the script is valid without executing it.
Is there a better approach to accomplishing this?
Thanks and looking forward to your help.