namespace JSDOC {
+ public enum ScopeParserMode {
+ BUILDING_SYMBOL_TREE,
+ PASS2_SYMBOL_TREE
+ }
+
+
public class ScopeParser : Object {
TokenStream ts;
string[] idents;
- //global : false,
- //mode : "", //"BUILDING_SYMBOL_TREE",
+ Scope global ;
+ ScopeParserMode mode;
//braceNesting : 0,
- //indexedScopes : false,
- //munge: true,
+ Gee.HashMap<int,Scope> indexedScopes;
+ bool munge = true;
public ScopeParser(TokenStream ts) {
this.ts = ts; // {TokenStream}
this.warnings = new Gee.ArrayList<string>();
+ this.globalScope = new Scope(-1, false, -1, '');
+ this.indexedScopes = new Gee.HashMap<int,Scope>();
+
//this.indexedg = {};
//this.timer = new Date() * 1;
this.idents = {
- buildSymbolTree : function()
+ void buildSymbolTree()
{
//println("<PRE>");
this.globalScope = new Scope(-1, false, -1, '');
- this.indexedScopes = { 0 : this.globalScope };
+ this.indexedScopes = new Gee.HashMap<int,Scope>();
+ this.indexedScopes.set(0, this.globalScope );
+
+ this.mode = ScopeParserMode.BUILDING_SYMBOL_TREE;
- this.mode = 'BUILDING_SYMBOL_TREE';
this.parseScope(this.globalScope);
//print("---------------END PASS 1 ---------------- ");
- },
- mungeSymboltree : function()
+ }
+
+ void mungeSymboltree()
{
if (!this.munge) {
this.ts.rewind();
this.braceNesting = 0;
- this.mode = 'PASS2_SYMBOL_TREE';
+ this.mode = ScopeParserMode.PASS2_SYMBOL_TREE;
//println("MUNGING?");
this.globalScope.munge();
- },
+ }
- log : function(str)
+ void log(string str)
{
- print (" ".substring(0, this.braceNesting*2) + str);
+ print(str);
+ //print (" ".substring(0, this.braceNesting*2) + str);
//println("<B>LOG:</B>" + htmlescape(str) + "<BR/>\n");
- },
- logR : function(str)
+ }
+ void logR (string str)
{
//println("<B>LOG:</B>" + str + "<BR/>");
- },
+ }
- parseScope : function(scope) // parse a token stream..
+ void parseScope(Scope scope) // parse a token stream..
{
//this.timerPrint("parseScope EnterScope");
//this.log(">>> ENTER SCOPE" + this.scopes.length);
- var symbol;
- var token;
-
- var identifier;
-
+
var expressionBraceNesting = this.braceNesting + 0;
var parensNesting = 0;
- var isObjectLitAr = [ false ];
- var isInObjectLitAr;
+ var isObjectLitAr = new Gee.ArrayList<bool>();
+ isObjectLitAr.add(false);
+
//var scopeIndent = '';
- token = this.ts.lookTok(1);
- while (token) {
+ var token = this.ts.lookTok(1);
+ while (token != null) {
// this.timerPrint("parseScope AFTER lookT: " + token.toString());
//this.dumpToken(token , this.scopes, this.braceNesting);
//print('SCOPE:' + token.toString());
token = this.ts.nextTok();
//!this.debug|| print( token.toString());
// print('SCOPE-VAR-VAL:' + JSON.stringify(token, null, 4));
- if (!token) { // can return false at EOF!
+ if (token == null) { // can return false at EOF!
break;
}
- if (token.name == "VAR" || token.data == ',') { // kludge..
+ if (token.name == "VAR" || token.data == ",") { // kludge..
continue;
}
//this.logR("parseScope GOT VAR : <B>" + token.toString() + "</B>");
if (token.type != "NAME") {
- for(var i = Math.max(this.ts.cursor-10,0); i < this.ts.cursor+1; i++) {
+
+ for(var i = Int.max(this.ts.cursor-10,0); i < this.ts.cursor+1; i++) {
print(this.ts.tokens[i].toString());
}
print( "var without ident");
- Seed.quit()
+ GLib.Process.exit (0);
}
- if (this.mode == "BUILDING_SYMBOL_TREE") {
- identifier = scope.getIdentifier(token.data,token) ;
+ if (this.mode == ScopeParserMode.BUILDING_SYMBOL_TREE) {
+ var identifier = scope.getIdentifier(token.data,token) ;
if (identifier == false) {
scope.declareIdentifier(token.data, token);
} else {
token.identifier = identifier;
- this.warn("(SCOPE) The variable " + token.data + ' (line:' + token.line + ") has already been declared in the same scope...");
+ this.warn("(SCOPE) The variable " + token.data + " (line:" + token.line + ") has already been declared in the same scope...");
}
}
token = this.ts.nextTok();
- !this.debug|| print(token.toString());
+ //!this.debug|| print(token.toString());
/*
assert token.getType() == Token.SEMI ||
token.getType() == Token.ASSIGN ||
} else {
//var bn = this.braceNesting;
var bn = this.braceNesting;
- var nts = [];
+ var nts = new Gee.ArrayList<Token>();
while (true) {
- if (!token || token.type == 'VOID' || token.data == ',') {
+ if (!token || token.type == "VOID" || token.data == ",") {
break;
}
- nts.push(token);
+ nts.add(token);
token = this.ts.nextTok();
}
- if (nts.length) {
+ if (nts.size > 0) {
var TS = this.ts;
this.ts = new TokenStream(nts);
this.parseExpression(scope);
token = this.ts.lookTok(1);
//!this.debug||
// print("AFTER EXP: " + token.toString());
- if (token.data == ';') {
+ if (token.data == ";") {
break;
}
}
//print('SCOPE-CURLY/PAREN:' + token.toString());
//println("<i>"+token.data+"</i>");
var curTS = this.ts;
- if (token.props) {
+ if (token.props.size() > 0) {
// { a : ... , c : .... }
+ var iter = token.props.map_iterator();
- for (var prop in token.props) {
+ while(iter.next()) {
+
+ TokenKeyMap val = iter.get_value(); // TokenKeyMap
// print('SCOPE-PROPS:' + JSON.stringify(token.props[prop],null,4));
- if (token.props[prop].val[0].data == 'function') {
+ if (val.vals.get(0).data == "function") {
// parse a function..
- this.ts = new TokenStream(token.props[prop].val);
+ this.ts = new TokenStream(val.vals);
this.ts.nextTok();
this.parseFunctionDeclaration(scope);
}
// key value..
- this.ts = new TokenStream(token.props[prop].val);
+ this.ts = new TokenStream(val.vals);
this.parseExpression(scope);
}
// ( ... ) or { .... } not object literals..
- var _this = this;
- for (var xx =0; xx < token.items.length; xx++) {
- expr = token.items[xx];
+
+ for (var xx =0; xx < token.items.size; xx++) {
+ expr = token.items.get(xx);
//token.items.forEach(function(expr) {
//print(expr.toString());
- _this.ts = new TokenStream(expr);
+ this.ts = new TokenStream(expr);
//if (curTS.data == '(') {
- _this.parseScope(scope)
+ this.parseScope(scope);
//} else {
// _this.parseExpression(scope)
//}