Example #1
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());
            }
        }
Example #2
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);
        }
Example #3
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--;
                     * }*/
                }
            }
        }
Example #4
0
        /*public DynLanCodeLine GetCodeLine(Int32 Depth, CodeLine line, CodeLine nextLine)
         * {
         *  return SetCodeLine(null, Depth, line, nextLine);
         * }*/

        /*public DynLanCodeLine SetCodeLine(DynLanCodeLine compiledLine, Int32 Depth, String line)
         * {
         *  return SetCodeLine(compiledLine, Depth, new CodeLine(line));
         * }*/

        public DynLanCodeLine SetCodeLine(DynLanCodeLine compiledLine, CodeLine line, CodeLine nextLine, ref Int32 Depth, ref int CharIndex)
        {
            Int32 orgDepth = Depth;

            IList <Char> lineTrimmed = Linq2.ToArray(
                StringHelper.TrimStart(
                    StringHelper.TrimEnd(line)));

            IList <Char>  lineBody     = line;
            EOperatorType operatorType = EOperatorType.NONE;

            // IF: wykrycie definicji IF'a
            if (//lineTrimmed.Count > str_if.Length &&
                StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_if, true, true) /* &&
                                                                                                                 * Char.IsWhiteSpace(lineTrimmed[str_if.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.IF;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_if.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#else
                if (lineBody.Count == 0)
                {
                    throw new Exception("IF body cannot be empty !");
                }
                if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin))
                {
                    throw new Exception("IF body should begin with bracket { !");
                }
                else
                {
                    Depth++; CharIndex++;
                }
#endif
            }
            // WHILE: wykrycie definicji WHILE'a
            else if (//lineTrimmed.Count > str_while.Length &&
                StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_while, true, true) /*&&
                                                                                                                    * Char.IsWhiteSpace(lineTrimmed[str_while.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.WHILE;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_while.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#else
                if (lineBody.Count == 0)
                {
                    throw new Exception("WHILE body cannot be empty !");
                }
                if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin))
                {
                    throw new Exception("WHILE body should begin with bracket { !");
                }
                else
                {
                    Depth++; CharIndex++;
                }
#endif
            }
            // ELSE: wykrycie definicji ELSE'a
            else if (// lineTrimmed.Count >= str_else.Length &&
                StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_else, true, true))
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.ELSE;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_else.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#else
                if (lineBody.Count > 0)
                {
                    throw new Exception("ELSE body must be empty !");
                }
                if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin))
                {
                    throw new Exception("ELSE body should begin with bracket { !");
                }
                else
                {
                    Depth++; CharIndex++;
                }
#endif
            }
            // ELIF: wykrycie definicji ELIF'a
            else if (// lineTrimmed.Count > str_elif.Length &&
                StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_elif, true, true) /*&&
                                                                                                                   * Char.IsWhiteSpace(lineTrimmed[str_elif.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.ELIF;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_elif.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#else
                if (lineBody.Count == 0)
                {
                    throw new Exception("ELIF body cannot be empty !");
                }
                if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin))
                {
                    throw new Exception("ELIF body should begin with bracket { !");
                }
                else
                {
                    Depth++; CharIndex++;
                }
#endif
            }
            // RETURN: wykrycie definicji RETURN'a
            else if (// lineTrimmed.Count > str_return.Length &&
                StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_return, true, true) /*&&
                                                                                                                     * Char.IsWhiteSpace(lineTrimmed[str_return.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.RETURN;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_return.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#endif
            }
            // RETURN: wykrycie definicji RETURN'a

            /*else if (// lineTrimmed.Count >= str_return.Length &&
             *         StringHelper.StartsWith(lineTrimmed.TrimStart().ToArray(), str_return, true, true))
             * {
             *  Int32 depth = GetDepth(line);
             *  operatorType = EOperatorType.RETURN;
             *
             *  lineBody = lineTrimmed.
             *      Substring2(str_return.Length).
             *      TrimStart().
             *      ToList();
             *
             #if SPACES_FOR_DEPTH
             *  for (int i = 0; i < depth; i++)
             *      lineBody.Insert(0, ' ');
             *  // lineBody.TrimEnd(':');
             #endif
             * }*/
            // RETURN: wykrycie definicji PASS'a
            else if (//(lineTrimmed.Count == str_pass.Length || (lineTrimmed.Count > str_pass.Length && Char.IsWhiteSpace(lineTrimmed[str_pass.Length])))
                StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_pass, true, true))
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.PASS;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_pass.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#endif
            }
            // TRY: wykrycie definicji TRY'a
            else if (// lineTrimmed.Count > str_try.Length &&
                StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_try, true, true) /*&&
                                                                                                                  * Char.IsWhiteSpace(lineTrimmed[str_try.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.TRY;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_try.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#else
                if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin))
                {
                    throw new Exception("TRY body should begin with bracket { !");
                }
                else
                {
                    Depth++; CharIndex++;
                }
#endif
            }
            // CATCH: wykrycie definicji CATCH'a
            else if (// lineTrimmed.Count > str_catch.Length &&
                StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_catch, true, true) /*&&
                                                                                                                    * Char.IsWhiteSpace(lineTrimmed[str_catch.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.CATCH;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_catch.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#else
                if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin))
                {
                    throw new Exception("CATCH body should begin with bracket { !");
                }
                else
                {
                    Depth++; CharIndex++;
                }
#endif
            }
            // FINALLY: wykrycie definicji FINALLY'a
            else if (// lineTrimmed.Count > str_finally.Length &&
                StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_finally, true, true) /*&&
                                                                                                                      * Char.IsWhiteSpace(lineTrimmed[str_finally.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.FINALLY;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_finally.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#else
                if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin))
                {
                    throw new Exception("FINALLY body should begin with bracket { !");
                }
                else
                {
                    Depth++; CharIndex++;
                }
#endif
            }
            // THROW: wykrycie definicji THROW'a
            else if (lineTrimmed.Count > str_throw.Length &&
                     StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_throw, true, true) /*&&
                                                                                                                         * Char.IsWhiteSpace(lineTrimmed[str_THROW.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.THROW;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_throw.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#endif
            }
            // BREAK: wykrycie definicji BREAK'a
            else if (// lineTrimmed.Count > str_break.Length &&
                StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_break, true, true) /*&&
                                                                                                                    * Char.IsWhiteSpace(lineTrimmed[str_break.Length])*/)
            {
                Int32 depth = GetDepth(line);
                operatorType = EOperatorType.BREAK;

                lineBody = Linq2.ToList(
                    StringHelper.TrimStart(
                        StringHelper.Substring2(lineTrimmed, str_break.Length)));

#if SPACES_FOR_DEPTH
                for (int i = 0; i < depth; i++)
                {
                    lineBody.Insert(0, ' ');
                }
                // lineBody.TrimEnd(':');
#endif
            }

            ExpressionGroup expressionGroup = TokenizerInvariant.I.
                                              Compile(lineBody);

            if (compiledLine == null)
            {
                compiledLine = new DynLanCodeLine();
            }

            compiledLine.Code            = StringHelper.ToString2(line);
            compiledLine.ExpressionGroup = expressionGroup;
            compiledLine.OperatorType    = operatorType;
            compiledLine.IsLineEmpty     = lineTrimmed.Count == 0;

#if !SPACES_FOR_DEPTH
            compiledLine.Depth = orgDepth;
#else
            compiledLine.Depth += GetDepth(lineBody);
#endif

            return(compiledLine);
        }