Exemplo n.º 1
0
        /// <summary>
        /// Prepares the text adding marks at the end of each regular expression (Programming sentence)
        /// so they can be deleted easily after generating the report.-
        /// </summary>
        private void PreprocessText()
        {
            if (!_preprocessText)
            {
                return;
            }
            //Check to see if must work with RTF or plain text format.
            idFmt = TextFormat == ETextFormat.Text ? (IDocumentFormat) new TextFormat() : (IDocumentFormat) new RTFFormat();

            //Get Matches for any possible placeholder
            Regex           regex0        = CommonMethods.GetRegex(KeywordsRegExString);
            MatchCollection matchCollInit = regex0.Matches(_RTFText.ToString());

            //Replaces every 'new line' sequence with '\DEL' sequence.
            foreach (Match m in matchCollInit)
            {
                int i = RTFInput.ToString().IndexOf(idFmt.NewLine, m.Index);
                if (i >= 0)
                {
                    RTFInput = RTFInput.Remove(i, idFmt.NewLine.Length);
                    RTFInput = RTFInput.Insert(i, "\\DEL");
                }
            }
            RTFInput = RTFInput.Replace("\\DEL", "");
        }
Exemplo n.º 2
0
        private IControlBlock CloseControlBlock(IControlBlock closingNode /*, int matchIndex*/)
        {
            IControlBlock cb = closingNode;

            cb.MatchEnd           = RTFInput.Length;
            cb.CloseRegEx         = null;
            closingNode.End       = RTFInput.Length;
            closingNode.InnerText = RTFInput.ToString().InnerString(closingNode.Start, closingNode.End).Trim(); // TODO: CAMBIO RTFInput.ToString().InnerString(closingNode.Start, closingNode.End);

            closingNode = closingNode.Parent;
            return(closingNode);
        }
Exemplo n.º 3
0
        private IControlBlock CloseControlBlock(IControlBlock closingNode, Match match)
        {
            IControlBlock cb = (IControlBlock)closingNode;

            cb.MatchEnd           = match.Index + match.Length;
            cb.CloseRegEx         = match;
            closingNode.End       = match.Index;
            closingNode.InnerText = RTFInput.ToString().InnerString(closingNode.Start, closingNode.End).Trim(); // TODO: CAMBIO RTFInput.ToString().InnerString(closingNode.Start, closingNode.End);

            closingNode = closingNode.Parent;
            return(closingNode);
        }
Exemplo n.º 4
0
        private void GetControlBlocks()
        {
            bool fetchedTrailingText = false;

            //Locate and put an special mark on the "progamming sentences" so it's easier to find and delete them later.
            PreprocessText();

            Regex regex = CommonMethods.GetRegex(KeywordsRegExString);

            matchCollection = regex.Matches(RTFInput.ToString());
            #region Set up the document's root

            documentNode       = new TextBlock(true);
            documentNode.Start = 0;
            if (matchCollection.Count > 0)
            {
                documentNode.End = matchCollection[0].Index - 1;
            }
            else
            {
                documentNode.End = RTFInput.Length;
            }
            documentNode.InnerText      = RTFInput.ToString().InnerString(documentNode.Start, documentNode.End).Trim();
            documentNode.DocumentParser = this;
            IControlBlock currentNode = documentNode;

            #endregion

            int currRegex = 0;
            foreach (Match match in matchCollection)
            {
                #region Create the tree of control blocks
                switch (GetKeyWord(match))
                {
                case KeyWords.SCAN:
                {
                    //Closes the Texblok immediately before this SCAN
                    if (!currentNode.IsRoot)
                    {
                        currentNode = CloseControlBlock(currentNode, match);
                    }

                    IControlBlock scan = CreateScan(currentNode, match, false);

                    //Creates a new TextBlock as a child of this scan
                    currentNode = CreateTextBlock(match, scan);

                    break;
                }

                case KeyWords.SCAN_FOR:
                {
                    //Closes the Texblok immediately before this SCAN
                    if (!currentNode.IsRoot)
                    {
                        currentNode = CloseControlBlock(currentNode, match);
                    }

                    IControlBlock scan = CreateScan(currentNode, match, true);

                    currentNode = CreateTextBlock(match, scan);

                    break;
                }

                case KeyWords.IF:
                {
                    //Closes the Texblok immediately before this if
                    if (!currentNode.IsRoot)
                    {
                        currentNode = CloseControlBlock(currentNode, match);
                    }

                    IControlBlock ifBlock = new IfBlock(match, this);
                    ifBlock.OpenRegEx      = match;
                    ifBlock.MatchStart     = match.Index;
                    ifBlock.Start          = match.Index + match.Length;
                    ifBlock.DocumentParser = this;
                    ifBlock.Parent         = currentNode;
                    currentNode.Children.Add(ifBlock);

                    //Create a new TextBlock for the "true" part of the if
                    currentNode = CreateTextBlock(match, ifBlock);
                    break;
                }

                case KeyWords.ELSE:
                {
                    //Close the 'true' part of the if
                    currentNode = CloseControlBlock(currentNode, match);

                    // Create the 'Else' part
                    currentNode = CreateTextBlock(match, currentNode);
                    break;
                }

                case KeyWords.ENDIF:
                {
                    //Close the 'true' or the 'false' part of the if
                    currentNode = CloseControlBlock(currentNode, match);

                    //Close the embracing 'if' block
                    currentNode = CloseControlBlock(currentNode, match);

                    currentNode = CreateTextBlock(match, currentNode);
                    if (currRegex == matchCollection.Count - 1)         //There are no more regexes ahead
                    {
                        //It's the end of the document, close the textblock right here
                        currentNode         = CloseControlBlock(currentNode);
                        fetchedTrailingText = true;
                    }
                    break;
                }

                case KeyWords.ENDSCAN:
                {
                    if (currentNode is TextBlock)
                    {
                        currentNode = CloseControlBlock(currentNode, match);
                    }

                    currentNode = CloseControlBlock(currentNode, match);

                    currentNode = CreateTextBlock(match, currentNode);
                    if (currRegex == matchCollection.Count - 1)         //There are no more regexes ahead
                    {
                        //It's the end of the document, close the textblock right here
                        currentNode         = CloseControlBlock(currentNode);
                        fetchedTrailingText = true;
                    }

                    break;
                }
                }
                currRegex++;

                #endregion
            }

            Match startMatch = null;
            if (matchCollection.Count > 0 && !fetchedTrailingText)
            {
                startMatch = matchCollection[currRegex - 1];
                IControlBlock trailingText = CreateTextBlock(startMatch, currentNode);
                currentNode = CloseControlBlock(trailingText);
            }
        }