Exemplo n.º 1
0
        private static void Parse(string wikiContent, IMacro macro, CompiledMacro compiledMacro,
                                  IScopeAugmenter augmenter, Action <IList <Scope> > parseHandler)
        {
            Match regexMatch = compiledMacro.Regex.Match(wikiContent);

            if (!regexMatch.Success)
            {
                return;
            }

            IList <Scope> capturedScopes = new List <Scope>();

            while (regexMatch.Success)
            {
                string matchedContent = wikiContent.Substring(regexMatch.Index, regexMatch.Length);
                if (!string.IsNullOrEmpty(matchedContent))
                {
                    capturedScopes = GetCapturedMatches(regexMatch, compiledMacro, capturedScopes, compiledMacro.Regex);
                }

                regexMatch = regexMatch.NextMatch();
            }

            if (augmenter != null && capturedScopes.Count > 0)
            {
                capturedScopes = augmenter.Augment(macro, capturedScopes, wikiContent);
            }

            if (capturedScopes.Count > 0)
            {
                parseHandler(capturedScopes);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Registers a new <see cref="IScopeAugmenter"/> that is paired with a <see cref="IMacro"/>.
        /// </summary>
        /// <typeparam name="TMacro">The <see cref="IMacro"/> type the <see cref="IScopeAugmenter"/> is paired with. Must have a parameterless constructor.</typeparam>
        /// <param name="augmenter">The scope augmenter to register.</param>
        /// <remarks>This augmenter needs to be thread safe.</remarks>
        /// <exception cref="System.ArgumentNullException">Thrown when the augmenter is null.</exception>
        public static void Register <TMacro>(IScopeAugmenter augmenter)
            where TMacro : class, IMacro, new()
        {
            Guard.NotNull(augmenter, "augmenter");

            augmenterLock.EnterWriteLock();
            try
            {
                loadedAugmenters[(new TMacro()).Id] = augmenter;
            }
            finally
            {
                augmenterLock.ExitWriteLock();
            }
        }
Exemplo n.º 3
0
        private static void Parse(string wikiContent, IMacro macro, CompiledMacro compiledMacro,
                                  IScopeAugmenter augmenter, Action<IList<Scope>> parseHandler)
        {
            Match regexMatch = compiledMacro.Regex.Match(wikiContent);
            if (!regexMatch.Success)
                return;

            IList<Scope> capturedScopes = new List<Scope>();

            while (regexMatch.Success)
            {
                string matchedContent = wikiContent.Substring(regexMatch.Index, regexMatch.Length);
                if (!string.IsNullOrEmpty(matchedContent))
                    capturedScopes = GetCapturedMatches(regexMatch, compiledMacro, capturedScopes, compiledMacro.Regex);

                regexMatch = regexMatch.NextMatch();
            }

            if (augmenter != null && capturedScopes.Count > 0)
                capturedScopes = augmenter.Augment(macro, capturedScopes, wikiContent);

            if (capturedScopes.Count > 0)
                parseHandler(capturedScopes);
        }