// Validates a single script. ValidationMessage[] ValidateFile(TextAsset script, Analysis.Context analysisContext, out CheckerResult.State result) { var messageList = new List <ValidationMessage>(); var variableStorage = new Yarn.MemoryVariableStore(); var dialog = new Dialogue(variableStorage); bool failed = false; dialog.LogErrorMessage = delegate(string message) { var msg = new ValidationMessage(); msg.type = MessageType.Error; msg.message = message; messageList.Add(msg); // any errors means this validation failed failed = true; }; dialog.LogDebugMessage = delegate(string message) { var msg = new ValidationMessage(); msg.type = MessageType.Info; msg.message = message; messageList.Add(msg); }; try { dialog.LoadString(script.text, script.name); } catch (System.Exception e) { dialog.LogErrorMessage(e.Message); } dialog.Analyse(analysisContext); if (failed) { result = CheckerResult.State.Failed; } else { result = CheckerResult.State.Passed; } return(messageList.ToArray()); }
// Validates a single script. ValidationMessage[] ValidateFile(TextAsset script, Analysis.Context analysisContext, out CheckerResult.State result) { // The list of messages we got from the compiler. var messageList = new List <ValidationMessage>(); // A dummy variable storage; it won't be used, but Dialogue // needs it. var variableStorage = new Yarn.MemoryVariableStore(); // The Dialog object is the compiler. var dialog = new Dialogue(variableStorage); // Whether compilation failed or not; this will be // set to true if any error messages are returned. bool failed = false; // Called when we get an error message. Convert this // message into a ValidationMessage and store it; // additionally, mark that this file failed compilation dialog.LogErrorMessage = delegate(string message) { var msg = new ValidationMessage(); msg.type = MessageType.Error; msg.message = message; messageList.Add(msg); // any errors means this validation failed failed = true; }; // Called when we get an error message. Convert this // message into a ValidationMessage and store it dialog.LogDebugMessage = delegate(string message) { var msg = new ValidationMessage(); msg.type = MessageType.Info; msg.message = message; messageList.Add(msg); }; // Attempt to compile this script. Any exceptions will result // in an error message try { dialog.LoadString(script.text, script.name); } catch (System.Exception e) { dialog.LogErrorMessage(e.Message); } // Once compilation has finished, run the analysis on it dialog.Analyse(analysisContext); // Did it succeed or not? if (failed) { result = CheckerResult.State.Failed; } else { result = CheckerResult.State.Passed; } // All done. return(messageList.ToArray()); }