Skip to content

Commit

Permalink
V0.2 is now out
Browse files Browse the repository at this point in the history
The V0.2 is now out. Many thinks is changes so it a lot faster end V0.1
  • Loading branch information
Ronnie committed Feb 4, 2016
1 parent 65b44c6 commit 3e84480
Show file tree
Hide file tree
Showing 28 changed files with 298 additions and 44 deletions.
9 changes: 6 additions & 3 deletions EnegyData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class EnegyData
{
public FunctionVariabel ErrorHandler { get; set; }
public ScriptConfig Config { get; set; }
public RunningState State { get; private set; }
public virtual RunningState State { get; private set; }
public PluginContainer Plugin { get; set; }

public ScriptError ErrorData { get; private set; }
Expand All @@ -33,11 +33,14 @@ public void setReturn(CVar r)
ReturnContext = r;
}

public void setError(ScriptError er, VariabelDatabase db)
public virtual void setError(ScriptError er, VariabelDatabase db)
{
if (State == RunningState.Error)
return;
State = RunningState.Error;
ErrorData = er;
if(ErrorHandler != null)

if (ErrorHandler != null)
{
//okay here may not be a error handler and state must be set to normal
FunctionVariabel eh = ErrorHandler;
Expand Down
22 changes: 19 additions & 3 deletions Interprenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using script.plugin;
using script.token;
using script.variabel;
using System;

namespace script
{
Expand All @@ -21,17 +22,22 @@ public void setStatic(ClassVariabel c)
}

public static void parse(Token token, EnegyData data, VariabelDatabase db) {
parse(token, data, db, false);
}

public static void parse(Token token, EnegyData data, VariabelDatabase db, bool isFile)
{
token.next();
ParserInterface pi;
//run thrue the script (if Run is true and return is null)
while (data.State == RunningState.Normal && token.getCache().type() != TokenType.EOF)
while (data.State == RunningState.Normal && token.getCache().type() != TokenType.EOF && (pi = getParser(token, isFile, data, db)) != null)
{
ParserInterface pi = getParser(token);
pi.parse(data, db, token);
pi.end(data, db);//in some parser it will have this to detext if end is okay (like variabel parseren)
}
}

private static ParserInterface getParser(Token token)
private static ParserInterface getParser(Token token, bool isFile, EnegyData data, VariabelDatabase database)
{
switch (token.getCache().type())
{
Expand All @@ -51,6 +57,16 @@ private static ParserInterface getParser(Token token)
return new WhileParser();
case TokenType.Repeat:
return new RepeatParser();
case TokenType.For:
return new ForParser();
case TokenType.Public:
if (!isFile)
{
data.setError(new ScriptError("public [function/class] can only be uses when you parse file from use 'path'", token.getCache().posision()), database);
return null;
}

return new PublicParser();
default:
return new VariabelParser();
}
Expand Down
25 changes: 17 additions & 8 deletions builder/Class.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class Class
public ClassMethods constructor { private set; get; }
private EnegyData data;
private VariabelDatabase db;
public VariabelDatabase extraVariabelDatabase { get; set; }

public Class(string name, EnegyData data, VariabelDatabase db) { Name = name; this.data = data; this.db = db; }
public Class(string name) { Name = name; data = new EnegyData(); }
Expand All @@ -24,14 +25,16 @@ public void setStaticData(Dictionary<string, ClassStaticData> i, ClassVariabel v
i.Add(d.Name, new ClassStaticData()
{
isMethod = true,
Context = new StaticMethodVariabel((ClassStaticMethods)d.Method, var),
isPublic = d.Method.isPublic
Context = new StaticMethodVariabel((ClassStaticMethods)d.Method, var, extraVariabelDatabase),
isPublic = d.Method.isPublic,
extraVariabelDatabase = extraVariabelDatabase,
});
else if (!d.IsMethod && d.IsStatic)
i.Add(d.Name, new ClassStaticData() {
isMethod = false,
Context = d.Context,
isPublic = d.IsPublic
Context = d.Context,
isPublic = d.IsPublic,
extraVariabelDatabase = extraVariabelDatabase,
});
}
}
Expand All @@ -47,7 +50,8 @@ public void addVariabel(string name, CVar context, bool isStatic, bool isPublic)
Name = name,
Context = context,
IsStatic = isStatic,
IsPublic = isPublic
IsPublic = isPublic,
extraVariabelDatabase = extraVariabelDatabase,
});
}

Expand All @@ -59,13 +63,17 @@ public void addVariabel(string name, bool isStatic, bool isPublic)
public void addMethod(ClassItemsMethod m)
{
if (!controlItems(m.Name))
{
data.setError(new ScriptError("You can only add one method: " + m.Name, new Posision(0, 0)), db);
return;
}

items.Add(m.Name, new ClassItems()
{
IsMethod = true,
Method = m,
Method = m,
Name = m.Name,
extraVariabelDatabase = extraVariabelDatabase,
});
}

Expand Down Expand Up @@ -94,7 +102,7 @@ public ObjectVariabel createObject()
{
isMethod = true,
Name = item.Method.Name,
Context = new MethodVariabel((ClassMethods)item.Method, obj),
Context = new MethodVariabel((ClassMethods)item.Method, obj, extraVariabelDatabase),
isPublic = item.Method.isPublic,
isStatic = item.Method.isStatic
});
Expand All @@ -106,7 +114,8 @@ public ObjectVariabel createObject()
Name = item.Name,
Context = item.Context,
isPublic = item.IsPublic,
isStatic = item.IsStatic
isStatic = item.IsStatic,
extraVariabelDatabase = extraVariabelDatabase,
});
}

