Ejemplo n.º 1
0
        //////////////////////////////////////////////////////////////////////////////////////////////////

        public virtual Object Clone()
        {
            DynLanProgram item = (DynLanProgram)this.MemberwiseClone();

#if !NET20
            if (item.Lines != null)
            {
                item.Lines = new DynLanCodeLines(item.Lines.Select(i => i.Clone()));
            }
            if (item.Classes != null)
            {
                item.Classes = new DynLanClasses(item.Classes.Select(i => i.Clone() as DynLanClass));
            }
            if (item.Methods != null)
            {
                item.Methods = new DynLanMethods(item.Methods.Select(i => i.Clone() as DynLanMethod));
            }
#else
            if (item.Lines != null)
            {
                item.Lines = new DynLanCodeLines(Linq2.Select(item.Lines, i => i.Clone()));
            }
            if (item.Classes != null)
            {
                item.Classes = new DynLanClasses(Linq2.Select(item.Classes, i => i.Clone() as DynLanClass));
            }
            if (item.Methods != null)
            {
                item.Methods = new DynLanMethods(Linq2.Select(item.Methods, i => i.Clone() as DynLanMethod));
            }
#endif

            return(item);
        }
Ejemplo n.º 2
0
        private ExpressionTokens GetSetTokens(IList <ExpressionToken> Tokens)
        {
            ExpressionTokens result = null;

            if (Tokens.Count >= 2)
            {
                if (Linq2.Any(Tokens, t => t.TokenType == TokenType.EQUAL_OPERATOR))
                {
                    for (var i = 0; i < Tokens.Count; i++)
                    {
                        ExpressionToken token = Tokens[i];

                        if (token.TokenType == TokenType.EQUAL_OPERATOR)
                        {
                            break;
                        }

                        if (result == null)
                        {
                            result = new ExpressionTokens();
                        }
                        result.Add(token);
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        ////////////////////////////////////////////

        public Type GetPropertyType(Type Type, String Name)
        {
            if (this.unsensitive)
            {
                Name = Name.ToUpper();
            }

            if (!_cachePropertiesTypes.ContainsKey(Type))
            {
                lock (lck)
                {
                    if (!_cachePropertiesTypes.ContainsKey(Type))
                    {
#if !NET20
                        _cachePropertiesTypes[Type] = Type.GetProperties().ToDictionary(
                            p => this.unsensitive ? p.Name.ToUpper() : p.Name,
                            p => p.PropertyType);
#else
                        _cachePropertiesTypes[Type] = Linq2.ToDictionary(Type.GetProperties(),
                                                                         p => this.unsensitive ? p.Name.ToUpper() : p.Name,
                                                                         p => p.PropertyType);
#endif
                    }
                }
            }
            return(_cachePropertiesTypes.ContainsKey(Type) && _cachePropertiesTypes[Type].ContainsKey(Name) ?
                   _cachePropertiesTypes[Type][Name] :
                   null);
        }
Ejemplo n.º 4
0
        //////////////////////////////////////////////////

        public Int32 IndexOfSequence(IEnumerable <ExpressionToken> Sequence)
        {
            Int32 index = -1;

#if !NET20
            if (Sequence.Any())
#else
            if (Linq2.Any(Sequence))
#endif

            {
#if !NET20
                index = this.IndexOf(Sequence.First());
#else
                index = this.IndexOf(Linq2.FirstOrDefault(Sequence));
#endif
                if (index >= 0)
                {
                    Int32 nextIndex = index;
                    foreach (ExpressionToken item in Sequence)
                    {
                        if (this.IndexOf(item) != nextIndex)
                        {
                            return(-1);
                        }
                        nextIndex++;
                    }
                }
            }

            return(index);
        }
Ejemplo n.º 5
0
        //////////////////////////////

        public override string ToString()
        {
            return(String.Format(
                       "{0}",
                       //ID,
                       String.Join(" ", Linq2.ToArray(Linq2.Select(this.Tokens, i => i.TokenName)))));
        }
Ejemplo n.º 6
0
        public DynLanMethod By_Name(String Name)
        {
#if !NET20
            return(this.FirstOrDefault(i => i.Name == Name));
#else
            return(Linq2.FirstOrDefault(this, i => i.Name == Name));
#endif
        }
Ejemplo n.º 7
0
        ////////////////////////////////////////

        public DynLanCodeLine Get_by_ID(Guid ID)
        {
#if !NET20
            return(this.FirstOrDefault(i => i.ID == ID));
#else
            return(Linq2.FirstOrDefault(this, i => i.ID == ID));
#endif
        }
Ejemplo n.º 8
0
        public void test_linq_select()
        {
            var array = new[] { "aaa", "bb", "dddd", "c" };

            var r1 = string.Join(",", array.Select(i => i.Length).ToArray());
            var r2 = string.Join(",", Linq2.From(array).Select(i => i.Length).ToArray());

            Assert.AreEqual(r1, r2);
        }
Ejemplo n.º 9
0
        public void test_linq_orderby2()
        {
            var array = new[] { "aaa", "bb", "dddd", "c" };

            var r1 = string.Join(",", array.Select(i => i.Length).OrderBy(i => i).ToArray());
            var r2 = string.Join(",", Linq2.OrderBy(Linq2.Select(array, i => i.Length), i => i).ToArray());

            Assert.AreEqual(r1, r2);
        }
Ejemplo n.º 10
0
        public void Set(IList <Char> TokenName, Boolean CorrectPriority)
        {
            this.TokenChars = TokenName;
            this.TokenName  = new String(Linq2.ToArray(this.TokenChars));

            if (CorrectPriority)
            {
                this.Priority = OnpOnpTokenHelper.GetPriority(this);
            }
        }
Ejemplo n.º 11
0
        public void Set(String TokenName, Boolean CorrectPriority)
        {
            this.TokenChars = Linq2.ToArray(TokenName.ToCharArray());
            this.TokenName  = TokenName;

            if (CorrectPriority)
            {
                this.Priority = OnpOnpTokenHelper.GetPriority(this);
            }
        }
Ejemplo n.º 12
0
        public ExpressionToken Clone()
        {
            ExpressionToken item = (ExpressionToken)this.MemberwiseClone();

            item.TokenChars = Linq2.ToArray(this.TokenChars);
            if (item.TokenData != null)
            {
                item.TokenData = item.TokenData.Clone();
            }
            return(item);
        }
Ejemplo n.º 13
0
        public virtual Expression Clone()
        {
            Expression item = (Expression)this.MemberwiseClone();

            if (item.Tokens != null)
            {
                item.Tokens = new ExpressionTokens(Linq2.Select(item.Tokens, i => i.Clone()));
            }
            if (item.OnpTokens != null)
            {
                item.OnpTokens = new ExpressionTokens(Linq2.Select(item.OnpTokens, i => i.Clone()));
            }
            return(item);
        }
Ejemplo n.º 14
0
        private IList <String> GetVariablesNames(Expression Expression, ExpressionGroup ExpressionGroup)
        {
#if !NET20
            return(Expression.
                   Tokens.
                   Where(t => t.TokenType == TokenType.VARIABLE && !ExpressionGroup.Expressions.ContainsKey(t.TokenName)).
                   Select(t => t.TokenName).
                   ToArray());
#else
            return(Linq2.From(Expression.Tokens).
                   Where(t => t.TokenType == TokenType.VARIABLE && !ExpressionGroup.Expressions.ContainsKey(t.TokenName)).
                   Select(t => t.TokenName).
                   ToArray());
#endif
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
        //////////////////////////////////////////////////

        public void CopyTo(Object Source, Object Dest, String[] PropertiesToOmit)
        {
            if (Source == null || Dest == null)
            {
                return;
            }

            if (unsensitive)
            {
#if !NET20
                PropertiesToOmit = PropertiesToOmit.Select(i => i.ToUpper()).ToArray();
#else
                PropertiesToOmit = Linq2.From(PropertiesToOmit).Select(i => i.ToUpper()).ToArray();
#endif
            }

            foreach (var property in GetPropertyinfos(Source))
            {
                if (PropertiesToOmit != null && PropertiesToOmit.Length > 0)
                {
                    if (Linq2.Contains(PropertiesToOmit, unsensitive ? property.Name.ToUpper() : property.Name))
                    {
                        continue;
                    }
                }

                if (Attribute.IsDefined(property, typeof(NoCloneAttribute)))
                {
                    continue;
                }

                try
                {
                    SetValue(
                        Dest,
                        property.Name,
                        GetValue(Source, property.Name));
                }
                catch
                {
                    throw;
                }
            }
        }
Ejemplo n.º 18
0
        ////////////////////

        public static Boolean Is(
#if !NET20
            this
#endif
            Type Type, Type Subclass)
        {
            if (Subclass.IsInterface)
            {
#if !NET20
                return(Type.GetInterfaces().Contains(Subclass));
#else
                return(Linq2.Contains(Type.GetInterfaces(), Subclass));
#endif
            }
            else
            {
                return(PrivIs(Type, Subclass));
            }
        }
Ejemplo n.º 19
0
        public String[] GetProperties(Type Type)
        {
            if (!_cacheProperties.ContainsKey(Type))
            {
                lock (lck)
                {
                    if (!_cacheProperties.ContainsKey(Type))
                    {
#if !NET20
                        _cacheProperties[Type] = Type.GetProperties().Select(p => this.unsensitive ? p.Name.ToUpper() : p.Name).ToArray();
#else
                        _cacheProperties[Type] = Linq2.From(Type.GetProperties()).Select(p => this.unsensitive ? p.Name.ToUpper() : p.Name).ToArray();
#endif
                    }
                }
            }
            return(_cacheProperties.ContainsKey(Type) ?
                   _cacheProperties[Type] :
                   new String[0]);
        }
Ejemplo n.º 20
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;
                }
            }
        }
Ejemplo n.º 21
0
        public virtual ExpressionGroup Clone()
        {
            ExpressionGroup item = (ExpressionGroup)this.MemberwiseClone();

            if (item.MainExpression != null)
            {
                item.MainExpression = item.MainExpression.Clone();
            }
            if (item.Expressions != null)
            {
#if !NET20
                item.Expressions = item.Expressions.ToDictionary(
                    i => i.Key,
                    i => i.Value.Clone());
#else
                item.Expressions = Linq2.ToDictionary(item.Expressions,
                                                      i => i.Key,
                                                      i => i.Value.Clone());
#endif
            }
            return(item);
        }
Ejemplo n.º 22
0
        public static IEnumerable <String> SplitMethodParameters(String Code, Boolean AllObjects)
        {
            StringBuilder paramStr = new StringBuilder();
            Boolean       isFirst  = true;

            IList <String> tokens = Linq2.ToList(TokenGetter.
                                                 GetStringTokens(Code.Trim()));

            foreach (String token in tokens)
            {
                if (token.EndsWith(","))
                {
                    if (!isFirst && AllObjects)
                    {
                        yield return(",");
                    }

                    isFirst = false;
                    paramStr.Append(token.Substring(0, token.Length - 1));
                    yield return(paramStr.ToString());

                    paramStr.Remove(0, paramStr.Length);
                }
                else
                {
                    paramStr.Append(token);
                }
            }
            if (paramStr.Length > 0)
            {
                if (!isFirst && AllObjects)
                {
                    yield return(",");
                }

                yield return(paramStr.ToString());
            }
        }
Ejemplo n.º 23
0
        public static IList <Char> TrimEnd(
#if !NET20
            this
#endif
            IEnumerable <Char> Chars,
            Char?trimchar)
        {
            var chars = Linq2.ToList(Chars);

            for (var i = chars.Count - 1; i >= 0; i--)
            {
                char ch = chars[i];
                if (trimchar == null ? Char.IsWhiteSpace(ch) : trimchar == ch)
                {
                    chars.RemoveAt(i);
                }
                else
                {
                    break;
                }
            }
            return(chars);
        }
Ejemplo n.º 24
0
        private ExpressionTokens TakeSetTokens(IList <ExpressionToken> Tokens, Boolean RemoveTakenTokens)
        {
            ExpressionTokens result = null;

            if (Tokens.Count >= 2)
            {
                if (Linq2.Any(Tokens, t => t.TokenType == TokenType.EQUAL_OPERATOR))
                {
                    for (var i = 0; i < Tokens.Count; i++)
                    {
                        ExpressionToken token = Tokens[i];

                        if (token.TokenType == TokenType.EQUAL_OPERATOR)
                        {
                            if (RemoveTakenTokens)
                            {
                                Tokens.RemoveAt(i);
                            }
                            break;
                        }

                        if (result == null)
                        {
                            result = new ExpressionTokens();
                        }
                        result.Add(token.Clone());

                        if (RemoveTakenTokens)
                        {
                            Tokens.RemoveAt(i);
                            i--;
                        }
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 25
0
        public static Type FindType(String Name)
        {
            Init();

            if (cache.ContainsKey(Name))
            {
                var dict = cache[Name];

                if (dict.ContainsKey(Name))
                {
                    return(dict[Name]);
                }
                else
                {
#if !NET20
                    return(dict.First().Value);
#else
                    return(Linq2.FirstOrDefault(dict).Value);
#endif
                }
            }

            return(null);
        }
Ejemplo n.º 26
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);
        }
Ejemplo n.º 27
0
        ////////////////////////////////////////////////////////////////////////

        public static Object Execute(DynContext EvaluateContext, Object obj, IList <Object> Parameters)
        {
            Object Collection = obj;

#if !NET20
            Object Key = Parameters == null ? null : Parameters.FirstOrDefault();
#else
            Object Key = Parameters == null ? null : Linq2.FirstOrDefault(Parameters);
#endif
            if (Collection == null)
            {
                return(null);
            }

            if (Collection is String)
            {
                Int32?index = UniConvert.ToInt32N(Key);
                if (index == null || index < 0)
                {
                    return(null);
                }

                String str = (String)Collection;
                if (index >= str.Length)
                {
                    return(null);
                }

                return(str[index.Value]);
            }

            if (Collection is DynLanObject)
            {
                DynLanObject DynLanObj = Collection as DynLanObject;

                if (DynLanObj.TotalCount == 0)
                {
                    return(null);
                }

                /*IDictionary<String, Object> dict = ((DynLanObject)Collection).Values;
                 * if (dict.Count == 0)
                 *  return null;*/

                String finalKey = ((String)(Key.GetType() == typeof(String) ? Key :
                                            Convert.ChangeType(Key, typeof(String), System.Globalization.CultureInfo.InvariantCulture)));

                return(DynLanObj[finalKey]);
            }

            if (Collection is IDictionaryWithGetter)
            {
                IDictionaryWithGetter dict = Collection as IDictionaryWithGetter;
                if (dict.CanGetValueFromDictionary(Key))
                {
                    return(dict.GetValueFromDictionary(Key));
                }
            }
            else if (Collection is IDictionary)
            {
                IDictionary dict = (IDictionary)Collection;
                if (dict.Count == 0)
                {
                    return(null);
                }

                Type[] arguments = dict.GetType().GetGenericArguments();
                Type   keyType   = arguments[0];

                Object finalKey = Key.GetType() == keyType ? Key :
                                  Convert.ChangeType(Key, keyType, System.Globalization.CultureInfo.InvariantCulture);

                return(dict[finalKey]);
            }
            else if (Collection is IDictionary <string, object> )
            {
                IDictionary <string, object> dict = (IDictionary <string, object>)Collection;
                if (dict.Count == 0)
                {
                    return(null);
                }
                return(dict[UniConvert.ToString(Key)]);
            }

            if (Collection is IList)
            {
                Int32?index = UniConvert.ToInt32N(Key);
                if (index == null || index < 0)
                {
                    return(null);
                }

                IList list = (IList)Collection;
                if (index >= list.Count)
                {
                    return(null);
                }

                return(list[index.Value]);
            }

            if (Collection is IEnumerable)
            {
                Int32?index = UniConvert.ToInt32N(Key);
                if (index == null || index < 0)
                {
                    return(null);
                }

                Int32 i = -1;
                foreach (Object item in ((IEnumerable)Collection))
                {
                    i++;
                    if (i == index.Value)
                    {
                        return(item);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 28
0
        public MemberGetter GetGetter(Type type, String Name)
        {
            if (type != null && !String.IsNullOrEmpty(Name))
            {
                if (this.unsensitive)
                {
                    Name = Name.ToUpper();
                }

                Dictionary <String, MemberGetter> innerDict = null;

                if (!_cacheGetter.ContainsKey(type))
                {
                    lock (lck)
                    {
                        if (!_cacheGetter.ContainsKey(type))
                        {
                            _cacheGetter[type] = innerDict = new Dictionary <String, MemberGetter>();
                        }
                    }
                }
                innerDict = _cacheGetter[type];

                if (!innerDict.ContainsKey(Name))
                {
                    lock (lck)
                    {
                        if (!innerDict.ContainsKey(Name))
                        {
                            MemberGetter getter = null;
#if !NET20
                            PropertyInfo property = this.unsensitive ? type.GetProperties().FirstOrDefault(p => p.Name.ToUpper().Equals(Name)) : type.GetProperty(Name);
                            FieldInfo    field    = this.unsensitive ? type.GetFields().FirstOrDefault(p => p.Name.ToUpper().Equals(Name)) : type.GetField(Name);
#else
                            PropertyInfo property = this.unsensitive ? Linq2.FirstOrDefault(type.GetProperties(), p => p.Name.ToUpper().Equals(Name)) : type.GetProperty(Name);
                            FieldInfo    field    = this.unsensitive ? Linq2.FirstOrDefault(type.GetFields(), p => p.Name.ToUpper().Equals(Name)) : type.GetField(Name);
#endif
                            if (property != null || field != null)
                            {
                                if (property != null)
                                {
                                    getter = new MemberGetter()
                                    {
                                        P = property.GetGetMethod() ?? property.GetGetMethod(false)
                                    }
                                }
                                ;                                                                                                // type.DelegateForGetPropertyValue(property.Name);

                                if (getter == null)
                                {
                                    if (field != null)
                                    {
                                        getter = new MemberGetter()
                                        {
                                            F = field
                                        }
                                    }
                                }
                                ;                                                  // type.DelegateForGetFieldValue(field.Name);
                            }

                            innerDict[Name] = getter;
                        }
                    }
                }

                MemberGetter outGetter = null;
                innerDict.TryGetValue(Name, out outGetter);
                return(outGetter != null && outGetter.Exists() ? outGetter : null);
            }
            return(null);
        }
    }
Ejemplo n.º 29
0
        private static Boolean GotoCatch(
            DynContext DynLanContext,
            Exception exception)
        {
            while (true)
            {
                DynLanState currentState = DynLanContext.
                                           CurrentState;

                // reset dla kontekstu obliczeń, ponieważ przechodzimy do catch'a
                currentState.ExpressionContext = null;

                DynLanCodeLines lines       = currentState.GetCurrentLines();
                DynLanCodeLine  currentLine = currentState.GetCurrentLine();

                // poszukanie poprzedniego catch'a
                DynLanCodeLine prevCatch = DynLanCodeLinesExtender.
                                           PrevLineWithLessDepth(lines, currentLine, l => l.OperatorType == EOperatorType.CATCH);

                // poszukanie poprzedniego try'a
                DynLanCodeLine prevTry = DynLanCodeLinesExtender.
                                         PrevLineWithLessDepth(lines, currentLine, l => l.OperatorType == EOperatorType.TRY);

                if (exception is DynLanAbortException)
                {
                    ExitCurrentContext(
                        DynLanContext,
                        exception);

                    if (DynLanContext.IsFinished)
                    {
                        break;
                    }
                }
                else if (prevTry == null)
                {
                    ExitCurrentContext(
                        DynLanContext,
                        exception);

                    if (DynLanContext.IsFinished)
                    {
                        break;
                    }
                }
                // jeśli znalazł try'a i nie jesteśmy w catch'u
                else if (prevTry.Depth < currentLine.Depth &&
                         (prevCatch == null || lines.IndexOf(prevCatch) < lines.IndexOf(prevTry)))
                {
                    DynLanCodeLine nextCatch = DynLanCodeLinesExtender.NextOnSameOrLower(
                        lines,
                        prevTry,
                        i => i.OperatorType == EOperatorType.CATCH);

                    if (nextCatch != null)
                    {
                        ExpressionToken variableForException = null;

                        if (nextCatch.ExpressionGroup != null &&
                            nextCatch.ExpressionGroup.MainExpression != null &&
                            nextCatch.ExpressionGroup.MainExpression.Tokens != null &&
                            nextCatch.ExpressionGroup.MainExpression.Tokens.Count > 0)
                        {
#if !NET20
                            variableForException = nextCatch.
                                                   ExpressionGroup.MainExpression.Tokens.
                                                   FirstOrDefault(i => i.TokenType != TokenType.BRACKET_BEGIN);
#else
                            variableForException = Linq2.FirstOrDefault(nextCatch.
                                                                        ExpressionGroup.MainExpression.Tokens,
                                                                        i => i.TokenType != TokenType.BRACKET_BEGIN);
#endif
                        }


                        currentState.CurrentLineID = nextCatch.ID;

                        if (variableForException != null && !String.IsNullOrEmpty(variableForException.TokenName))
                        {
                            currentState.Object[variableForException.TokenName] = exception;
                        }

                        break;
                    }
                    else
                    {
                        ExitCurrentContext(
                            DynLanContext,
                            exception);

                        if (DynLanContext.IsFinished)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    ExitCurrentContext(
                        DynLanContext,
                        exception);

                    if (DynLanContext.IsFinished)
                    {
                        break;
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// zastapienie ciagu tokenków zmienną i podpiecie nowego wyrazenia do zmiennej
        /// </summary>
        public void CorrectQueueExpression(
            Expression Expression,
            ParserSettings ParserSettings,
            ExpressionGroup ExpressionGroup)
        {
            if (Expression == null)
            {
                return;
            }

            if (Expression.Tokens == null || Expression.Tokens.Count <= 0)
            {
                return;
            }

            for (var i = 0; i < Expression.Tokens.Count; i++)
            {
                ExpressionToken token      = Expression.Tokens[i];
                ExpressionToken token_next = i + 1 < Expression.Tokens.Count ? Expression.Tokens[i + 1] : null;
                ExpressionToken token_prev = i - 1 >= 0 ? Expression.Tokens[i - 1] : null;

                ExpressionTokens functionCallTokens = new ExpressionTokens(
                    GetNextTokensOnSameLevel(Expression.Tokens, i));

                if (functionCallTokens.Count > 1)
                {
                    // generowanie expressions dla wnętrz funkcji
                    IList <ExpressionTokens> functionParameters = Linq2.ToList(SplitTokensIntoFunctionParameters(functionCallTokens));
                    foreach (ExpressionTokens functionParameter in functionParameters)
                    {
                        // generowanie expression z wyrażenia z parametru
                        if (functionParameter.Count > 1)
                        {
                            Expression functionExpression = new Expression();
                            functionExpression.Tokens         = new ExpressionTokens(functionParameter);
                            functionExpression.IsOnpExecution = true;

                            ExpressionGroup.Expressions[functionExpression.ID] =
                                functionExpression;

                            new Tokenizer().PrepareExpressions(
                                functionExpression,
                                ParserSettings,
                                ExpressionGroup);

                            ExpressionToken functionParameterToken = new ExpressionToken(
                                functionExpression.ID.ToCharArray(),
                                TokenType.VARIABLE);

                            Int32 index = Expression.Tokens.
                                          RemoveSequence(functionParameter);

                            Expression.Tokens.Insert(
                                index,
                                functionParameterToken);

                            i = index;
                        }
                        // gdy pojedyncze wyrażenie w fukncji
                        else
                        {
                            Int32 index = Expression.Tokens.
                                          IndexOfSequence(functionParameter);

                            i = index;
                        }
                    }

                    // dla operatora @ ustalenie liczby parametrów
                    if (token_prev != null &&
                        token_prev.TokenType == TokenType.OPERATOR &&
                        (OnpOnpTokenHelper.IsFunctionOperatorToken(token_prev)))
                    {
                        token_prev.TokenData = new OnpTokenData();
                        token_prev.TokenData.FunctionParametersCount = functionParameters.Count;
                    }
                }
                else
                {
                    // zamiana typu zmiennej na property_name jeśli nie jest to pierwsza zmienna
                    if (i > 0 && (token.TokenType == TokenType.VARIABLE || token.TokenType == TokenType.VALUE))
                    {
                        if (token_next == null || !OnpOnpTokenHelper.IsFunctionOperatorToken(token_next))
                        {
                            token.TokenType = TokenType.PROPERTY_NAME;
                        }
                    }
                    // usunięcie operatorów typu 'get property' ('.')

                    /*else if (OnpOnpTokenHelper.IsPropertyOperatorToken(token) )
                     * {
                     *  queueTokens.RemoveAt(i);
                     *  i--;
                     * }*/
                }
            }
        }