Пример #1
0
        // TODO: dokončiť!
        // zostupne podľa priority vyhľadávania
        // konštanty sa pridružujú k iným operandom a určujú sa podľa kontextu!

        // "string"
        // "string".member
        // "string"[i]

        // &"FILE_LOCALIZED_STRING"

        // 56 | -56 | +56

        // []

        // { 1, 2, 3 }

        // (0,1,2)
        // (0,1,2)[i]

        // (subExpression)
        // (subExpression).member
        // (subExpression)[i]

        // true
        // false
        // undefined

        // thread

        // ::func
        // path::func | path::const

        // var | const
        // var.member
        // var[i]


        // as operators

        // = Expression

        // lastOperand [[delegate]]()
        // lastOperand [[delegate]]().member
        // lastOperand [[delegate]]()[i]

        // lastOperand func()
        // lastOperand func().member
        // lastOperand func()[i]
        // lastOperand path::func()
        // lastOperand path::func().member
        // lastOperand path::func()[i]

        public static bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo, ref bool isSingleOperand, bool isArrayContentDefEnabled, bool isArrayDefEnabled)
        {
            if ((isArrayDefEnabled && (ArrayDef.Check(parentInfo, parsingInfo, scriptInfo))) || // []
                (isArrayContentDefEnabled && ArrayContentDef.Check(parentInfo, parsingInfo, scriptInfo)))    // { 0,1,2 }
            {
                isSingleOperand = IsSingle(parentInfo, parsingInfo);
                return(true);
            }

            if (StringArray.Check(parentInfo, parsingInfo, scriptInfo) || // "str" | "str".member | "str"[]
                LocalizedString.Check(parentInfo, parsingInfo, scriptInfo) || // &"str"
                SignedNumber.Check(parentInfo, parsingInfo, scriptInfo) || // 56 | -56 | +56
                Vector.Check(parentInfo, parsingInfo, scriptInfo) || // (0,1,2) | (0,1,2)[]
                SubExpression.Check(parentInfo, parsingInfo, scriptInfo) || // (exp) | (exp).member* | (exp)[]*
                Literal.Check(parentInfo, parsingInfo, scriptInfo) || // true | false | undefined
                FuncCallModifier.Check(parentInfo, parsingInfo, scriptInfo) || // thread
                DelegateCall.Check(parentInfo, parsingInfo, scriptInfo) || // // [[delegate]](funcArgs) | [[d]]().member* | [[d]]()[]*
                FuncCall.Check(parentInfo, parsingInfo, scriptInfo) || // f() | path::f() | f().member* | f()[i]*
                DelegateDef.Check(parentInfo, parsingInfo, scriptInfo) || // ::func | path::func
                VarName.Check(parentInfo, parsingInfo, scriptInfo)    // var | var.member* | var[i]*
                )
            {
                isSingleOperand = IsSingle(parentInfo, parsingInfo);
                return(true);
            }

            return(false);
        }
Пример #2
0
        public override IElement CreateCopy()
        {
            DelegateCall e = new DelegateCall();

            e.Arguments = Arguments;
            e.AddChildren(this.CopyChildren());
            return(e);
        }
