Esempio n. 1
0
        ////////////////////////////////////////////

        private CodeLines GetLines(IList <Char> Chars)
        {
            CodeLines outChars = new CodeLines();

            CodeLine currentLine = new CodeLine();

            outChars.Add(currentLine);
            Boolean wasCommentStart = false;

            for (Int32 i = 0; i <= Chars.Count; i++)
            {
                {
                    OnpOnpStringFindResult firstNext = StringHelper.FirstNextIndex(
                        Chars, i,
                        new[] { DynLanuageSymbols.NewLineChars, DynLanuageSymbols.DepthBegin, DynLanuageSymbols.DepthEnd },
                        false);

                    // gdy nie znalazł znaku nowej linii
                    if (firstNext == null || firstNext.Index < 0)
                    {
                        OnpOnpStringFindResult commentStartNext = StringHelper.FirstNextIndex(
                            Chars, i,
                            new[] { DynLanuageSymbols.Comment1StartSymbol },
                            false);

                        if (commentStartNext == null || commentStartNext.Index < 0)
                        {
                            for (var j = i; j < Chars.Count; j++)
                            {
                                var ch = Chars[j];
#if !SPACES_FOR_DEPTH
                                if (currentLine.Count > 0 || !Char.IsWhiteSpace(ch))
#endif
                                currentLine.Add(ch);
                            }
                        }
                        else
                        {
                            for (var j = i; j < commentStartNext.Index; j++)
                            {
                                var ch = Chars[j];
#if !SPACES_FOR_DEPTH
                                if (currentLine.Count > 0 || !Char.IsWhiteSpace(ch))
#endif
                                currentLine.Add(ch);
                            }
                            wasCommentStart = true;
                        }
                        break;
                    }
                    // gdy znalazł znak nowej linii
                    else
                    {
#if !NET20
                        if (DynLanuageSymbols.NewLineChars.Contains(firstNext.Chars) ||
                            DynLanuageSymbols.DepthBegin.Contains(firstNext.Chars) ||
                            DynLanuageSymbols.DepthEnd.Contains(firstNext.Chars))
#else
                        if (Linq2.Contains(DynLanuageSymbols.NewLineChars, firstNext.Chars) ||
                            Linq2.Contains(DynLanuageSymbols.DepthBegin, firstNext.Chars) ||
                            Linq2.Contains(DynLanuageSymbols.DepthEnd, firstNext.Chars))
#endif
                        {
                            OnpOnpStringFindResult commentStartNext = StringHelper.FirstNextIndex(
                                Chars, i, firstNext.Index,
                                new[] { DynLanuageSymbols.Comment1StartSymbol },
                                false);

                            if (commentStartNext == null || commentStartNext.Index < 0)
                            {
                                for (var j = i; j < firstNext.Index; j++)
                                {
                                    var ch = Chars[j];
#if !SPACES_FOR_DEPTH
                                    if (currentLine.Count > 0 || !Char.IsWhiteSpace(ch))
#endif
                                    currentLine.Add(ch);
                                }
                            }
                            else
                            {
                                for (var j = i; j < commentStartNext.Index; j++)
                                {
                                    var ch = Chars[j];
#if !SPACES_FOR_DEPTH
                                    if (currentLine.Count > 0 || !Char.IsWhiteSpace(ch))
#endif
                                    currentLine.Add(ch);
                                }
                                wasCommentStart = true;
                            }
#if !NET20
                            if (DynLanuageSymbols.DepthBegin.Contains(firstNext.Chars) ||
                                DynLanuageSymbols.DepthEnd.Contains(firstNext.Chars))
#else
                            if (Linq2.Contains(DynLanuageSymbols.DepthBegin, firstNext.Chars) ||
                                Linq2.Contains(DynLanuageSymbols.DepthEnd, firstNext.Chars))
#endif
                            {
                                if (currentLine.Count > 0)
                                {
                                    currentLine = new CodeLine();
                                    outChars.Add(currentLine);
                                }
                                currentLine.AddRange(firstNext.Chars);
                            }

                            i = firstNext.Index + firstNext.Chars.Length - 1;

                            currentLine = new CodeLine();
                            outChars.Add(currentLine);
                            wasCommentStart = false;
                        }
                    }
                }
            }

            return(outChars);
        }
Esempio n. 2
0
        ////////////////////////////////////////////

        private CodeLines GetLines(IList <Char> Chars)
        {
            CodeLines outChars = new CodeLines();

            CodeLine currentLine = new CodeLine();

            outChars.Add(currentLine);
            Boolean wasCommentStart = false;

            for (Int32 i = 0; i <= Chars.Count; i++)
            {
                OnpOnpStringFindResult firstNext = StringHelper.FirstNextIndex(
                    Chars, i,
                    new[] { PainLanguageSymbols.NewLineChars },
                    false);

                if (firstNext == null || firstNext.Index < 0)
                {
                    for (var j = i; j < Chars.Count; j++)
                    {
                        var ch = Chars[j];

                        if (ch == PainLanguageSymbols.CommentStartSymbol[0][0])
                        {
                            wasCommentStart = true;
                        }

                        if (!wasCommentStart)
                        {
                            currentLine.Add(ch);
                        }
                    }
                    break;
                }
                else
                {
                    if (PainLanguageSymbols.NewLineChars.Contains(firstNext.Chars))
                    {
                        for (var j = i; j < firstNext.Index; j++)
                        {
                            var ch = Chars[j];

                            if (ch == PainLanguageSymbols.CommentStartSymbol[0][0])
                            {
                                wasCommentStart = true;
                            }

                            if (!wasCommentStart)
                            {
                                currentLine.Add(ch);
                            }
                        }

                        i = firstNext.Index + firstNext.Chars.Length - 1;

                        currentLine = new CodeLine();
                        outChars.Add(currentLine);
                        wasCommentStart = false;
                    }
                }
            }

            return(outChars);
        }