public OpsScript(OpsCommandLibrary library, string script) { OpsParsedStatement[] parsedStatements = OpsParser.ParseScript(script); if(parsedStatements != null) { if(OpsConsole.Verbose) OpsConsole.WriteLine("Prevalidating script starting."); Statements = new OpsStatement[parsedStatements.Length]; for( int i = 0; i < parsedStatements.Length; i++) { OpsParsedStatement parsed = parsedStatements[i] as OpsParsedStatement; IOpsCommand command = null; object arguments = null; if(OpsConsole.Verbose) OpsConsole.WriteLine("Prevalidating statement #{0}: \"{1}\"", i, parsed); try { command = library.GetCommand(parsed.Command); } catch( Exception e ) { OpsConsole.WriteError(i+1, e, "Unable to fetch command: " + parsed.Command); throw; } if(command is IOpsRemappable) { try { command = (command as IOpsRemappable).RemapCommand(parsed); } catch( Exception e ) { OpsConsole.WriteError(i+1, e, "Unable to remap command: " + parsed.Command); throw; } } try { arguments = command.ParseArguments(parsed); } catch( Exception e ) { OpsConsole.WriteError(i+1, e, "Command failed to interpret the arguments."); throw; } Statements[i] = new OpsStatement(parsed, command, arguments); } if(OpsConsole.Verbose) OpsConsole.WriteLine("Prevalidating script finished."); } }
public OpsScript(OpsCommandLibrary library, string script) { OpsParsedStatement[] parsedStatements = OpsParser.ParseScript(script); if (parsedStatements != null) { if (OpsConsole.Verbose) { OpsConsole.WriteLine("Prevalidating script starting."); } Statements = new OpsStatement[parsedStatements.Length]; for (int i = 0; i < parsedStatements.Length; i++) { OpsParsedStatement parsed = parsedStatements[i] as OpsParsedStatement; IOpsCommand command = null; object arguments = null; if (OpsConsole.Verbose) { OpsConsole.WriteLine("Prevalidating statement #{0}: \"{1}\"", i, parsed); } try { command = library.GetCommand(parsed.Command); } catch (Exception e) { OpsConsole.WriteError(i + 1, e, "Unable to fetch command: " + parsed.Command); throw; } if (command is IOpsRemappable) { try { command = (command as IOpsRemappable).RemapCommand(parsed); } catch (Exception e) { OpsConsole.WriteError(i + 1, e, "Unable to remap command: " + parsed.Command); throw; } } try { arguments = command.ParseArguments(parsed); } catch (Exception e) { OpsConsole.WriteError(i + 1, e, "Command failed to interpret the arguments."); throw; } Statements[i] = new OpsStatement(parsed, command, arguments); } if (OpsConsole.Verbose) { OpsConsole.WriteLine("Prevalidating script finished."); } } }