- else return got;
- },
- // what about comments after 'function'...
- // is this used ???
- nextTok : function() {
- return this.nextNonSpace();
- },
- nextNonSpace : function ()
- {
-
- while (true) {
- tok = this.next(1);
- if (!tok) {
- return false;
- }
- if (tok.is('WHIT') || tok.is('COMM')) {
- continue;
- }
- return tok;
+ got.add(this.tokens.get(this.cursor+i));
+ }
+ this.cursor += howMany;
+
+ return got;
+ }
+
+
+
+
+ // what about comments after 'function'...
+ // is this used ???
+ public Token? nextTok() {
+ return this.nextNonSpace();
+ }
+
+ public Token? nextNonSpace ()
+ {
+
+ while (true) {
+ var tok = this.next();
+ if (tok == null) {
+ return null;
+ }
+ if (tok.is("WHIT") || tok.is("COMM")) {
+ continue;
+ }
+ return tok;
+ }
+ }
+
+ /**
+ * balance
+ * -- returns all the tokens betweeen and including stop token eg.. from {... to }
+ * @param start {String} token name or data (eg. '{'
+ * @param stop {String} (Optional) token name or data (eg. '}'
+ */
+ public Gee.ArrayList<Token> balance (string start, string in_stop = "") throws TokenStreamError
+ {
+
+ // accepts names or "{" etc..
+ var stop = in_stop;
+ start = Lang.punc(start) == null ? start : Lang.punc(start);
+
+ if (stop=="") {
+ var newstop = Lang.matching(start);
+ stop = newstop;
+ }
+ if (stop == null) {
+ throw new TokenStreamError.ArgumentError("balance called with invalid start/stop : %s",start);
+ }
+ debug("START=%s, STOP=%s \n", start,stop);
+ var depth = 0;
+ var got = new Gee.ArrayList<Token>();
+ var started = false;
+ //Seed.print("START:" + start);
+ //Seed.print("STOP:" + stop);
+ Token token;
+
+ while (null != (token = this.look(1,false))) {
+ debug("BALANCE: " + token.asString());
+ if (token.is(start)) {
+ // Seed.print("balance: START : " + depth + " " + token.data);
+ depth++;
+ started = true;