Ejemplo n.º 1
0
        // ----------------------- ReportParsedWords -------------------------------
        public static ParsedWordsReport ReportParsedWords(StmtWord TopWord)
        {
            ParsedWordsReport r1 = new ParsedWordsReport();

            StmtWordCursor c1 = new StmtWordCursor(TopWord);

            r1.AddTextLine(BuildLegend());

            // show the first 5 lines of the stmt text.
            {
                string s1 =
                    TopWord.StmtText.SubstringLenient(TopWord.BeginCursor.WordBx, 500);
                string[] lines =
                    s1.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                int cx = 0;
                int bx = 0;
                foreach (string s2 in lines)
                {
                    if (s2.IsNullOrEmpty() == false)
                    {
                        r1.AddTextLine(bx.ToString( ) + ") " + s2);

                        cx += 1;
                        if (cx > 5)
                        {
                            break;
                        }
                    }
                    bx += (s2.Length + Environment.NewLine.Length);
                }

                r1.AddSepLine();
            }

            StmtWord w1     = null;
            StmtWord pvWord = null;

            while (true)
            {
                pvWord = w1;

                c1 = c1.NextDeep();
                if (c1 == null)
                {
                    break;
                }
                w1 = c1.Node;

                if ((pvWord != null) && (pvWord.Depth != w1.Depth))
                {
                    r1.AddSepLine();
                }

                r1.AddTextLine(CursorToPresentationString(c1));
            }

            return(r1);
        }
Ejemplo n.º 2
0
        // -------------------------- CursorToPresentationString -----------------------
        static string CursorToPresentationString(StmtWordCursor Cursor)
        {
            StringBuilder sb = new StringBuilder();

            // the StmtWord the cursor is at.
            if ((Cursor.Position != RelativePosition.At) &&
                (Cursor.Position != RelativePosition.After))
            {
                throw new ApplicationException("Cursor must be positioned at a StmtWord");
            }
            StmtWord sw = Cursor.Node;

            sb.Append(sw.Depth.ToString() + " " + sw.CompositeCode.ToString());

            // the trailing edge of a composite word
            if (Cursor.Position == RelativePosition.After)
            {
                sb.Append(" TrailingEdge.");
            }

            // nbr of sub words
            if (sw.HasSubWords == true)
            {
                sb.Append(" " + "wCx:" + sw.SubWords.Count.ToString());
            }

            // the delimeter of the word is found in the EndCursor of the word.
            if ((sw.IsComposite == false) || (Cursor.Position == RelativePosition.After))
            {
                if (sw.EndCursor != null)
                {
                    sb.Append(" " + sw.EndCursor.ToDelimPresentationString());
                }
            }

            // word classification
            if ((sw.IsComposite == false) || (Cursor.Position == RelativePosition.At))
            {
                if (sw.WordCursor != null)
                {
                    sb.Append(" wc: " + sw.WordCursor.WordClassification.ToString());
                }
            }

            // the text of the word
            if ((sw.IsComposite == false) || (Cursor.CompositeNodeEdge == WhichEdge.LeadEdge))
            {
                string showText = null;
                if (sw.WordText.Length < 60)
                {
                    showText = sw.WordText;
                }
                else
                {
                    showText = sw.WordText.Substring(0, 60) + "...";
                }
                sb.Append(" wt: " + showText);
            }

            return(sb.ToString());
        }