Skip to content

Commit

Permalink
finishi version 0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecvo committed Aug 4, 2009
1 parent f0d5f6e commit c3016f0
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Unahi.CRake/Binary.cs
Expand Up @@ -27,7 +27,7 @@ public class Binary {
return;
}
}
throw new InvalidOperationException(string.Format("Unknow method '{0}'", key));
throw new InvalidOperationException(string.Format("Unknow task '{0}'", key));
}

private object GetInstance(string className) {
Expand Down
7 changes: 6 additions & 1 deletion Unahi.CRake/CRake.cs
Expand Up @@ -67,7 +67,12 @@ class CRake : Base<CRake> {
}

var key = Arguments.Values[0];
binary.InvokeMember(key);
try {
binary.InvokeMember(key);
} catch (Exception ex) {
Console.WriteLine("CRake aborted!");
Console.WriteLine(ex.Message);
}
//foreach (var task in binary.Tasks) {
// if (task.Key == key) {
// if (task.Compiled.Errors.HasErrors) {
Expand Down
2 changes: 2 additions & 0 deletions Unahi.CRake/Code/Base.cs
Expand Up @@ -9,11 +9,13 @@ public class Base {
Namespaces = new List<Namespace>();
Tasks = new List<Task>();
Imports = new List<string>();
Codes = new List<string>();
}

public List<Namespace> Namespaces { get; set; }
public List<Task> Tasks { get; set; }
public List<string> Imports { get; set; }
public List<string> Codes { get; set; }
public string Name { get; set; }
}
}
10 changes: 8 additions & 2 deletions Unahi.CRake/Code/Compiler.cs
Expand Up @@ -59,7 +59,7 @@ public class Compiler : Base {
return binary;
}

private void CompileClass(string parent, List<Task> tasks, List<Namespace> subClasses, CodeTypeDeclaration parentType) {
private CodeTypeDeclaration CompileClass(string parent, List<Task> tasks, List<Namespace> subClasses, CodeTypeDeclaration parentType) {
var className = parent.Split(':').Last();
if (className == string.Empty) className = "root";
className = string.Format("Class_{0}", className);
Expand Down Expand Up @@ -93,8 +93,14 @@ public class Compiler : Base {
foreach (var item in subClass.Imports) {
codeNamespace.Imports.Add(new CodeNamespaceImport(item));
}
CompileClass(string.Format("{0}{1}{2}", parent, string.IsNullOrEmpty(parent) ? "" : ":", subClass.Name), subClass.Tasks, subClass.Namespaces, type);
var child = CompileClass(string.Format("{0}{1}{2}", parent, string.IsNullOrEmpty(parent) ? "" : ":", subClass.Name), subClass.Tasks, subClass.Namespaces, type);
foreach (var code in subClass.Codes) {
var member = new CodeSnippetTypeMember(code);
child.Members.Add(member);
}
}

return type;
}

private string GetFullClassName(string parent) {
Expand Down
14 changes: 13 additions & 1 deletion Unahi.CRake/FileParser.cs
Expand Up @@ -8,7 +8,7 @@

namespace Unahi.CRake {
public class FileParser {
const string MethodPattern = "^(require|namespace|desc|task|end|imports)\\s+(.+)";
const string MethodPattern = "^(require|namespace|desc|task|end|imports|public)\\s+(.+)";
Compiler compiler = new Compiler();
string tempDescription = string.Empty;

Expand Down Expand Up @@ -43,10 +43,22 @@ public class FileParser {
return ProcessTask(parent, body);
case "imports":
return ProcessUsing(parent, body);
case "public":
return ProcessCode(parent, body);
}
return null;
}

private string ProcessCode(Base parent, string body) {
if (!(parent is Namespace)) {
throw new InvalidOperationException("C# code is only accepted inside a namespace");
}
var split = Regex.Split(body, "(.+?{.+})\\s*(.*)");
var code = "public " + split[1];
parent.Codes.Add(code);
return split[2];
}

private string ProcessUsing(Base parent, string body) {
if (!(parent is Namespace) && !(parent is Compiler)) {
throw new InvalidOperationException("using must be inside a namespace or root.");
Expand Down
Binary file modified Unahi.CRake/Unahi.CRake.suo
Binary file not shown.
Binary file modified Unahi.CRake/bin/Debug/crake.exe
Binary file not shown.
Binary file modified Unahi.CRake/bin/Debug/crake.pdb
Binary file not shown.
Binary file modified Unahi.CRake/bin/Debug/crake.vshost.exe
Binary file not shown.
4 changes: 4 additions & 0 deletions Unahi.CRake/bin/Debug/crakefile
Expand Up @@ -6,6 +6,10 @@ namespace :db do
task :create do
System.Console.WriteLine("criei o banco de dados");
end

task :say do
CreateTable2("HI");
end
end

namespace :tests do
Expand Down
13 changes: 13 additions & 0 deletions Unahi.CRake/bin/Debug/tasks/migration.crake
Expand Up @@ -11,4 +11,17 @@ namespace :db do
task :migration do
System.Console.WriteLine("fiz a migration");
end

task :my do
CreateTable("");
end

public void CreateTable(string tableName) {
Console.WriteLine("Custom method in C#");
}

public void CreateTable2(string tableName) {
Console.WriteLine("Custom method in C# 2!");
Console.WriteLine("Table: " + tableName);
}
end
Binary file modified Unahi.CRake/bin/Release/crake.exe
Binary file not shown.
Binary file modified Unahi.CRake/bin/Release/crake.pdb
Binary file not shown.
Binary file modified Unahi.CRake/obj/Debug/crake.exe
Binary file not shown.
Binary file modified Unahi.CRake/obj/Debug/crake.pdb
Binary file not shown.
Binary file modified Unahi.CRake/obj/Release/crake.exe
Binary file not shown.
Binary file added Unahi.CRake/obj/Release/crake.pdb
Binary file not shown.

0 comments on commit c3016f0

Please sign in to comment.