Esempio n. 1
0
            /// <summary>
            /// Search for the index of the beginning of the terminator.
            /// </summary>
            /// <returns>Index of the beginning of the terminator. OR -1 if no such terminator is found.</returns>
            public int Search(string str, int startIndex, IWikitextParserLogger logger)
            {
                logger?.NotifyRegexMatchingStarted(startIndex, searcher);
                var match = searcher.Match(str, startIndex);

                logger?.NotifyRegexMatchingFinished(startIndex, searcher);
                return(match.Success ? match.Index : -1);
            }
Esempio n. 2
0
 public int FindTerminator(string str, int startIndex, IWikitextParserLogger logger)
 {
     Debug.Assert(str != null);
     if (Terminator == null)
     {
         return(-1);
     }
     return(Terminator.Search(str, startIndex, logger));
 }
Esempio n. 3
0
 public Wikitext Parse(WikitextParserOptions options, IWikitextParserLogger logger, string wikitext,
                       CancellationToken cancellationToken)
 {
     if (wikitext == null)
     {
         throw new ArgumentNullException(nameof(wikitext));
     }
     cancellationToken.ThrowIfCancellationRequested();
     // Initialize
     this.options           = options?.DefensiveCopy() ?? WikitextParserOptions.DefaultOptionsCopy;
     this.logger            = logger;
     fulltext               = wikitext;
     lineNumber             = linePosition = 0;
     position               = 0;
     contextStack           = new Stack <ParsingContext>();
     this.cancellationToken = cancellationToken;
     try
     {
         // Then parse
         logger?.NotifyParsingStarted(wikitext);
         var root = ParseWikitext();
         // State check
         if (position < fulltext.Length)
         {
             throw new InvalidParserStateException(
                       "Detected unparsed wikitext after parsing. There might be a bug with parser.");
         }
         if (contextStack.Count > 0)
         {
             throw new InvalidParserStateException(
                       "Detected remaining ParsingContext on context stack. There might be a bug with parser.");
         }
         logger?.NotifyParsingFinished();
         return(root);
     }
     finally
     {
         // Cleanup
         fulltext     = null;
         contextStack = null;
         options      = null;
         logger       = null;
     }
 }