diff --git a/.gitignore b/.gitignore index 3804965b14ab0de411111baa23a4cd604d97ad3c..d043fb5915ac923321569a9f29204570a43c0e2c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /obj/ /bin/ /.vs/ +/output/ \ No newline at end of file diff --git a/IWriter.cs b/IWriter.cs new file mode 100644 index 0000000000000000000000000000000000000000..b159d1e23a2a975caf1d303e2846135de0f6be12 --- /dev/null +++ b/IWriter.cs @@ -0,0 +1,7 @@ +namespace compiler +{ + public interface IWriter + { + void Write(string path, TestParser.Node rootNode); + } +} diff --git a/MonitorPyWriter.cs b/MonitorPyWriter.cs new file mode 100644 index 0000000000000000000000000000000000000000..73ab9336de5b8b5905fdc5798b859210edb8fc71 --- /dev/null +++ b/MonitorPyWriter.cs @@ -0,0 +1,18 @@ +using System.IO; + +namespace compiler +{ + public class MonitorPyWriter : IWriter + { + public void Write(string path, TestParser.Node rootNode) + { + var targetFile = Path.Combine(path, "monitor.py"); + File.WriteAllText(targetFile, $@" +# ToDo: Add Python Code + + + +"); + } + } +} diff --git a/ObstaclePyWriter.cs b/ObstaclePyWriter.cs new file mode 100644 index 0000000000000000000000000000000000000000..f942ac8d5e8df8fbd656df94418d81796e4458fd --- /dev/null +++ b/ObstaclePyWriter.cs @@ -0,0 +1,18 @@ +using System.IO; + +namespace compiler +{ + public class ObstaclePyWriter : IWriter + { + public void Write(string path, TestParser.Node rootNode) + { + var targetFile = Path.Combine(path, "obstacle.py"); + File.WriteAllText(targetFile, $@" +# ToDo: Add Python Code + + + +"); + } + } +} diff --git a/Program.cs b/Program.cs index db124679b2c71a6072b801561bb4bc66829f5053..97dfc5ff824e2c6bb5bd5399cf50f7d165cc7856 100644 --- a/Program.cs +++ b/Program.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Linq; namespace compiler @@ -16,23 +17,27 @@ namespace compiler } var sourceDirectory = args[0]; - var sourceFiles = System.IO.Directory.GetFiles(sourceDirectory, "*.uml"); + var targetDirectory = args[1]; + + if (Directory.Exists(targetDirectory)) + { + Directory.Delete(targetDirectory, true); + } + + var sourceFiles = Directory.GetFiles(sourceDirectory, "*.uml", SearchOption.AllDirectories); foreach (var sourceFile in sourceFiles) { - Console.WriteLine("New file: " + sourceFile); + var baseName = sourceFile.Substring(sourceDirectory.Length + 1); + + Console.WriteLine("Processing file: " + baseName); var rootNodes = TestParser.ReadFile(sourceFile).ToList(); - // thw following is just for testing - foreach (var rootNode in rootNodes) + for (var i = 0; i < rootNodes.Count; i++) { - Console.WriteLine("New rootNode"); - var node = rootNode; - while (node != null) - { - Console.WriteLine(node.Text); - Console.WriteLine(node.Data?.Select(x => " " + x)?.Aggregate((x, y) => x + "\n" + y)); - node = node.Next; - } + var rootNode = rootNodes[i]; + var path = Path.Combine(targetDirectory, @$"{baseName}-{i}"); + Directory.CreateDirectory(path); + TestWriter.WriteAll(path, rootNode); } } } diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json index ec02d06b895d4a4b3c06c3822abc0e3b71cb535d..889107a5bfa7f6db94ecb4e506bb91e7de233db6 100644 --- a/Properties/launchSettings.json +++ b/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "compiler": { "commandName": "Project", - "commandLineArgs": "../../../tests ../../../output" + "commandLineArgs": "../../../TestSpec ../../../output" } } } \ No newline at end of file diff --git a/TestWriter.cs b/TestWriter.cs index 0250c713af00f252810b3d6394efb875448af254..6b5cf6e83438d1506bdb8308a9271e3737a42590 100644 --- a/TestWriter.cs +++ b/TestWriter.cs @@ -1,6 +1,20 @@ -namespace compiler +using System.Collections.Generic; + +namespace compiler { public static class TestWriter { + public static void WriteAll(string path, TestParser.Node rootNode) + { + var writers = new List<IWriter>(); + writers.Add(new MonitorPyWriter()); + writers.Add(new ObstaclePyWriter()); + writers.Add(new WorldWriter()); + + foreach (var writer in writers) + { + writer.Write(path, rootNode); + } + } } } diff --git a/WorldWriter.cs b/WorldWriter.cs new file mode 100644 index 0000000000000000000000000000000000000000..f410760f6d6376a25d14750080efdd6741a95fdd --- /dev/null +++ b/WorldWriter.cs @@ -0,0 +1,17 @@ +using System.IO; + +namespace compiler +{ + public class WorldWriter : IWriter + { + public void Write(string path, TestParser.Node rootNode) + { + var targetFile = Path.Combine(path, "test.world"); + File.WriteAllText(targetFile, $@" + + + +"); + } + } +} diff --git a/compiler.csproj b/compiler.csproj index d453e9a07115e38f587d8e299b4fc2d68f0f4d74..70f7e771d51d1508362c40ba6db4d0e538478793 100644 --- a/compiler.csproj +++ b/compiler.csproj @@ -5,4 +5,17 @@ <TargetFramework>netcoreapp3.1</TargetFramework> </PropertyGroup> + <ItemGroup> + <Compile Remove="Tests\**" /> + <EmbeddedResource Remove="Tests\**" /> + <None Remove="Tests\**" /> + </ItemGroup> + + <ItemGroup> + <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8"> + <PrivateAssets>all</PrivateAssets> + <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> + </PackageReference> + </ItemGroup> + </Project>