コード例 #1
0
        // @"\A\s*call\s+(?<name>.+)"
        unsafe public override bool IsSyntaxMatchFast(char *ptr, int length, ref List <string> args)
        {
            string callStr = "call"; // should be interned

            fixed(char *ptrB = callStr)
            {
                // skip whitespaces
                DHJassSyntax.skipWhiteSpacesFast(ref ptr);

                // "call" keyword should be here
                if (!DHJassSyntax.checkStringsEqual(ptr, ptrB, callStr.Length))
                {
                    return(false);
                }

                // skip the "call`" bytes
                ptr += callStr.Length;

                // make sure the "call" is followed by whitespace
                if (*ptr != ' ')
                {
                    return(false);
                }

                // skip whitespaces
                DHJassSyntax.skipWhiteSpacesFast(ref ptr);

                // add argument
                args.Add(new string(ptr));
                return(true);
            }
        }
コード例 #2
0
        // @"\A\s*exitwhen\s*(?<condition>.*)"
        unsafe public override bool IsSyntaxMatchFast(char *ptr, int length, ref List <string> args)
        {
            string exitwhenStr = "exitwhen"; // should be interned

            fixed(char *ptrB = exitwhenStr)
            {
                // skip whitespaces
                DHJassSyntax.skipWhiteSpacesFast(ref ptr);

                // "exitwhen" keyword should be here
                if (!DHJassSyntax.checkStringsEqual(ptr, ptrB, exitwhenStr.Length))
                {
                    return(false);
                }

                // skip the "exitwhen`" bytes
                ptr += exitwhenStr.Length;

                // skip whitespaces
                DHJassSyntax.skipWhiteSpacesFast(ref ptr);

                // add argument
                args.Add(new string(ptr));
                return(true);
            }
        }
コード例 #3
0
        public DHJassCallOperation(List <string> lines, ref int line, List <string> args)
        {
            // concat this line with next if it contains a string with newline character
            // the determining factor is odd number of quotes

            int    quotes      = -1;
            string result      = "";
            string currentLine = args[0];

            do
            {
                if (quotes != -1)
                {
                    currentLine = lines[++line];
                    result     += Environment.NewLine + currentLine;
                }
                else
                {
                    quotes  = 0;
                    result += currentLine;
                }

                quotes += DHJassSyntax.getQuoteCountFast(currentLine);
            }while (quotes % 2 != 0);

            command = new DHJassCallFunctionCommand(result);
        }
コード例 #4
0
        // @"\A\s*loop"
        unsafe public override bool IsSyntaxMatchFast(char *ptr, int length, ref List <string> args)
        {
            // skip whitespaces
            DHJassSyntax.skipWhiteSpacesFast(ref ptr);

            // 'loop' == 0x0070006F006F006C
            return(*(Int64 *)ptr == 0x0070006F006F006C);
        }
コード例 #5
0
        // @"\A\s*(if|elseif)\s*(?<condition>.*[^\s]{1})\s*then"
        unsafe public override bool IsSyntaxMatchFast(char *code, int length, ref List <string> args)
        {
            string ifStr     = "if"; // should be interned
            string elseifStr = "elseif";
            string thenStr   = "then";

            char *ptr = code;

            fixed(char *ptrIF = ifStr, ptrELSEIF = elseifStr, ptrTHEN = thenStr)
            {
                // skip whitespaces
                DHJassSyntax.skipWhiteSpacesFast(ref ptr);

                // "if" or "elseif" keyword should be here
                if (DHJassSyntax.checkStringsEqual(ptr, ptrIF, ifStr.Length))
                {
                    ptr += ifStr.Length; // skip the "if" bytes
                }
                else
                if (DHJassSyntax.checkStringsEqual(ptr, ptrELSEIF, elseifStr.Length))
                {
                    ptr += elseifStr.Length;     // skip the "elseif" bytes
                }
                else
                {
                    return(false);
                }

                // skip whitespaces
                DHJassSyntax.skipWhiteSpacesFast(ref ptr);

                // go to the end of this string where "then" string should be
                char *pEnd = (code + length) - thenStr.Length;

                // check for "then" string
                if (!DHJassSyntax.checkStringsEqual(pEnd, ptrTHEN, thenStr.Length))
                {
                    return(false);
                }

                // skip whitespaces from the end
                --pEnd;
                DHJassSyntax.skipWhiteSpacesReverseFast(ref pEnd);

                // make sure the condition is not empty
                if (ptr > pEnd)
                {
                    return(false);
                }

                // add argument
                args.Add(new string(ptr, 0, (int)(pEnd - ptr) + 1));
                return(true);
            }
        }
コード例 #6
0
ファイル: _Commands.cs プロジェクト: sonygod/dotahit
        public DHJassCallFunctionCommand(string code)
        {
            //Match match;
            string        name;
            List <string> args;

            if (DHJassSyntax.checkFunctionUsageSyntaxFast(code, out name, out args)) //out match))
            {
                parse(name, args);                                                   //match);
            }
            else
            {
                function = null;
            }
        }
コード例 #7
0
        // @"\A\s*endloop"
        bool IBodyEndSyntaxHolder.CheckBodyEndSyntax(string code)
        {
            unsafe
            {
                fixed(char *pCode = code)
                {
                    char *tmpPtr = pCode;

                    // skip whitespaces
                    DHJassSyntax.skipWhiteSpacesFast(ref tmpPtr);

                    Int64 *ptr = (Int64 *)tmpPtr;

                    // 'endl' == 0x006C0064006E0065
                    // '\0oop'== 0x0070006F006F0000

                    return((*ptr == 0x006C0064006E0065) &&
                           ((*(++ptr)) << 16) == 0x0070006F006F0000);
                }
            }
        }
コード例 #8
0
ファイル: _Commands.cs プロジェクト: sonygod/dotahit
        public bool TryParseCode(string name_usage, string valueToSet, out DHJassCommand command)
        {
            string name;
            string param;

            if (DHJassSyntax.checkTypeVariableUsageSyntaxFast(name_usage, out name))
            {
                command = new DHJassPassVariableCommand(name);
                value   = new DHJassGetValueOnDemandCommand(valueToSet);
                return(true);
            }
            else
            if (DHJassSyntax.checkArrayVariableUsageSyntaxFast(name_usage, out name, out param))
            {
                command = new DHJassPassVariableCommand(name);
                index   = new DHJassGetValueOnDemandCommand(param);
                value   = new DHJassGetValueOnDemandCommand(valueToSet);

                return(true);
            }

            command = null;
            return(false);
        }
コード例 #9
0
ファイル: _Commands.cs プロジェクト: sonygod/dotahit
        public bool TryParseCode(string code, out DHJassCommand command)
        {
            if (String.IsNullOrEmpty(code))
            {
                command = null;
                return(false);
            }

            string        name;
            string        param;
            List <string> operands;
            List <string> operators;
            bool          isDirectValue;
            object        parsedValue;

            unsafe
            {
                fixed(char *pStr = code)
                {
                    char *ptr = DHJassSyntax.removeWsRbRecursive(pStr, pStr + code.Length);

                    code = new string(ptr);

                    if (isDirectValue = DHJassSyntax.checkDirectValueSyntaxFast(*ptr))
                    {
                        foreach (DHJassValue parser in DbJassTypeValueKnowledge.TypeValuePairs.Values)
                        {
                            if (parser.TryParseDirect(code, out parsedValue))
                            {
                                DHJassValue value = parser.GetNew();
                                value.Value = parsedValue;
                                command     = new DHJassPassValueCommand(value);
                                return(true);
                            }
                        }
                    }
                    else
                    {
                        switch (code)
                        {
                        case "null":
                            command = new DHJassPassValueCommand(new DHJassUnusedType());
                            return(true);

                        case "true":
                            command = new DHJassPassValueCommand(new DHJassBoolean(null, true));
                            return(true);

                        case "false":
                            command = new DHJassPassValueCommand(new DHJassBoolean(null, false));
                            return(true);
                        }
                    }

                    if (DHJassSyntax.checkLogicalExpressionsSyntaxFast(ptr, out operands, out operators))//code, out match))
                    {
                        return(TryGetLogicalExpressionCommandFast(operands, operators, out command));
                    }
                    else
                    if (DHJassSyntax.checkRelationalExpressionsSyntaxFast(ptr, out operands, out operators)) // out match))
                    {
                        return(TryGetRelationalExpressionCommandFast(operands, operators, out command));     //match, out command);
                    }
                    else
                    if (DHJassSyntax.checkArithmeticExpressionsSyntaxFast(ptr, out operands, out operators))    // out match))
                    {
                        return(TryGetArithmeticExpressionCommandFast(operands, operators, out command));        //match, out command);
                    }
                    else
                    if (!isDirectValue)
                    {
                        if (DHJassSyntax.checkNegativeOperatorUsageSyntaxFast(ptr, out name))
                        {
                            return(TryGetNegativeOperatorCommand(name, out command));
                        }
                        else
                        if (DHJassSyntax.checkTypeVariableUsageSyntaxFast(ptr, out name))
                        {
                            return(TryGetVariableCommand(name, out command));
                        }
                        else
                        if (DHJassSyntax.checkArrayVariableUsageSyntaxFast(ptr, out name, out param))
                        {
                            return(TryGetArrayElementCommand(name, param, out command));
                        }
                        else
                        if (DHJassSyntax.checkFunctionUsageSyntaxFast(ptr, out name, out operands))                        // out match))
                        {
                            return(TryGetCallFunctionCommandFast(name, operands, out command));
                        }
                        else
                        if (DHJassSyntax.checkFunctionPointerUsageSyntaxFast(ptr, out name))
                        {
                            return(TryGetFunctionPointerCommand(name, out command));
                        }
                    }
                }
            }

            command = null;
            return(false);
        }
