public static AgumentStack parseAguments(Token token, VariabelDatabase database, EnegyData data) { hasDefault = false;//be sure :) AgumentStack agument = new AgumentStack(); if(token.getCache().type() != TokenType.LeftBue) { data.setError(new ScriptError("Excpect ( got: " + token.getCache().ToString(), token.getCache().posision()), database); return null; } //control if wee need to look and parse aguments :) if(token.next().type() != TokenType.RightBue) { //wee need :) if (!getSingleAguments(token, agument, database, data)) return new AgumentStack(); while(token.getCache().type() == TokenType.Comma) { token.next(); if (!getSingleAguments(token, agument, database, data)) return new AgumentStack(); } } //control wee got to ) if(token.getCache().type() != TokenType.RightBue) { data.setError(new ScriptError("Missing ) after function aguments got: " + token.getCache().ToString(), token.getCache().posision()), database); return new AgumentStack(); } return agument; }
private CVar Create_caller(CVar c, VariabelDatabase db, CVar[] stack, EnegyData data, Posision pos) { if(((StaticMethodVariabel)TypeHandler.ToObjectVariabel(c).get("exists")).call(data, db, stack[0].toString(pos, data, db)).toBoolean(pos, data, db)) { data.setError(new ScriptError("'" + stack[0].toString(pos, data, db) + "' exists and there for can not be createt", pos), db); return null; } FileStream fs; StreamWriter f = new StreamWriter((fs = System.IO.File.Create(stack[0].toString(pos, data, db)))); if(!(stack[1] is NullVariabel)) { try { f.Write(stack[1].toString(pos, data, db)); }catch(IOException e) { fs.Close(); f.Close(); data.setError(new ScriptError("Write to the new file '" + stack[0].toString(pos, data, db) + "' failed: " + e.Message, pos), db); return null; } } fs.Close(); f.Close(); return null; }
private void UnsetNext(Token token, EnegyData data, VariabelDatabase db) { if(token.next().type() != TokenType.Variabel) { data.setError(new ScriptError("Missing variabel in 'unset' statmenet", token.getCache().posision()), db); return; } //control wee has the variabel in the variabel database. if (!db.isExists(token.getCache().ToString())) { data.setError(new ScriptError("Unknown variabel: " + token.getCache().ToString(), token.getCache().posision()), db); return; } //is this variabel a global. if (!db.allowedOveride(token.getCache().ToString())) { data.setError(new ScriptError("You can not unset the variabel: " + token.getCache().ToString(), token.getCache().posision()), db); return; } //unset the variabel. db.removeVariabel(token.getCache().ToString()); }
public static TokenCache getScope(Token token, EnegyData data, VariabelDatabase db) { ArrayList cache = new ArrayList(); TokenBuffer buffer; int happens = 1; while((buffer = token.next()).type() != TokenType.EOF) { if (buffer.type() == TokenType.RightBue) { happens--; if (happens == 0) return new TokenCache(cache, data, db); cache.Add(buffer); continue; } else if (buffer.type() == TokenType.LeftBue) happens++; cache.Add(buffer); } data.setError(new ScriptError("Missing ) ", token.getCache().posision()), db); return new TokenCache(new ArrayList(), data, db); }
public virtual CVar call(CVar[] call, VariabelDatabase db, EnegyData data, Posision pos) { if(func.extraVariabelDatabase != null) { db = func.extraVariabelDatabase.createShadow(); if (SetVariabel) { for (int i = 0; i < func.agument.size(); i++) db.push(func.agument.get(i).Name, call[i], data); } } CVar r = func.callFunction(call, db, data, pos); db.garbageCollector(); if(func.ReturnType != null) { //this function is lock to a type :) if (r == null) r = new NullVariabel(); if(!TypeHandler.controlType(r, func.ReturnType)) { data.setError(new ScriptError("a function '"+func.Name+"' returns can not be convertet to '" + func.ReturnType + "'", pos), db); return new NullVariabel(); } } if (r == null) return new NullVariabel(); return r; }
public CVar parse(EnegyData ed, VariabelDatabase db, Token token) { if (token.next().type() != TokenType.LeftBue) ed.setError(new ScriptError("Missing ( after while", token.getCache().posision()), db); TokenCache scope = ScopeParser.getScope(token, ed, db); ArrayList body = BodyParser.parse(token, ed, db); token.next(); //run the code until a boolean false i hit :) while (ed.State == RunningState.Normal && new VariabelParser().parseNoEnd(ed, db, scope).toBoolean(new Posision(0, 0), ed, db)) { Interprenter.parse(new TokenCache(body, ed, db), ed, db); if(ed.State == RunningState.Continue) { ed.setNormal(); }else if(ed.State == RunningState.Break) { ed.setNormal(); break; } } return new NullVariabel(); }
public override CVar call(CVar[] call, VariabelDatabase db, EnegyData data, Posision pos) { if(extraVariabelDatabase != null) { db = getShadowVariabelDatabase(extraVariabelDatabase); if (SetVariabel) { for (int i = 0; i < method.Agument.size(); i++) db.push(method.Agument.get(i).Name, call[i], data); } } CVar cache = method.Body(obj, db, call, data, pos); db.garbageCollector(); if(method.ReturnType != null) { if(!TypeHandler.controlType(cache, method.ReturnType)) { data.setError(new ScriptError("a method '" + obj.Name + "->"+method.Name+"' returns can not be convertet to '" + method.ReturnType + "'", pos), db); return new NullVariabel(); } } return cache; }
public void SetConstructor(Method method, EnegyData data, VariabelDatabase db, Posision pos) { if(container.Constructor != null) { data.setError(new ScriptError("A class can only have one constructor", pos), db); return; } container.Constructor = method.GetMethodContainer(); }
private void parseFile(EnegyData ed, VariabelDatabase db, Posision pos, string plugin) { if (!File.Exists(plugin)) { ed.setError(new ScriptError("Unknown file: " + plugin, pos), db); return; } FileEnergy.parse(ed, new FileVariabelDatabase(db), plugin); }
public CVar get(CVar key, Posision pos, EnegyData data, VariabelDatabase db) { if (!keyExists(key, pos, data, db)) { data.setError(new ScriptError("Unknown key in array: " + key.toString(pos, data, db), pos), db); return new NullVariabel(); } return container[key.toString(pos, data, db)]; }
private CVar ToInt_call(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos) { double result; if (!double.TryParse(stack[0].toString(pos, data, db), out result)) { data.setError(new ScriptError(stack[0].toString(pos, data, db) + " could not be convertet to int", new Posision(0, 0)), db); return new NullVariabel(); } return Types.toInt(result, data, db, pos); }
private CVar Get_caller(CVar c, VariabelDatabase db, CVar[] stack, EnegyData data, Posision pos) { string name = stack[0].toString(pos, data, db); if (!data.Config.exists(name)) { data.setError(new ScriptError("Unknown config name: " + name, pos), db); return new NullVariabel(); } return Types.toString(data.Config.get(name, ""), data, db, pos); }
private CVar IsLocked_caller(CVar c, VariabelDatabase db, CVar[] stack, EnegyData data, Posision pos) { string name = stack[0].toString(pos, data, db); if (!data.Config.exists(name)) { data.setError(new ScriptError("Unknown config: " + name, pos), db); return new BooleanVariabel(false); } return new BooleanVariabel(data.Config.isAllowedOverride(name)); }
public static ArrayList parse(Token token, EnegyData data, VariabelDatabase db, bool needTubor = false) { ArrayList cache = new ArrayList(); //wee control the next token to see if it { if(token.next().type() == TokenType.LeftTuborg) { int happens = 1; TokenBuffer buffer; while((buffer = token.next()).type() != TokenType.EOF) { if (buffer.type() == TokenType.RightTuborg) { happens--; if (happens == 0) break; } else if (buffer.type() == TokenType.LeftTuborg) happens++; cache.Add(buffer); } if(token.getCache().type() != TokenType.RightTuborg) { data.setError(new ScriptError("Missing } got " + token.getCache().ToString(), token.getCache().posision()), db); return new ArrayList(); } } else { if (needTubor) { data.setError(new ScriptError("Missing {", token.getCache().posision()), db); return new ArrayList(); } } return cache; }
public CVar parse(EnegyData ed, VariabelDatabase db, Token token) { if(token.next().type() != TokenType.End) { ed.setError(new ScriptError("Missing ; after 'break'", token.getCache().posision()), db); return null; } token.next(); ed.setBreak(); return null; }
public CVar parse(EnegyData ed, VariabelDatabase db, Token token) { if (token.next().type() != TokenType.LeftBue) { ed.setError(new ScriptError("Missing ( after 'for'", token.getCache().posision()), db); return null; } //push the tokens until ; ArrayList init = getNextBlock(ed, db, token, true); if (ed.State != RunningState.Normal) { return null; } ArrayList status = getNextBlock(ed, db, token, true); if (ed.State != RunningState.Normal) { return null; } ArrayList handler = getNextBlock(ed, db, token, false); if (ed.State != RunningState.Normal) { return null; } ArrayList body = BodyParser.parse(token, ed, db); if (ed.State != RunningState.Normal) { return null; } //init the data :) new VariabelParser().parseNoEnd(ed, db, new TokenCache(init, ed, db)); while (ed.State == RunningState.Normal && new VariabelParser().parseNoEnd(ed, db, new TokenCache(status, ed, db)).toBoolean(token.getCache().posision(), ed, db)) { Interprenter.parse(new TokenCache(body, ed, db), ed, db); if (ed.State == RunningState.Normal) new VariabelParser().parseNoEnd(ed, db, new TokenCache(handler, ed, db)); } token.next(); return null; }
public CVar parse(EnegyData ed, VariabelDatabase db, Token token) { if (token.next().type() != TokenType.LeftBue) { ed.setError(new ScriptError("Missing ( after repeat", token.getCache().posision()), db); return new NullVariabel(); } TokenCache cache = ScopeParser.getScope(token, ed, db); token.next(); while (new VariabelParser().parse(ed, db, cache).toBoolean(token.getCache().posision(), ed, db)) ; return new NullVariabel(); }
public CVar parse(EnegyData ed, VariabelDatabase db, Token token) { UnsetNext(token, ed, db); while (token.next().type() == TokenType.Comma) UnsetNext(token, ed, db); if(token.getCache().type() != TokenType.End) { ed.setError(new ScriptError("Missing ; in end of unset", token.getCache().posision()), db); return null; } token.next(); return null; }
private ArrayList getNextBlock(EnegyData data, VariabelDatabase db, Token token, bool isEnd) { TokenBuffer buffer; ArrayList b = new ArrayList(); while ((buffer = token.next()).type() != TokenType.EOF && buffer.type() != (isEnd ? TokenType.End : TokenType.RightBue)) { b.Add(buffer); } if (token.getCache().type() != (isEnd ? TokenType.End : TokenType.RightBue)) { data.setError(new ScriptError("Missing " + (isEnd ? ";" : ")") + " got: " + token.getCache().ToString(), token.getCache().posision()), db); return new ArrayList(); } return b; }
public CVar parse(EnegyData ed, VariabelDatabase db, Token token) { if (token.next().type() == TokenType.Function) { functionParser p = new functionParser(); p.parseFunction(ed, db, token, true, true); }else if(token.getCache().type() == TokenType.Class) { ClassParser p = new ClassParser(); p.parse(ed, db, token); } else { ed.setError(new ScriptError("unknown token after public: " + token.getCache().ToString(), token.getCache().posision()), db); } return new NullVariabel(); }
public override CVar call(CVar[] call, VariabelDatabase db, EnegyData data, Posision pos) { CVar cache = method.Body(c, db, call, data, pos); db.garbageCollector(); if (method.ReturnType != null) { if(!TypeHandler.controlType(cache, method.ReturnType)) { data.setError(new ScriptError("a static method '" + c.Name + "->" + method.Name + "' returns can not be convertet to '" + method.ReturnType + "'", pos), db); return new NullVariabel(); } } return cache; }
public void open(VariabelDatabase database, EnegyData data, Posision pos) { if(data.Config.get("file.system.enable", "false") != "true") { data.setError(new ScriptError("You can use the plugin 'file' becuse it not enabled in the config system!", new Posision(0, 0)), database); return; } Class f = new Class("File"); Method exsist = new Method("exists"); exsist.SetStatic(); exsist.GetAgumentStack().push("string", "dir"); exsist.SetBody(Exsist_caller); f.SetMethod(exsist, data, database, pos); Method create = new Method("create"); create.SetStatic(); create.GetAgumentStack().push("string", "dir"); create.GetAgumentStack().push("string", "context", new NullVariabel()); create.SetBody(Create_caller); f.SetMethod(create, data, database, pos); Method delete = new Method("delete"); delete.SetStatic(); delete.GetAgumentStack().push("string", "dir"); delete.SetBody(Delete_caller); f.SetMethod(delete, data, database, pos); Method write = new Method("write"); write.SetStatic(); write.GetAgumentStack().push("string", "dir"); write.GetAgumentStack().push("string", "context"); write.SetBody(Write_caller); f.SetMethod(write, data, database, pos); Method read = new Method("read"); read.SetStatic(); read.GetAgumentStack().push("string", "dir"); read.SetBody(Read_caller); f.SetMethod(read, data, database, pos); database.pushClass(f, data); }
private void includePlugin(string name, EnegyData ed, VariabelDatabase db, Token token) { //control if the plugin exists in the system if (ed.Plugin.exists(name)) { //wee has the plugin and load it :) ed.Plugin.open(db, name, ed, token.getCache().posision()); } else { if (ed.Config.get("file.enabled", "false") == "false") { ed.setError(new ScriptError("It is not allow to use file in use. 'file.enabled' is not set.", token.getCache().posision()), db); return; } parseFile(ed, db, token.getCache().posision(), name); } }
private CVar Set_caller(CVar c, VariabelDatabase db, CVar[] stack, EnegyData data, Posision pos) { if (data.Config.isScriptLock) { data.setError(new ScriptError("The config is locked", pos), db); return null; } string name = stack[0].toString(pos, data, db); if (data.Config.exists(name) && data.Config.isAllowedOverride(name)) { data.setError(new ScriptError("The config '" + name + "' is not allowed to be changed by the script", pos), db); return new NullVariabel(); } data.Config.append(name, stack[1].toString(pos, data, db), true); return null; }
public CVar parse(EnegyData ed, VariabelDatabase db, Token token) { token.next(); includePlugin(new VariabelParser().parseNoEnd(ed, db, token).toString(token.getCache().posision(), ed, db), ed, db, token); while (token.getCache().type() == TokenType.Comma) { token.next(); includePlugin(new VariabelParser().parseNoEnd(ed, db, token).toString(token.getCache().posision(), ed, db), ed, db, token); } if(token.getCache().type() != TokenType.End) { ed.setError(new ScriptError("Missing ; in end of use. got: "+token.getCache().ToString(), token.getCache().posision()), db); return null; } token.next(); return new NullVariabel(); }
public override CVar call(EnegyData data, VariabelDatabase db, params object[] parameters) { CVar[] stack = new CVar[method.Agument.size()]; VariabelDatabase vd = getShadowVariabelDatabase(db); for (int i = 0; i < parameters.Length && i <= method.Agument.size(); i++) { CVar context = ScriptConverter.convert(parameters[i], data, db); if (method.Agument.get(i).hasType() && !TypeHandler.controlType(context, method.Agument.get(i).Type)) { data.setError(new ScriptError("Cant convert " + context.type() + " to " + method.Agument.get(i).Type.ToString(), new Posision(0, 0)), db); } //okay let cache the parameters :) stack[0] = context; if(SetVariabel) vd.push(method.Agument.get(i).Name, stack[0], data); } //wee take a new for loop to get other parameters there is not has been set :) for (int i = stack.Length; i < method.Agument.size(); i++) { if (!method.Agument.get(i).hasValue()) { data.setError(new ScriptError("Missing agument to " + method.Name, new Posision(0, 0)), db); return new NullVariabel(); } stack[i] = method.Agument.get(i).Value; if(SetVariabel) vd.push(method.Agument.get(i).Name, method.Agument.get(i).Value, data); } return call(stack, db, data, new Posision(0,0)); }
private CVar p(EnegyData ed, VariabelDatabase db, Token token, bool name) { this.db = db; if (name) { if (token.next().type() != TokenType.Variabel) { ed.setError(new ScriptError("Missing class name after 'class'", token.getCache().posision()), db); return new NullVariabel(); } builder = new Class(token.getCache().ToString()); } else { builder = new Class(); } if(token.next().type() == TokenType.Extends) { if(token.next().type() != TokenType.Variabel) { ed.setError(new ScriptError("Missing variabel after extends", token.getCache().posision()), db); return new NullVariabel(); } //control if the variabel exteis in the variabel database if (!db.isExists(token.getCache().ToString())) { ed.setError(new ScriptError("Unknown variabel: " + token.getCache().ToString(), token.getCache().posision()), db); return new NullVariabel(); } CVar buffer = db.get(token.getCache().ToString(), ed); if(!(buffer is ClassVariabel)) { ed.setError(new ScriptError(token.getCache().ToString() + " is not a class", token.getCache().posision()), db); return new NullVariabel(); } builder.Extends((ClassVariabel)buffer); token.next(); } if(token.getCache().type() != TokenType.LeftTuborg) { ed.setError(new ScriptError("Missing { after class name", token.getCache().posision()), db); return new NullVariabel(); } token.next(); while (ed.State == RunningState.Normal && run(token.getCache().type())) build(token, ed); if(token.getCache().type() != TokenType.RightTuborg) { ed.setError(new ScriptError("Missing } in end of class building", token.getCache().posision()), db); return new NullVariabel(); } token.next(); if (name) { db.pushClass(builder, ed); if (db is FileVariabelDatabase) { builder.SetExtraVariabelDatabase(db); ((FileVariabelDatabase)db).VariabelDatabase.pushClass(builder, ed); } return null; } else { return new ClassVariabel(builder); } }
private static bool getSingleAguments(Token token, AgumentStack agument, VariabelDatabase database, EnegyData data) { string type = null; string name = null; CVar value = null; //wee control if it is function :) if(token.getCache().ToString() == "function") { if(token.next().type() == TokenType.Greater) { //it is a function with return type :) if (!database.isType(token.next().ToString())) { data.setError(new ScriptError("Unknown type: " + token.getCache().ToString(), token.getCache().posision()), database); return false; } type = "function<" + token.getCache().ToString() + ">"; if(token.next().type() != TokenType.Less) { data.setError(new ScriptError("Missing > in end of function return type agument", token.getCache().posision()), database); } token.next(); } else { type = "function"; } //okay let try to find the name if (token.getCache().type() != TokenType.Variabel) { data.setError(new ScriptError("After type there must be a variabel", token.getCache().posision()), database); return false; } name = token.getCache().ToString(); } else if (database.isType(token.getCache().ToString())) { //yes it is a type :) type = token.getCache().ToString(); //okay let try to find the name if (token.next().type() != TokenType.Variabel) { data.setError(new ScriptError("After type there must be a variabel", token.getCache().posision()), database); return false; } name = token.getCache().ToString(); } else { if (token.getCache().type() != TokenType.Variabel) { data.setError(new ScriptError("Unknown agument token: " + token.getCache().ToString(), token.getCache().posision()), database); return false; } name = token.getCache().ToString(); } if (token.next().type() == TokenType.Assigen) { token.next(); value = new VariabelParser().parseNoEnd(data, database, token); hasDefault = true; } else { if (hasDefault) { data.setError(new ScriptError("You can not put non default after a defualt variabel!", token.getCache().posision()), database); return false; } } agument.push(type, name, value); return true; }
private CVar Error_call(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos) { data.setError(new ScriptError(stack[0].toString(pos, data, db), pos), db); return new NullVariabel(); }
private bool buildMethod(ClassItemAccessLevel level, bool isStatic, Token token, EnegyData data) { //control if there are is name after function :) if (token.getCache().type() != TokenType.Variabel) { data.setError(new ScriptError("A method should have a name", token.getCache().posision()), db); return false; } string type = null; //okay the name can be a type so wee control it here :) if (Types.IsType(token.getCache().ToString(), db)) { type = token.getCache().ToString(); if(token.next().type() != TokenType.Variabel) { data.setError(new ScriptError("A method should have a name", token.getCache().posision()), db); return false; } } Method method = new Method(token.getCache().ToString()); token.next(); if (isStatic) method.SetStatic(); method.SetAgumentStack(AgumentParser.parseAguments(token, db, data)); method.SetBody(new CallScriptMethod(method.GetAgumentStack(), BodyParser.parse(token, data, db)).call); method.SetVariabel();//in this way the script can use agument as name :) method.setLevel(level); builder.SetMethod(method, data, db, token.getCache().posision()); token.next(); return true; }