Advertisement
Guest User

Untitled

a guest
May 20th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. private void parseLine(string line, ParsingContext context, IDocumentTemplate template)
  2. {
  3. bool anyTokenProcessed = false;
  4.  
  5. // section token and option token should never be on the same line.
  6. // so at most one of following tokens can be encountered
  7. if (_tokenParser.TryParseSection(line, context.CurrentLineIndex, out SectionToken sectionToken))
  8. {
  9. context.AddSection(sectionToken);
  10. var lengthOfToken = sectionToken.StartIndex + sectionToken.Lenght;
  11. line = line.Substring(lengthOfToken);
  12. anyTokenProcessed = true;
  13. }
  14.  
  15. else if (_tokenParser.TryParseOption(line, context.CurrentLineIndex, out OptionToken optionToken))
  16. {
  17. OptionParser.processOptionToken(context, template, optionToken);
  18.  
  19. var lengthOfToken = optionToken.StartIndex + optionToken.Length;
  20. line = line.Substring(lengthOfToken);
  21. anyTokenProcessed = true;
  22. }
  23.  
  24. // comment can be on the same line
  25. // since the parser is line oriented. This case must be handled separately
  26. if (_tokenParser.TryParseComment(line, context.CurrentLineIndex, out CommentToken commentToken))
  27. {
  28. context.AddComment(commentToken, anyTokenProcessed);
  29. line = "";
  30. }
  31.  
  32. line = line.Trim();
  33. if (!string.IsNullOrEmpty(line))
  34. {
  35. throw new FormatException($"line #{context.CurrentLineIndex} contains " +
  36. $"text that could not be parsed \"{line}\" ");
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement