Guest User

Untitled

a guest
Jun 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. ParseResult ParseZeroOrMoreClause(
  2. IList<Token> tokens,
  3. Clause clause,
  4. int currentPosition) {
  5.  
  6. var children = new List<Node>();
  7. var ok = true;
  8. while (ok) {
  9.  
  10. // attempt to parse the clause
  11. var result = Parse(tokens, clause, currentPosition);
  12. if (!result.IsError) {
  13.  
  14. // add the parsed results node to the list of children
  15. children.Add(result.Node);
  16.  
  17. // Move the current position to the end of the parsed result
  18. currentPosition = result.EndingPosition;
  19. } else {
  20. // We were not able to parse another zeroOrMoreClause
  21. // we can stop and currentPosition will be the end position
  22. // of the last successfully parsed clause, if any
  23. ok = false;
  24. }
  25. }
  26.  
  27. // there is never an error parsing in this function
  28. return new ParseResult {
  29. IsError = false,
  30. EndingPosition = currentPosition,
  31. Children = children
  32. };
  33. }
  34.  
  35. // empty list
  36.  
  37. list => listStart listEnd
  38.  
  39. // list with elements
  40.  
  41. list => listStart listElements listEnd
  42.  
  43. // elements within a list
  44.  
  45. listElements => value additionalListElement*
  46.  
  47. // additional list elements
  48.  
  49. additionalListElement => Seperator value
  50.  
  51. [
  52. { Id: 1, Name: "John" },
  53. { Id: 2, Name: "Bobby" },
  54. { Id: 3, Name: George }
  55. ]
Add Comment
Please, Sign In to add comment