Esempio n. 1
0
        public static int FindParamPosition(CompilerState State, StringSlice Code)
        {
            var Ok       = false;
            var Handlers = State.Language.GlobalHandlers;
            var RSM      = new ResultSkippingManager(Handlers, Code);

            var Language       = State.Language;
            var LangRoot       = Language.Root;
            var CastRecognizer = Language.Root.GetObject <CastRecognizer>(false);

            while (RSM.Loop())
            {
                var Pos = RSM.Current;
                var Chr = Code[Pos];
                if (!Helper.IsIdChar(Chr))
                {
                    if (!Ok)
                    {
                        continue;
                    }

                    if (Chr == '(')
                    {
                        var Brackets = Code.Substring(Pos);
                        if (CastRecognizer != null && CastRecognizer.IsCastString(State, Brackets))
                        {
                            return(Pos);
                        }

                        if (Brackets.GetBracketPos(false, Handlers) == Brackets.Length - 1)
                        {
                            return(Pos);
                        }
                    }
                    else if (char.IsWhiteSpace(Chr))
                    {
                        // ambiguous: Print (Obj is object).ToString()
                        var After    = Code.Substring(Pos + 1).Trim();
                        var AfterChr = After.Length > 0 ? After[0] : '\0';
                        if (Helper.IsIdChar(AfterChr) || AfterChr == '(' || AfterChr == '[')
                        {
                            return(Pos);
                        }
                    }

                    if (Code.SubstringEquals(Pos, LangRoot.OnlyRight, LangRoot.OnlyRightSkip,
                                             false, new IdCharCheck(true)).Position != -1)
                    {
                        return(Pos);
                    }

                    for (var i = 0; i < Language.ExprRecognizers.Length; i++)
                    {
                        var Rec = Language.ExprRecognizers[i] as SkippedBetweenRecognizer;
                        if (Rec != null && Code.SubstringEquals(Pos, Rec.Operators, Rec.Skip).Index != -1)
                        {
                            return(Pos);
                        }
                    }
                }
                else
                {
                    Ok = true;
                }
            }

            return(-1);
        }