public static void PerformCompilerTest(bool generateComments = false) { #if (!CI) PrintTestScenario(); #endif var compilerParameters = CreateCompilerParameters(generateComments); var compiler = new SyntactikCompiler(compilerParameters); var context = compiler.Run(); //Compiler Error Assertions string serialParserErrors; var recordedParserErros = LoadSavedCompilerErrors(context.Errors, out serialParserErrors); if (recordedParserErros != null) { #if (!CI) TestContext.WriteLine("Compiler Errors:"); TestContext.WriteLine(serialParserErrors); #endif Assert.AreEqual(recordedParserErros, serialParserErrors); } else { #if (!CI) TestContext.WriteLine("Compiler Errors:"); TestContext.WriteLine(serialParserErrors); #endif Assert.IsTrue(context.Errors.Count == 0, "Compiler has errors"); } if (IsRecordedTest() || IsRecordTest()) { CompareResultAndRecordedFiles(IsRecordTest()); } }
public static int Main(string[] args) { AppInfo(); var result = 1; try { ArgumentsParser.Parse(args, out var files, out var convert, out bool _, out var outputDirectory); if (!convert) { var compilerParameters = GetCompilerParameters(files, outputDirectory); var compiler = new SyntactikCompiler(compilerParameters); var context = compiler.Run(); if (context.Errors.Count > 0) { PrintCompilerErrors(context.Errors); return(1); } } else { foreach (var file in files) { if (file.EndsWith(".xml")) { string s = ConvertXml(File.ReadAllText(file), 0, ' ', 2); File.WriteAllText(Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(file) + ".s4x"), s); } else if (file.EndsWith(".json")) { string s = ConvertJson(File.ReadAllText(file), 0, ' ', 2); File.WriteAllText(Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(file) + ".s4j"), s); } } } result = 0; } catch (ArgumentsParserException e) { Console.WriteLine("Fatal error: {0}", e.Message); ArgumentsParser.Help(); AppInfo2(); } catch (Exception e) { Console.WriteLine("Fatal error: {0}", e.Message); Console.WriteLine(e.StackTrace); } return(result); }
private void SourceTextBox_TextChanged(object sender, EventArgs e) { if (sourceTextBox.Text != string.Empty) { Clipboard.SetText(sourceTextBox.Text); } if (modeStripDropDownButton.Text == @"PAIR") { var module = new Module { Name = "Module", Value = null, FileName = "" }; var parser = new Parser(new InputStream(sourceTextBox.Text), new PairFactory(), module); //var parser = new Parser(new InputStream(((RichTextBox) sender).Text)); var errorListener = new ErrorListener(); parser.ErrorListeners.Add(errorListener); try { var printer = new DomPrinter(); printer.Visit(parser.ParseModule("")); domTextBox.Text = printer.Text; errorsTextBox.Text = string.Join(Environment.NewLine, errorListener.Errors.ToArray()); } catch (Exception exception) { errorsTextBox.Text = exception.ToString(); } } else { var outputName = modeStripDropDownButton.Text == @"XML" ? "main.s4x" : "main.s4j"; var compilerParameters = CreateCompilerParameters(outputName); var compiler = new SyntactikCompiler(compilerParameters); var context = compiler.Run(); if (context.InMemoryOutputObjects.Count >= 1) { var sb = new StringBuilder(); foreach (var item in context.InMemoryOutputObjects) { sb.Append(item.Key).AppendLine(":").AppendLine(item.Value.ToString()); } domTextBox.Text = sb.ToString(); } else { domTextBox.Text = ""; } errorsTextBox.Text = SerializeErrors(context.Errors); } }
public static int Main(string[] args) { AppInfo(); var result = 1; try { bool recursive; List <string> files; string outputDirectory; ArgumentsParser.Parse(args, out files, out recursive, out outputDirectory); var compilerParameters = GetCompilerParameters(files, outputDirectory); var compiler = new SyntactikCompiler(compilerParameters); var context = compiler.Run(); if (context.Errors.Count > 0) { PrintCompilerErrors(context.Errors); } result = 0; } catch (ArgumentsParserException e) { Console.WriteLine("Fatal error: {0}", e.Message); ArgumentsParser.Help(); AppInfo2(); } catch (Exception e) { Console.WriteLine("Fatal error: {0}", e.Message); Console.WriteLine(e.StackTrace); } return(result); }