コード例 #10
0
        // @"\A\s*set\s+(?<name>[^=]+[^\s]|[^=]+)\s*=\s*(?<value>.+)"
        unsafe public override bool IsSyntaxMatchFast(char *ptr, int length, ref List <string> args)
        {
            string setStr = "set"; // should be interned

            fixed(char *ptrB = setStr)
            {
                // skip whitespaces
                DHJassSyntax.skipWhiteSpacesFast(ref ptr);

                // "set" keyword should be here
                if (!DHJassSyntax.checkStringsEqual(ptr, ptrB, setStr.Length))
                {
                    return(false);
                }

                // skip the "set`" bytes
                ptr += setStr.Length;

                // there should be white space after "set"
                if (*ptr != ' ')
                {
                    return(false);
                }

                // skip whitespaces
                DHJassSyntax.skipWhiteSpacesFast(ref ptr);

                // move to the end of variable name
                char *pVariableEnd = DHJassSyntax.reachEndOfVarArrNameSyntaxFast(ptr);

                if (pVariableEnd == null)
                {
                    return(false);
                }

                // memorize starting position of variable's name
                char *pVariableStart = ptr;

                ptr = pVariableEnd;

                // skip whitespaces
                DHJassSyntax.skipWhiteSpacesFast(ref ptr);

                // make sure the '=' is present
                if (*ptr != '=')
                {
                    return(false);
                }
                ++ptr; // move beyond '='

                // skip whitespaces
                DHJassSyntax.skipWhiteSpacesFast(ref ptr);

                // add variable name argument
                args.Add(new string(pVariableStart, 0, (int)(pVariableEnd - pVariableStart)));

                // add variable value argument
                args.Add(new string(ptr));
                return(true);
            }
        }
コード例 #11
0
        //@"\A\s*(else|elseif\s*.+|endif)"
        bool IBodyEndSyntaxHolder.CheckBodyEndSyntax(string code)
        {
            unsafe
            {
                fixed(char *pCode = code)
                {
                    char *tmpPtr = pCode;

                    // skip whitespaces
                    DHJassSyntax.skipWhiteSpacesFast(ref tmpPtr);

                    Int64 *ptr = (Int64 *)tmpPtr;

                    // 'else' == 0x00650073006C0065
                    // 'endi' == 0x00690064006E0065

                    switch (*ptr)
                    {
                    case 0x00650073006C0065:     // 'else'
                        ptr++;
                        switch (*(Int16 *)ptr)
                        {
                        case 0x0000:         // '\0'
                        case 0x0020:         // ' '
                            return(true);
                        }

                        // check for 'elseif'

                        // '\0if ' == 0x0020006600690000
                        // '\0if(' == 0x0028006600690000
                        // '\0if\0'== 0x0000006600690000

                        switch ((*ptr) << 16)
                        {
                        case 0x0020006600690000:
                        case 0x0028006600690000:
                        case 0x0000006600690000:
                            return(true);
                        }
                        return(false);

                    case 0x00690064006E0065:     // 'endi'
                        ptr++;

                        // 'f ' == 0x00200066
                        // 'f(' == 0x00280066
                        // 'f\0'== 0x00000066

                        switch (*(Int32 *)ptr)
                        {
                        case 0x00200066:
                        case 0x00280066:
                        case 0x00000066:
                            return(true);
                        }
                        return(false);
                    }

                    return(false);
                }
            }
        }