-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
95 lines (76 loc) · 3 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using MiKoSolutions.SemanticParsers.CSharp.Yaml;
using SystemFile = System.IO.File;
namespace MiKoSolutions.SemanticParsers.CSharp
{
public static class Program
{
private static readonly Guid InstanceId = Guid.NewGuid();
/// <summary>
/// Console input:
/// 1. "input file"
/// 2. "encoding"
/// 3. "output file"
/// 4. "end" -> ends session
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
public static async Task<int> Main(string[] args)
{
// check for GMaster or PlasticSCM or SemanticMerge arguments (to allow debugging without the tools)
if (args.Length == 2)
{
var shell = args[0]; // reserved for future usage
var flagFile = args[1];
SystemFile.WriteAllBytes(flagFile, new byte[] { 0x42 });
}
var watch = Stopwatch.StartNew();
while (true)
{
var inputFile = await Console.In.ReadLineAsync();
if (inputFile is null || "end".Equals(inputFile, StringComparison.OrdinalIgnoreCase))
{
// session is done
Tracer.Trace($"Terminating as session was ended (instance {InstanceId:B})");
return 0;
}
var encodingToUse = await Console.In.ReadLineAsync();
var outputFile = await Console.In.ReadLineAsync();
try
{
var parseErrors = false;
try
{
watch.Restart();
// SystemFile.Copy(inputFile, $@"z:\{Path.GetFileName(inputFile)}", true);
var file = Parser.Parse(inputFile, encodingToUse);
using (var writer = SystemFile.CreateText(outputFile))
{
YamlWriter.Write(writer, file);
}
parseErrors = file.ParsingErrorsDetected is true;
if (parseErrors)
{
var parsingError = file.ParsingErrors[0];
Tracer.Trace(parsingError.ErrorMessage);
Tracer.Trace(parsingError.Location);
}
Console.WriteLine(parseErrors ? "KO" : "OK");
}
finally
{
Tracer.Trace($"Parsing took {watch.Elapsed:s\\.fff} secs (instance {InstanceId:B}), errors found: {parseErrors}");
}
}
catch (Exception ex)
{
Tracer.Trace($"Exception: {ex}", ex);
Console.WriteLine("KO");
return 0;
}
}
}
}
}