コード例 #1
0
ファイル: Parser.cs プロジェクト: senny970/2007
        public static OpsParsedStatement[] ParseScript(string script)
        {
            if (script == null || script.Length == 0)
            {
                return(null);
            }

            if (OpsConsole.Verbose)
            {
                OpsConsole.WriteLine("Parsing script starting.");
            }


            char lastChar = script[script.Length - 1];

            if (lastChar != ';' && lastChar != '\n')
            {
                script += '\n';
            }

            ArrayList parsedStatements = new ArrayList();

            int iStatement = 0;

            for (Match statementMatch = StatementReg.Match(script); statementMatch.Success; iStatement++, statementMatch = statementMatch.NextMatch())
            {
                try
                {
                    OpsParsedStatement parsedStatement = ParseStatement(statementMatch);

                    //statements can be null  such as a ;
                    if (parsedStatement != null)
                    {
                        parsedStatements.Add(parsedStatement);

                        if (OpsConsole.Verbose)
                        {
                            OpsConsole.WriteLine("Parsing statement: \"{0}\"", parsedStatement);
                        }
                    }
                }
                catch (Exception e)
                {
                    OpsConsole.WriteError(iStatement + 1, e, "Could not parse statement: {0}", statementMatch.Result("${statement}"));
                    throw;
                }
            }

            OpsParsedStatement[] result = new OpsParsedStatement[parsedStatements.Count];
            parsedStatements.CopyTo(result, 0);


            if (OpsConsole.Verbose)
            {
                OpsConsole.WriteLine("Found {0} statements.", result.Length);
                OpsConsole.WriteLine("Parsing script finished.");
            }

            return(result);
        }
コード例 #2
0
ファイル: Parser.cs プロジェクト: senny970/2007
        public static OpsParsedStatement ParseStatement(Match statementMatch)
        {
            string command = statementMatch.Result("${command}").Trim();
            string invalid = statementMatch.Result("${invalid}");

            if (command.Length == 0)
            {
                if (invalid.Length == 0)
                {
                    return(null); // no statement
                }
                else
                {
                    throw new OpsException("Could not pattern match statement.\nCheck that command and argument identifier match " + IdentifierExp + "\nand argument value with spaces are surrounded by single quotes.");
                }
            }

            OpsParsedStatement result = new OpsParsedStatement();

            result.Command = command;

            string args = statementMatch.Result("${args}");

            ParseArguments(result, args);

            return(result);
        }
コード例 #3
0
            public UnloadArguments(OpsParsedStatement statement)
            {
                OpsParsedArgument srcArg = statement.FindArgument("src");
                if( srcArg == null )
                {
                    srcArg = statement.FindArgument("");
                    if( srcArg == null )
                        throw OpsException.ArgRequired("src");
                }
                Src = srcArg.Value;

                OpsParsedArgument filterArg = statement.FindArgument("Type");
                if( filterArg != null )
                {
                    if(0==string.Compare(filterArg.Value, "Texture", true) )
                        Type = ContentType.TEXTURES;
                    else if(0==string.Compare(filterArg.Value, "Textures", true) )
                        Type = ContentType.TEXTURES;
                    else if(0==string.Compare(filterArg.Value, "Model", true) )
                        Type = ContentType.MODELS;
                    else if(0==string.Compare(filterArg.Value, "Models", true) )
                        Type = ContentType.MODELS;
                    else if(0==string.Compare(filterArg.Value, "Both", true) )
                        Type = ContentType.GENERIC;
                    else
                        throw new OpsException("Type Argument is invalid.  Value must be (Textures|Models|Both).");
                }
            }
コード例 #4
0
        public OpsStatement( OpsParsedStatement parsed, IOpsCommand command, object arguments)
        {
            Parsed = parsed;
            OpsParsedArgument arg = parsed.FindArgument("Src");
            ContentRegex = (arg == null) ? "(?# Default Expression ).*" : arg.Value;

            Command = command;
            Arguments = arguments;
        }
コード例 #5
0
ファイル: Script.cs プロジェクト: senny970/2007
        public OpsStatement(OpsParsedStatement parsed, IOpsCommand command, object arguments)
        {
            Parsed = parsed;
            OpsParsedArgument arg = parsed.FindArgument("Src");

            ContentRegex = (arg == null) ? "(?# Default Expression ).*" : arg.Value;

            Command   = command;
            Arguments = arguments;
        }
