// Read a JKLSequence, checking that it starts and terminates correctly. // Named read_list to follow the ref, but has been genericized to handle vectors as well. static public JKLSeqBase read_list(TokenQueue TQ, JKLSeqBase sequence, char start, char end) { // Check that we are in fact at the start of a list. string token = TQ.Next(); if (token[0] != start) { // Parse error - probably internal if the list code is correct. throw new JKLInternalError("Sequence expected '" + start + "' but got: " + token); } // Use read_form to get the list's contents, accumulating them into the list. while (true) { token = TQ.Peek(); if (token != null) { // We are in the list or at the end. if (token[0] == end) { // Reached valid end of list. Consume the end char. TQ.Next(); // And we are done. break; } // Mutually recurse to read the next list element. JKLVal newVal = read_form(TQ); sequence.Add(newVal); } else { // The input has finished but the list hasn't. Try to get more input. TQ.LoadMoreTokens(start, end); } } return(sequence); }