private void GenerateCode() { LogTextBox.Text = ""; var dfm = _dfmTextArea.Text; _codeTextArea.ClearAll(); Logger.WriteLn("Code generation beginning..." + Environment.NewLine); if (string.IsNullOrWhiteSpace(dfm)) { Logger.WriteLn("Dfm is empty, nothing to do."); return; } try { var tokens = Tokenizer.Execute(dfm); var dfmObject = DfmParser.Execute(tokens); var code = CodeGen.Execute(dfmObject); _codeTextArea.Text = code; } catch (Exception e) { Logger.OnLog($"Error occured during processing:{Environment.NewLine}{e}"); } }
public void Given_Dfm_Should_Produce_Code() { var tokens = Tokenizer.Execute(Dfm); var dfmObject = DfmParser.Execute(tokens); var code = CodeGen.Execute(dfmObject); Assert.AreEqual(ExpectedCode.Trim(), code.Trim()); }
public void Given_Tokens_Should_Build_DfmObjects() { var tokens = Tokenizer.Execute(Dfm.Trim()); var dfmObject = DfmParser.Execute(tokens); Assert.AreEqual("Rectangle1", dfmObject.Name); Assert.AreEqual("TRectangle", dfmObject.Type); Assert.IsTrue(dfmObject.HasProperties); Assert.AreEqual(recProps.Count, dfmObject.PropertyCount); for (var i = 0; i < recProps.Count; ++i) { var recProp = recProps[i]; var dfmProp = dfmObject.Properties[i]; Assert.AreEqual(recProp.Name, dfmProp.Name); Assert.AreEqual(recProp.Value, dfmProp.Value); Assert.AreEqual(recProp.LineNumber, dfmProp.LineNumber); } Assert.IsTrue(dfmObject.HasObjects); Assert.AreEqual(1, dfmObject.ObjectCount); dfmObject = dfmObject.Objects[0]; Assert.AreEqual("Text2", dfmObject.Name); Assert.AreEqual("TText", dfmObject.Type); Assert.IsTrue(dfmObject.HasProperties); Assert.AreEqual(txtProps.Count, dfmObject.PropertyCount); for (var i = 0; i < txtProps.Count; ++i) { var txtProp = txtProps[i]; var dfmProp = dfmObject.Properties[i]; Assert.AreEqual(txtProp.Name, dfmProp.Name); Assert.AreEqual(txtProp.Value, dfmProp.Value); Assert.AreEqual(txtProp.LineNumber, dfmProp.LineNumber); } }