Expand Down
1 change: 1 addition & 0 deletions builder/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Function
public string Name { get; set; }
public AgumentStack agument = new AgumentStack();
public event CallFunctionEvent call;
public VariabelDatabase extraVariabelDatabase { get; set; }

public CVar callFunction(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos)
{
Expand Down
1 change: 1 addition & 0 deletions help/ClassItemsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public class ClassItems
public CVar Context { get; set; }
public bool IsStatic { get; set; }
public bool IsPublic { get; set; }
public VariabelDatabase extraVariabelDatabase { get; set; }
}
}
1 change: 1 addition & 0 deletions help/ClassStaticData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public class ClassStaticData
public bool isMethod { set; get; }
public CVar Context { set; get; }
public bool isPublic { set; get; }
public VariabelDatabase extraVariabelDatabase { set; get; }
}
}
1 change: 1 addition & 0 deletions help/ObjectItemData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public class ObjectItemData
public CVar Context { set; get; }
public bool isMethod { set; get; }
public bool isStatic { set; get; }
public VariabelDatabase extraVariabelDatabase { set; get; }
}
}
2 changes: 1 addition & 1 deletion help/StartItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private static void createStringClass(EnegyData data, VariabelDatabase db)
ClassMethods constructor = new ClassMethods(s, "constructor");
constructor.Aguments.push("string", "s", new NullVariabel());
constructor.caller += Constructor_caller;
constructor.create();
constructor.createConstructor();

ClassMethods length = new ClassMethods(s, "length");
length.caller += Length_caller;
Expand Down
13 changes: 13 additions & 0 deletions parser/ClassParser.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
using script.builder;
using script.help;
using script.plugin.File;
using script.stack;
using script.token;
using script.variabel;
using System;

namespace script.parser
{
class ClassParser : ParserInterface
{
private Class builder;
private VariabelDatabase db;
private bool isFile;

public ClassParser(bool isFile = false)
{
this.isFile = isFile;
}

public void end(EnegyData data, VariabelDatabase db)
{}
Expand Down Expand Up @@ -45,6 +53,11 @@ public CVar parse(EnegyData ed, VariabelDatabase db, Token token)

token.next();
db.pushClass(builder, ed);
if (isFile)
{
builder.extraVariabelDatabase = db;
((FileVariabelDatabase)db).VariabelDatabase.pushClass(builder, ed);
}
return new NullVariabel();
}

Expand Down
81 changes: 81 additions & 0 deletions parser/ForParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using script.token;
using script.variabel;
using System.Collections;

namespace script.parser
{
class ForParser : ParserInterface
{
public void end(EnegyData data, VariabelDatabase db)
{
}

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().parse(ed, db, new TokenCache(init, ed, db));

while(ed.State == RunningState.Normal && new VariabelParser().parse(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().parse(ed, db, new TokenCache(handler, ed, db));
}
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;
}
}
}
32 changes: 32 additions & 0 deletions parser/PublicParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using script.token;
using script.variabel;
using System;

namespace script.parser
{
class PublicParser : ParserInterface
{
public void end(EnegyData data, VariabelDatabase db)
{}

public CVar parse(EnegyData ed, VariabelDatabase db, Token token)
{
if(token.next().type() == TokenType.Function)
{
functionParser p = new functionParser(true);
p.parse(ed, db, token);
p.end(ed, db);
}else if(token.getCache().type() == TokenType.Class)
{
ClassParser p = new ClassParser(true);
p.parse(ed, db, token);
p.end(ed, db);
}
else
{
ed.setError(new ScriptError("unknown token after public: " + token.getCache().ToString(), token.getCache().posision()), db);
}
return new NullVariabel();
}
}
}
3 changes: 1 addition & 2 deletions parser/RepeatParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public CVar parse(EnegyData ed, VariabelDatabase db, Token token)
TokenCache cache = ScopeParser.getScope(token, ed, db);
token.next();

while (new VariabelParser().parse(ed, db, cache).toBoolean(token.getCache().posision(), ed, db))
cache.reaset();
while (new VariabelParser().parse(ed, db, cache).toBoolean(token.getCache().posision(), ed, db)) ;

return new NullVariabel();
}
Expand Down
19 changes: 13 additions & 6 deletions parser/UseParser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using script.token;
using script.plugin.File;
using script.token;
using script.variabel;
using System.Text.RegularExpressions;
using System.IO;

namespace script.parser
{
Expand All @@ -26,21 +27,27 @@ public CVar parse(EnegyData ed, VariabelDatabase db, Token token)
}
else
{
if(ed.Config.get("file.base", "0") == "0")
if(ed.Config.get("file.enabled", "false") == "false")
{
ed.setError(new ScriptError("It is not allow to use file in use. 'file.base' is not set.", token.getCache().posision()), db);
ed.setError(new ScriptError("It is not allow to use file in use. 'file.enabled' is not set.", token.getCache().posision()), db);
return new NullVariabel();
}

parseFile(ed, db, token.getCache().posision());
parseFile(ed, db, token.getCache().posision(), plugin);
}

return new NullVariabel();
}

private void parseFile(EnegyData ed, VariabelDatabase db, Posision pos)
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(new FileEnergyData(ed), new FileVariabelDatabase(db), plugin);
}
}
}
Loading

0 comments on commit 3e84480

Please sign in to comment.