Example #1
0
        public Boolean InBrackets()
        {
#if !NET20
            if (this.Count >= 1 &&
                this.First().TokenType != TokenType.BRACKET_BEGIN &&
                this.Last().TokenType != TokenType.BRACKET_END)
#else
            if (this.Count >= 1 &&
                Linq2.FirstOrDefault(this).TokenType != TokenType.BRACKET_BEGIN &&
                Linq2.LastOrDefault(this).TokenType != TokenType.BRACKET_END)
#endif
            {
                return(false);
            }
            return(this.Count > 1);
        }
Example #2
0
        public Boolean CloseInBrackets()
        {
#if !NET20
            if (this.Count >= 1 &&
                this.First().TokenType != TokenType.BRACKET_BEGIN &&
                this.Last().TokenType != TokenType.BRACKET_END)
#else
            if (this.Count >= 1 &&
                Linq2.FirstOrDefault(this).TokenType != TokenType.BRACKET_BEGIN &&
                Linq2.LastOrDefault(this).TokenType != TokenType.BRACKET_END)
#endif
            {
                this.Insert(0, new ExpressionToken(new[] { '(' }, TokenType.BRACKET_BEGIN));
                this.Add(new ExpressionToken(new[] { ')' }, TokenType.BRACKET_END));
                return(true);
            }
            return(false);
        }
Example #3
0
        public void RemoveBrackets()
        {
            while (this.Count > 1)
            {
#if !NET20
                if (this.First().TokenType == TokenType.BRACKET_BEGIN &&
                    this.Last().TokenType == TokenType.BRACKET_END)
#else
                if (Linq2.FirstOrDefault(this).TokenType == TokenType.BRACKET_BEGIN &&
                    Linq2.LastOrDefault(this).TokenType == TokenType.BRACKET_END)
#endif
                {
                    this.RemoveAt(0);
                    this.RemoveAt(this.Count - 1);
                }
                else
                {
                    break;
                }
            }
        }
Example #4
0
        //////////////////////////////////////////////

        public virtual ExpressionValue GetValue(
            DynContext EvalContext,
            String Name,
            Boolean SeekForExtenders,
            Boolean SeekForMethods,
            Boolean SeekInContexts)
        {
#if CASE_INSENSITIVE
            Name = Name.ToUpper();
#endif

            DynContext DynLanContext = EvalContext as DynContext;
            if (DynLanContext == null)
            {
                return(null);
            }

            // szukanie extender'a
            if (SeekForExtenders)
            {
                ExpressionExtenderInfo extender = BuildinExtenders.FindByName(Name);
                if (extender != null)
                {
                    return(new ExpressionValue(extender));
                }
            }

            if (SeekInContexts)
            {
                // szukanie zmiennej w lokalnym kontekście
                if (DynLanContext.CurrentState != DynLanContext.GlobalState)
                {
                    // szukanie zmiennej w metodach gdzie została zadeklarowana metoda
                    if (DynLanContext.Stack != null)
                    {
#if !NET20
                        DynLanState currentState = DynLanContext.
                                                   Stack.
                                                   LastOrDefault();
#else
                        DynLanState currentState = Linq2.LastOrDefault(
                            DynLanContext.Stack);
#endif
                        DynLanMethod method = currentState == null ? null :
                                              currentState.Program as DynLanMethod;

                        if (method != null)
                        {
                            for (Int32 i = DynLanContext.Stack.Count - 2; i >= 0; i--)
                            {
                                DynLanState state = DynLanContext.Stack[i];

                                DynLanMethod thisMethod = state.Program as DynLanMethod;
                                DynLanObject thisObject = state.Object;
                                if (thisMethod == null)
                                {
                                    break;
                                }

                                if (thisMethod != null &&
                                    thisMethod.Methods != null &&
                                    thisMethod.Methods.Contains(method))
                                {
                                    if (thisObject != null &&
                                        thisObject.Contains(Name))
                                    {
                                        return(new ExpressionValue(thisObject[Name]));
                                    }
                                }
                                else
                                {
                                    break;
                                }

                                method = thisMethod;
                            }
                        }
                    }

                    if (DynLanContext.CurrentState.Object != null &&
                        DynLanContext.CurrentState.Object.Contains(Name))
                    {
                        return(new ExpressionValue(DynLanContext.CurrentState.Object[Name]));
                    }
                }

                // szukanie zmiennej w globalnym kontekście
                if (DynLanContext.GlobalState.Object != null &&
                    DynLanContext.GlobalState.Object.Contains(Name))
                {
                    return(new ExpressionValue(DynLanContext.GlobalState.Object[Name]));
                }
            }

            // przeniesione na dło aby metody i zmiennej których nazwy pokrywaja sie z globalnymi
            // mobly byc używane
            // szukanie metody
            if (SeekForMethods)
            {
                ExpressionMethodInfo method = BuildinMethods.FindByName(Name);
                if (method != null)
                {
                    return(new ExpressionValue(method));
                }
            }

            /*for (var i = DynLanContext.Stack.IndexOf(DynLanContext.Current); i >= 0; i--)
             * {
             *  DynLanState context = DynLanContext.Stack[i];
             *
             *  if ((context == DynLanContext.Current || context.ContextType == DynLanContextType.GLOBAL) &&
             *      context.Object != null &&
             *      context.Object.Contains(Name))
             *  {
             *      return new ExpressionValue(context.Object[Name]);
             *  }
             * }*/

            // szukanie po globalnych zmiennych

            /*if (DynLanContext.GlobalContext.ContextType == DynLanContextType.GLOBAL)
             * {
             *  if (DynLanContext.GlobalContext.Object.Contains(Name))
             *      return new ExpressionValue(DynLanContext.GlobalContext.Object[Name]);
             * }*/

            return(null);
        }