public static Section ParseToDom(TextReader reader)
        {
            LineClassifier classifier = new LineClassifier(reader);
            Parser parser = new Parser(classifier);

            return parser.Parse();
        }
        public void Parse(TextReader reader)
        {
            if (_topSection != null)
            {
                throw new InvalidOperationException(AdornedTextStrings.AdornedProcessorAlreadyParsed);
            }

            LineClassifier classifier = new LineClassifier(reader);
            Parser parser = new Parser(classifier);

            try
            {
                _topSection = parser.Parse();
            }
            catch (AdornedTextParsingException ex)
            {
                _topSection = GenerateErrorDocument(ex, classifier);
            }
        }
        static Section GenerateErrorDocument(Exception ex, LineClassifier classifier)
        {
            ParseErrorSection topSection = new ParseErrorSection();

            Paragraph paragraph = new Paragraph(new FormattedSpan(FormattedSpanKind.Bold, new TextSpan("I can haz fixed?")));
            topSection.Blocks.Add(paragraph);

            LineClassifierContext context = classifier.GetContext();

            List<string> lines = new List<string>();

            foreach (Pair<int, string> pair in context.AllLines)
            {
                lines.Add(string.Format("{0} {1}: {2}",
                    pair.First == context.CurrentLine.First ? ">" : " ",
                    pair.First.ToString().PadLeft(4, ' '),
                    pair.Second));
            }

            VerbatimBlock linesBlock = new VerbatimBlock();
            linesBlock.Lines.AddRange(lines);

            topSection.Blocks.Add(linesBlock);

            return topSection;
        }
Example #4
0
 public Parser(LineClassifier classifier)
 {
     _classifier = classifier;
 }