Merge MVP features #1
31
Program.cs
31
Program.cs
@ -38,9 +38,34 @@ namespace XNeedle
|
||||
// Auto-discover operations via reflection
|
||||
BangOperation.RegisterAll();
|
||||
|
||||
var xnSource = XnParser.StripComments(File.ReadAllText(opts.XnDefinition));
|
||||
Console.WriteLine(xnSource);
|
||||
var masterRule = (Rule)XnParser.RuleObject.Parse(xnSource);
|
||||
var rawSource = File.ReadAllText(opts.XnDefinition);
|
||||
var xnSource = XnParser.StripComments(rawSource);
|
||||
Rule masterRule;
|
||||
try
|
||||
{
|
||||
masterRule = (Rule)XnParser.RuleObject.Parse(xnSource);
|
||||
}
|
||||
catch (ParseException ex)
|
||||
{
|
||||
var lines = rawSource.Split('\n');
|
||||
int line = ex.Position?.Line ?? -1;
|
||||
int col = ex.Position?.Column ?? -1;
|
||||
bool showPosition = (line != -1) && (col != -1);
|
||||
|
||||
if (showPosition)
|
||||
{
|
||||
Console.Error.WriteLine($"{opts.XnDefinition}({line},{col}): parse error: {ex.Message}");
|
||||
var srcLine = line <= lines.Length ? lines[line - 1].TrimEnd() : "";
|
||||
var pointer = new string(' ', Math.Max(0, col - 1)) + "^";
|
||||
Console.Error.WriteLine($" {srcLine}");
|
||||
Console.Error.WriteLine($" {pointer}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Error.WriteLine($"{opts.XnDefinition}: parse error: {ex.Message}");
|
||||
}
|
||||
return;
|
||||
}
|
||||
var doc = XDocument.Load(opts.Input, LoadOptions.PreserveWhitespace);
|
||||
var encoding = XmlRoundtripWriter.DetectEncoding(File.ReadAllBytes(opts.Input));
|
||||
var sloc = new SourceLocation(opts.Input, encoding);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user