if (this.mode == ScopeParserMode.BUILDING_SYMBOL_TREE) {
var identifier = scope.getIdentifier(token.data,token) ;
- if (identifier == false) {
+ if (identifier == null) {
scope.declareIdentifier(token.data, token);
} else {
token.identifier = identifier;
// should do a bit more checking!!!! (what about wierd char's in the string..
var str = token.data.substring(1,token.data.length-1);
- if (Regex.match_simple ("^[a-z_]+$", str) && this.idents.index_of(str) < 0) {
+ if (Regex.match_simple ("^[a-z_]+$", str,GLib.RegexCompileFlags.CASELESS) && this.idents.index_of(str) < 0) {
token.outData = str;
}
//println("GOT IDENT: <B>" + symbol + "</B><BR/>");
//println("GOT IDENT (2): <B>" + symbol + "</B><BR/>");
- identifier = this.getIdentifier(symbol, scope, token);
+ var identifier = this.getIdentifier(symbol, scope, token);
- if (identifier == false) {
+ if (identifier == null) {
// BUG!find out where builtin is defined...
if (symbol.length <= 3 && Scope.builtin.indexOf(symbol) < 0) {
// Here, we found an undeclared and un-namespaced symbol that is
//print("MATCH!?");
var _t = this;
-
- token.prefix.replace(/eval:var:([a-z_]+)/ig, function(m, a) {
- //print("GOT: " + a);
- var hi = _t.getIdentifier(a, scope, token);
- // println("PROTECT "+a+" from munge" + (hi ? "FOUND" : "MISSING"));
- if (hi) {
+ var regex = new GLib.Regex ("eval:var:([a-z_]+)",GLib.RegexCompileFlags.CASELESS );
+
+ regex.replace_eval (token.prefix, token.prefix.length, 0, 0, (match_info, result) => {
+ var a = match_info.fetch(0);
+ var hi = this.getIdentifier(a, scope, token);
+ // println("PROTECT "+a+" from munge" + (hi ? "FOUND" : "MISSING"));
+ if (hi.length > 0) {
// print("PROTECT "+a+" from munge");
//print(JSON.stringify(hi,null,4));
hi.toMunge = false;
var identifier = this.getIdentifier(symbol, scope, token);
//println("<B>??</B>");
- if (identifier == false) {
+ if (identifier == null) {
if (symbol.length <= 3 && Scope.builtin.indexOf(symbol) < 0) {
// Here, we found an undeclared and un-namespaced symbol that is
if (this.mode == ScopeParserMode.BUILDING_SYMBOL_TREE) {
if (token.name == "EVAL") {
+
+
//print(JSON.stringify(token,null,4));
- if (token.prefix && token.prefix.match(/eval:var:/g)) {
+
+ if (token.prefix.length > 0 && Regex.match_simple ("eval:var:", token.prefix,GLib.RegexCompileFlags.CASELESS)) {
// look for eval:var:noreplace\n
// print("GOT MATCH?");
- var _t = this;
- token.prefix.replace(/eval:var:([a-z]+)/ig, function(m, a) {
-
+
+
+ var regex = new GLib.Regex ("eval:var:([a-z_]+)",GLib.RegexCompileFlags.CASELESS );
+
+ regex.replace_eval (token.prefix, token.prefix.length, 0, 0, (match_info, result) => {
+ var a = match_info.fetch(0);
//print("PROTECT: " + a);
- var hi = _t.getIdentifier(a, scope, token);
+ var hi = this.getIdentifier(a, scope, token);
//println("PROTECT "+a+" from munge" + (hi ? "FOUND" : "MISSING"));
- if (hi) {
+ if (hi != null) {
// println("PROTECT "+a+" from munge");
hi.toMunge = false;
}
//assert token.getType() == Token.RP; // )
}
- void parseFunctionDeclaration (scope)
+ void parseFunctionDeclaration (Scope scope)
{
//print("PARSE FUNCTION");
var token = this.ts.nextTok();
if (token.type == "NAME") {
- if (this.mode == copeParserMode.BUILDING_SYMBOL_TREE) {
+ if (this.mode == ScopeParserMode.BUILDING_SYMBOL_TREE) {
// Get the name of the function and declare it in the current scope.
symbol = token.data;
if (scope.getIdentifier(symbol,token) != false) {
}
-
+ Scope fnScope;
//assert token.getType() == Token.LP;
- if (this.mode == 'BUILDING_SYMBOL_TREE') {
+ if (this.mode == ScopeParserMode.BUILDING_SYMBOL_TREE) {
fnScope = new Scope(1, scope, token.n, '', token);
//println("STORING SCOPE" + this.ts.cursor);
// print('FUNC-PARSE:' + JSON.stringify(token,null,4));
// Parse function arguments.
var args = token.items;
- for (var argpos =0; argpos < args.length; argpos++) {
+ for (var argpos =0; argpos < args.size; argpos++) {
- token = args[argpos][0];
+ token = args.get(argpos).get(0);
//print ("FUNC ARGS: " + token.toString())
//assert token.getType() == Token.NAME ||
// token.getType() == Token.COMMA;
- if (token.type == 'NAME' && this.mode == 'BUILDING_SYMBOL_TREE') {
- symbol = token.data;
- identifier = fnScope.declareIdentifier(symbol,token);
+ if (token.type == "NAME" && this.mode == ScopeParserMode.BUILDING_SYMBOL_TREE) {
+ var symbol = token.data;
+ var identifier = fnScope.declareIdentifier(symbol,token);
if (symbol == "$super" && argpos == 0) {
// Exception for Prototype 1.6...
identifier.preventMunging();
//token = this.ts.nextTok();
//print(token.toString());
var outTS = this.ts;
- var _this = this;
- token.items.forEach(function(tar) {
- _this.ts = new TokenStream(tar);
- _this.parseScope(fnScope);
-
+ foreach(var tar in token.items) {
+ this.ts = new TokenStream(tar);
+ this.parseScope(fnScope);
});
//print("ENDFN -1: " + this.ts.lookTok(-1).toString());
//print("ENDFN 0: " + this.ts.lookTok(0).toString());
//print("ENDFN 1: " + this.ts.lookTok(1).toString());
- },
+ }
- protectScopeFromObfuscation : function(scope) {
+ void protectScopeFromObfuscation (scope) {
//assert scope != null;
if (scope == this.globalScope) {
//assert scope.getParentScope() == globalScope;
scope.preventMunging();
- },
+ }
- getIdentifier: function(symbol, scope, token) {
- var identifier;
- while (scope != false) {
+ Token? getIdentifier(string symbol, Scope in_scope, Token token)
+ {
+ Token identifier;
+ var scope = in_scope;
+ while (scope != null) {
identifier = scope.getIdentifier(symbol, token);
//println("ScopeParser.getIdentgetUsedSymbols("+symbol+")=" + scope.getUsedSymbols().join(','));
- if (identifier) {
+ if (identifier != null) {
return identifier;
}
scope = scope.parent;
}
- return false;
+ return null;
}
-};
+}