- getMatchingToken : function(/**String*/start, /**String*/stop) {
- var depth = 0;
- var cursor = this.cursor;
-
- if (!start) {
- start = Lang.matching(stop);
- depth = 1;
- }
- if (!stop) stop = Lang.matching(start);
-
- while ((token = this.tokens[cursor])) {
- if (token.is(start)) {
- depth++;
- }
-
- if (token.is(stop) && cursor) {
- depth--;
- if (depth == 0) return this.tokens[cursor];
- }
- cursor++;
- }
- return false;
- },
+ for (var i = 1; i <= howMany; i++) {
+ if (this.cursor+i >= this.tokens.size) {
+ return null;
+ }
+ 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;
+ }
+
+ if (started) {
+ got.add(token);
+ }
+
+ if (token.is(stop)) {
+ depth--;
+ // Seed.print("balance: STOP: " + depth + " " + token.data);
+ if (depth < 1) {
+ return got;
+ }
+ }
+ if (null == this.next()) {
+ break;
+ }
+ }
+ return new Gee.ArrayList<Token>();
+ }