Пример #3
0
        public static bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo,
                                 ref bool isNextOperand, ref bool isNextNeeded, out bool isSingleOperand, bool isExpStatement, bool isArrayContentDefEnabled, bool isArrayDefEnabled)
        {
            isSingleOperand = false;
            IElement cur = parentInfo.Current;

            if (isNextOperand) // operand
            {
                // all unary operators -> without + and -
                // ex. !var
                if (!isExpStatement && UnaryOperator.Check(parentInfo, parsingInfo, scriptInfo))
                {
                    isNextOperand = true;
                    isNextNeeded  = true;
                    return(true);
                }

                // real operand
                // ex. VarName, FuncCall, etc.
                if (ExpressionOperand.Check(parentInfo, parsingInfo, scriptInfo, ref isSingleOperand, isArrayContentDefEnabled, isArrayDefEnabled))
                {
                    isNextOperand = false;
                    isNextNeeded  = false;
                    return(true);
                }
                else
                {
                    if (isNextNeeded)
                    {
                        throw new SyntaxException("Could not find operand", parentInfo.GetErrorInfo());
                    }

                    return(false);
                }
            }
            else // operator
            {
                if (isExpStatement && PostfixIncDec.Check(parentInfo, parsingInfo, scriptInfo))
                {
                    isSingleOperand = ExpressionOperand.IsSingle(parentInfo, parsingInfo);
                    isNextOperand   = false;
                    isNextNeeded    = false;
                    return(true);
                }

                if (!isExpStatement && BinaryOperator.Check(parentInfo, parsingInfo, scriptInfo))
                {
                    isNextOperand = true;
                    isNextNeeded  = true;
                    return(true);
                }

                if (isExpStatement && Assign.Check(parentInfo, parsingInfo, scriptInfo)) // = Expression
                {
                    isSingleOperand = ExpressionOperand.IsSingle(parentInfo, parsingInfo);
                    isNextNeeded    = false;
                    isNextOperand   = false;
                    return(true);
                }

                // self thread f()
                if (FuncCallModifier.Check(parentInfo, parsingInfo, scriptInfo)) // thread
                {
                    isSingleOperand = ExpressionOperand.IsSingle(parentInfo, parsingInfo);
                    isNextNeeded    = true;
                    isNextOperand   = false;
                    return(true);
                }

                // self f()
                // self thread f()
                // NOT f() !!
                if (DelegateCall.Check(parentInfo, parsingInfo, scriptInfo) || // // [[delegate]](funcArgs) | [[d]]().member* | [[d]]()[]*
                    FuncCall.Check(parentInfo, parsingInfo, scriptInfo))    // f() | path::f() | f().member* | f()[i]*
                {
                    isSingleOperand = ExpressionOperand.IsSingle(parentInfo, parsingInfo);
                    isNextOperand   = false;
                    isNextNeeded    = false;
                    return(true);
                }

                if (isNextNeeded)
                {
                    throw new SyntaxException("unknown operator '" + parentInfo.Current.ToString() + "'", parentInfo.GetErrorInfo());
                }
                else
                {
                    return(false);
                }
            }
        }
Пример #4
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            DelegateCall delegCall = new DelegateCall();
            MoveInfo     moveInfo  = new MoveInfo(parentInfo);

            DelegateCallGroup group     = (DelegateCallGroup)parentInfo.Current;
            MoveInfo          groupInfo = new MoveInfo(group, SearchTree.ContentBlock, 0, parentInfo);

            Expression deleg = Expression.Parse(groupInfo, parsingInfo, scriptInfo);

            if (deleg == null || groupInfo.FindNextBlack(SearchDirection.LeftToRight) != null)
            {
                throw new SyntaxException("Could not parse delegate", parentInfo.GetErrorInfo());
            }

            #region ParsingInfo Args
            object lastCall         = parsingInfo.CurrentCall;
            int?   lastCallArgIndex = parsingInfo.CurrentCallArgIndex;
            parsingInfo.CurrentCall         = delegCall;
            parsingInfo.CurrentCallArgIndex = 0;
            #endregion

            // find args
            moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            if (!FuncArgs.Check(moveInfo, parsingInfo, scriptInfo))
            {
                throw new SyntaxException("Could not find delegate funcArgs", parentInfo.GetErrorInfo());
            }

            int startIndex = parentInfo.CurrentIndex;
            int length;

            #region ParsingInfo Args
            parsingInfo.CurrentCall         = lastCall;
            parsingInfo.CurrentCallArgIndex = lastCallArgIndex;
            #endregion

            // find self and modifiers
            MoveInfo selfInfo = new MoveInfo(parentInfo);
            IElement self     = selfInfo.FindNextBlack(SearchDirection.RightToLeft);
            if (self != null && self is ExpressionOperand) // self is self or FuncCallModifier
            {
                startIndex = selfInfo.CurrentIndex;
                if (self is FuncCallModifier) // self is FuncCallModifier -> find self
                {
                    self = selfInfo.FindNextBlack(SearchDirection.RightToLeft);
                    if (self != null && self is ExpressionOperand)
                    {
                        startIndex = selfInfo.CurrentIndex;
                    }
                }
            }

            // find members and arrayIndexers
            IElement next = null;
            do
            {
                length = (moveInfo.CurrentIndex + 1) - startIndex;
                next   = moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            }while (next != null &&
                    (ArrayIndexer.Check(moveInfo, parsingInfo, scriptInfo) ||
                     DataMember.Check(moveInfo, parsingInfo, scriptInfo)));

            // build
            delegCall.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.MoveToIndex(startIndex);
            parentInfo.Replace(length, delegCall);
        }