コード例 #6
0
ファイル: Parser.cs プロジェクト: senny970/2007
        public static void ParseArguments(OpsParsedStatement statement, string args)
        {
            ArrayList argList = new ArrayList();

            for (Match argMatch = ArgsReg.Match(args); argMatch.Success; argMatch = argMatch.NextMatch())
            {
                OpsParsedArgument arg = new OpsParsedArgument();

                arg.Name = argMatch.Result("${argName}").Trim();

                string UnescapedArgValue = argMatch.Result("${argVal}");
                arg.Value = EscapeTickReg.Replace(UnescapedArgValue, "'").Trim();

                argList.Add(arg);
            }

            statement.Args = new OpsParsedArgument[argList.Count];
            argList.CopyTo(statement.Args);
        }
コード例 #7
0
        public static OpsParsedStatement[] ParseScript(string script)
        {
            if(script == null || script.Length == 0)
                return null;

            if(OpsConsole.Verbose)
                OpsConsole.WriteLine("Parsing script starting.");


            char lastChar = script[script.Length-1];
            if( lastChar != ';' && lastChar != '\n')
                script += '\n';

            ArrayList parsedStatements = new ArrayList();

            int iStatement = 0;
            for (Match statementMatch = StatementReg.Match(script); statementMatch.Success; iStatement++, statementMatch = statementMatch.NextMatch())
            {

                try
                {
                    OpsParsedStatement parsedStatement = ParseStatement(statementMatch);
                    
                    //statements can be null  such as a ;
                    if(parsedStatement != null)
                    {
                        parsedStatements.Add(parsedStatement);

                        if(OpsConsole.Verbose)
                            OpsConsole.WriteLine("Parsing statement: \"{0}\"", parsedStatement);
                    }
                }
                catch (Exception e)
                {
                    OpsConsole.WriteError( iStatement+1, e, "Could not parse statement: {0}", statementMatch.Result("${statement}")); 
                    throw;
                }
            }

            OpsParsedStatement[] result = new OpsParsedStatement[parsedStatements.Count];
            parsedStatements.CopyTo(result, 0);
            
        
            if(OpsConsole.Verbose)
            {
                OpsConsole.WriteLine("Found {0} statements.", result.Length);
                OpsConsole.WriteLine("Parsing script finished.");
            }

            return result;
        }        
コード例 #8
0
        public static void ParseArguments(OpsParsedStatement statement, string args)
        {
            ArrayList argList = new ArrayList();
            for (Match argMatch = ArgsReg.Match(args); argMatch.Success; argMatch = argMatch.NextMatch())
            {
                OpsParsedArgument arg = new OpsParsedArgument();

                arg.Name = argMatch.Result("${argName}").Trim();

                string UnescapedArgValue = argMatch.Result("${argVal}");
                arg.Value =  EscapeTickReg.Replace(UnescapedArgValue, "'").Trim();

                argList.Add(arg);
            }

            statement.Args = new OpsParsedArgument[argList.Count];
            argList.CopyTo(statement.Args);
        }
コード例 #9
0
        public static OpsParsedStatement ParseStatement(Match statementMatch)
        {

            string command = statementMatch.Result("${command}").Trim();
            string invalid = statementMatch.Result("${invalid}");

            if (command.Length == 0)
            {
                if(invalid.Length == 0)
                    return null; // no statement
                else
                    throw new OpsException( "Could not pattern match statement.\nCheck that command and argument identifier match " + IdentifierExp + "\nand argument value with spaces are surrounded by single quotes.");
            }

            OpsParsedStatement result = new OpsParsedStatement();

            result.Command = command;

            string args = statementMatch.Result("${args}");
            ParseArguments(result, args);

            return result;
        }
コード例 #10
0
ファイル: Script.cs プロジェクト: senny970/2007
        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.");
                }
            }
        }
コード例 #11
0
 //IOpsCommand
 public object ParseArguments(OpsParsedStatement statement)
 {
     return new UnloadArguments(statement);
 }