Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ParseResult ParseZeroOrMoreClause(
- IList<Token> tokens,
- Clause clause,
- int currentPosition) {
- var children = new List<Node>();
- var ok = true;
- while (ok) {
- // attempt to parse the clause
- var result = Parse(tokens, clause, currentPosition);
- if (!result.IsError) {
- // add the parsed results node to the list of children
- children.Add(result.Node);
- // Move the current position to the end of the parsed result
- currentPosition = result.EndingPosition;
- } else {
- // We were not able to parse another zeroOrMoreClause
- // we can stop and currentPosition will be the end position
- // of the last successfully parsed clause, if any
- ok = false;
- }
- }
- // there is never an error parsing in this function
- return new ParseResult {
- IsError = false,
- EndingPosition = currentPosition,
- Children = children
- };
- }
- // empty list
- list => listStart listEnd
- // list with elements
- list => listStart listElements listEnd
- // elements within a list
- listElements => value additionalListElement*
- // additional list elements
- additionalListElement => Seperator value
- [
- { Id: 1, Name: "John" },
- { Id: 2, Name: "Bobby" },
- { Id: 3, Name: George }
- ]
Add Comment
Please, Sign In to add comment