Ejemplo n.º 1
0
        public static OnpOnpStringFindResult FirstNextIndex(
            IList <Char> Source,
            Int32 StartIndex,
            IList <Char[][]> ItemsToFind,
            Boolean Insensitive,
            Char StringChar = '\'')
        {
            if (ItemsToFind == null || ItemsToFind.Count == 0)
            {
                return(null);
            }

            OnpOnpStringFindResult minResult = null;

            foreach (Char[][] items in ItemsToFind)
            {
                OnpOnpStringFindResult findResult = NextIndex(Source, items, StringChar, StartIndex, Insensitive);
                if (findResult != null)
                {
                    if (minResult == null || findResult.Index < minResult.Index)
                    {
                        minResult = findResult;
                    }
                }
            }

            return(minResult);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Zwraca kolejny token
        /// </summary>
        public static ExpressionToken GetNextToken(IList <Char> Chars, Int32 StartIndex, ExpressionToken PrevToken)
        {
            // szukanie operatórw porównania
            Char[] foundCompareOperator = StringHelper.StrEquals(Chars, PainLanguageSymbols.CompareOperators, StartIndex, false);
            if (foundCompareOperator != null)
            {
                return(new ExpressionToken(foundCompareOperator, TokenType.OPERATOR));
            }

            // szukanie nawiasu START
            Char[] foundBracketBegin = StringHelper.StrEquals(Chars, PainLanguageSymbols.BracketBegin, StartIndex, false);
            if (foundBracketBegin != null)
            {
                return(new ExpressionToken(foundBracketBegin, TokenType.BRACKET_BEGIN));
            }

            // szukanie nawiasu END
            Char[] foundBracketEnd = StringHelper.StrEquals(Chars, PainLanguageSymbols.BracketEnd, StartIndex, false);
            if (foundBracketEnd != null)
            {
                return(new ExpressionToken(foundBracketEnd, TokenType.BRACKET_END));
            }

            // szukanie indexera START
            Char[] foundIndexerBegin = StringHelper.StrEquals(Chars, PainLanguageSymbols.IndexerBegin, StartIndex, false);
            if (foundIndexerBegin != null)
            {
                return(new ExpressionToken(foundIndexerBegin, TokenType.INDEXER_BEGIN));
            }

            // szukanie indexera END
            Char[] foundIndexerEnd = StringHelper.StrEquals(Chars, PainLanguageSymbols.IndexerEnd, StartIndex, false);
            if (foundIndexerEnd != null)
            {
                return(new ExpressionToken(foundIndexerEnd, TokenType.INDEXER_END));
            }

            // szukanie operatora równości
            Char[] foundEqualOperator = StringHelper.StrEquals(Chars, PainLanguageSymbols.EqualOperator, StartIndex, false);
            if (foundEqualOperator != null)
            {
                return(new ExpressionToken(foundEqualOperator, TokenType.EQUAL_OPERATOR));
            }

            // szukanie operatora
            Char[] foundOperator = StringHelper.StrEquals(Chars, PainLanguageSymbols.Operators, StartIndex, false);
            if (foundOperator != null)
            {
                return(new ExpressionToken(foundOperator, TokenType.OPERATOR));
            }

            // szukanie operatorów logicznych
            Char[] foundLogicalOperator = StringHelper.StrEquals(Chars, PainLanguageSymbols.LogicalOperators, StartIndex, true);
            if (foundLogicalOperator != null)
            {
                Char?prevChar = StartIndex > 0 ? (Char?)Chars[StartIndex - 1] : null;
                Char?nextChar = StartIndex + foundLogicalOperator.Length < Chars.Count ? (Char?)Chars[StartIndex + foundLogicalOperator.Length] : null;

                if (!(prevChar != null && Char.IsLetterOrDigit(prevChar.Value) && Char.IsLetterOrDigit(foundLogicalOperator[0])) &&
                    !(nextChar != null && Char.IsLetterOrDigit(nextChar.Value) && Char.IsLetterOrDigit(foundLogicalOperator[foundLogicalOperator.Length - 1])))
                {
                    return(new ExpressionToken(foundLogicalOperator, TokenType.OPERATOR));
                }
                else
                {
                    prevChar = prevChar;
                }
            }

            // szukanie białych znaków
            Char[] foundWhitespaces = StringHelper.StrEquals(Chars, PainLanguageSymbols.Whitespaces, StartIndex, false);
            if (foundWhitespaces != null)
            {
                return(new ExpressionToken(foundWhitespaces, TokenType.WHITESPACE));
            }

            // szukanie przecinka
            Char[] foundSeparator = StringHelper.StrEquals(Chars, PainLanguageSymbols.Separators, StartIndex, false);
            if (foundSeparator != null)
            {
                return(new ExpressionToken(foundSeparator, TokenType.SEPARATOR));
            }

            TokenType   tokenType = TokenType.VARIABLE;
            Int32       nextIndex = -1;
            List <Char> chars     = new List <Char>();

            OnpOnpStringFindResult firstNext = StringHelper.FirstNextIndex(
                Chars, StartIndex,
                new[] { PainLanguageSymbols.IndexerBegin, PainLanguageSymbols.IndexerEnd, PainLanguageSymbols.BracketBegin, PainLanguageSymbols.BracketEnd, PainLanguageSymbols.OperatorsAndPropertyAndBrackets, PainLanguageSymbols.Separators },
                true);

            if (firstNext == null || firstNext.Index < 0)
            {
                for (Int32 j = StartIndex; j < Chars.Count; j++)
                {
                    chars.Add(Chars[j]);
                }
            }
            else
            {
                int len = firstNext.Index;
                for (Int32 j = StartIndex; j < len; j++)
                {
                    chars.Add(Chars[j]);
                }
                nextIndex = firstNext.Index;
            }
            if (nextIndex < 0)
            {
                nextIndex = Chars.Count;
            }

            chars.Trim();

            if (chars.Count != 0)
            {
                if (StringHelper.IsValue(chars))
                {
                    tokenType = TokenType.VALUE;
                }

                //if (tokenType == TokenType.VARIABLE)
                //    for (var i = 0; i < chars.Count; i++)
                //        chars[i] = Char.ToUpper(chars[i]);

                return
                    (new ExpressionToken(chars, tokenType)
                {
                    TokenLength = (nextIndex - StartIndex)
                });
            }

            return(null);
        }