Inheritance: IMarkdownParsingContext
Ejemplo n.º 1
0
        private List <IMarkdownToken> TokenizeCore(SourceInfo sourceInfo)
        {
            var pc     = new MarkdownParsingContext(sourceInfo);
            var tokens = new List <IMarkdownToken>();

            while (pc.CurrentMarkdown.Length > 0)
            {
                var token = ApplyRules(pc);
                if (token == null)
                {
                    throw new MarkdownParsingException("Cannot parse markdown: No rule match.", pc.ToSourceInfo());
                }
                tokens.Add(token);
            }
            return(tokens);
        }
Ejemplo n.º 2
0
        private List <IMarkdownToken> TokenizeCore(SourceInfo sourceInfo)
        {
            var pc     = new MarkdownParsingContext(sourceInfo);
            var tokens = new List <IMarkdownToken>();

            while (pc.CurrentMarkdown.Length > 0)
            {
                var token = (from r in Context.Rules
                             select r.TryMatch(this, pc)).FirstOrDefault(t => t != null);
                if (token == null)
                {
                    throw new InvalidOperationException($"Cannot parse markdown for file {sourceInfo.File}, line {pc.LineNumber}.");
                }
                tokens.Add(token);
            }
            return(tokens);
        }
Ejemplo n.º 3
0
 private IMarkdownToken ApplyRules(MarkdownParsingContext pc)
 {
     foreach (var r in Context.Rules)
     {
         try
         {
             var token = r.TryMatch(this, pc);
             if (token != null)
             {
                 return(token);
             }
         }
         catch (Exception ex)
         {
             throw new MarkdownParsingException($"Cannot parse markdown: Rule {r.Name} is fault.", pc.ToSourceInfo(), ex);
         }
     }
     return(null);
 }
Ejemplo n.º 4
0
 private IMarkdownToken ApplyRules(MarkdownParsingContext pc)
 {
     foreach (var r in Context.Rules)
     {
         try
         {
             var token = r.TryMatch(this, pc);
             if (token != null)
             {
                 return token;
             }
         }
         catch (Exception ex)
         {
             throw new MarkdownParsingException($"Cannot parse markdown: Rule {r.Name} is fault.", pc.ToSourceInfo(), ex);
         }
     }
     return null;
 }
Ejemplo n.º 5
0
 private List<IMarkdownToken> TokenizeCore(SourceInfo sourceInfo)
 {
     var pc = new MarkdownParsingContext(sourceInfo);
     var tokens = new List<IMarkdownToken>();
     while (pc.CurrentMarkdown.Length > 0)
     {
         var token = ApplyRules(pc);
         if (token == null)
         {
             throw new MarkdownParsingException("Cannot parse markdown: No rule match.", pc.ToSourceInfo());
         }
         else if (token.Rule is MarkdownTextBlockRule)
         {
             pc.IsInParagraph = true;
         }
         else
         {
             pc.IsInParagraph = false;
         }
         tokens.Add(token);
     }
     return tokens;
 }