Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void parseLine(string line, ParsingContext context, IDocumentTemplate template)
- {
- bool anyTokenProcessed = false;
- // section token and option token should never be on the same line.
- // so at most one of following tokens can be encountered
- if (_tokenParser.TryParseSection(line, context.CurrentLineIndex, out SectionToken sectionToken))
- {
- context.AddSection(sectionToken);
- var lengthOfToken = sectionToken.StartIndex + sectionToken.Lenght;
- line = line.Substring(lengthOfToken);
- anyTokenProcessed = true;
- }
- else if (_tokenParser.TryParseOption(line, context.CurrentLineIndex, out OptionToken optionToken))
- {
- OptionParser.processOptionToken(context, template, optionToken);
- var lengthOfToken = optionToken.StartIndex + optionToken.Length;
- line = line.Substring(lengthOfToken);
- anyTokenProcessed = true;
- }
- // comment can be on the same line
- // since the parser is line oriented. This case must be handled separately
- if (_tokenParser.TryParseComment(line, context.CurrentLineIndex, out CommentToken commentToken))
- {
- context.AddComment(commentToken, anyTokenProcessed);
- line = "";
- }
- line = line.Trim();
- if (!string.IsNullOrEmpty(line))
- {
- throw new FormatException($"line #{context.CurrentLineIndex} contains " +
- $"text that could not be parsed \"{line}\" ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement