public void Generate(CompilationUnit compilationUnit, ColumnsLayout columns = ColumnsLayout.FreeTextFormat) { Destination.Append(""); //Add version to output file if (!string.IsNullOrEmpty(TypeCobolVersion)) { Destination.AppendLine(" *TypeCobol_Version:" + TypeCobolVersion); } var sourceFile = compilationUnit.ProgramClassDocumentSnapshot.Root; sourceFile.AcceptASTVisitor(new ExportToDependency()); var lines = sourceFile.SelfAndChildrenLines; foreach (var textLine in lines) { if (textLine is TextLineSnapshot) { var test = CobolTextLine.Create(textLine.Text, ColumnsLayout.CobolReferenceFormat); Destination.AppendLine(test.First().Text); } else { Destination.AppendLine(textLine.Text); } } }
/// <summary> /// Produce an indented version of a text line. The indentation depends on the current Layout format /// ColumnsLayout.CobolReferenceFormat or ColumnsLayout.FreeTextFormat. /// </summary> /// <param name="line">The text line to be produced an indented version</param> /// <param name="isComment">if null then this is the identity function, if true a commented line is produced, otherwise an uncommented line is produced.</param> /// <returns>The idented line</returns> private IEnumerable <ITextLine> Indent(ITextLine line, bool?isComment) { var results = new List <ITextLine>(); var cobol = line as CobolTextLine; if (cobol != null) { if (Layout == ColumnsLayout.CobolReferenceFormat) { results.Add(SetComment(line, isComment)); } else if (Layout == ColumnsLayout.FreeTextFormat) { results.Add(SetComment(new TextLineSnapshot(-1, cobol.SourceText ?? "", null), isComment)); } else { throw new System.NotImplementedException("Unsuported columns layout: " + Layout); } } else { if (Layout == ColumnsLayout.CobolReferenceFormat) { var lines = CobolTextLine.Create(line.Text, Layout, line.LineIndex); foreach (var l in lines) { results.Add(SetComment(l, isComment)); } } else if (Layout == ColumnsLayout.FreeTextFormat) { results.Add(SetComment(line, isComment)); } else { throw new System.NotImplementedException("Unsuported columns layout: " + Layout); } } if (results.Count < 1) { throw new System.NotImplementedException("Unsuported ITextLine type: " + line.GetType()); } return(results); }
/// <summary> /// Produces a commented text line of a text line /// </summary> /// <param name="line">The text line to be procuded a commented text line </param> /// <returns>The commente dtext line</returns> private static ITextLine Comment(ITextLine line) { var cobol = line as CobolTextLine; if (cobol != null) { StringBuilder text = new StringBuilder(cobol.Text); text[6] = '*'; var lines = CobolTextLine.Create("*" + cobol.SourceText, cobol.ColumnsLayout, cobol.InitialLineIndex); foreach (var l in lines) { return(l); // there's only one in the collection } throw new System.NotImplementedException("I should have at least one item!"); } else { return(new TextLineSnapshot(line.InitialLineIndex, "*" + line.Text, null)); } }
/// <summary> /// Produces an uncommented text line from a commented text line /// </summary> /// <param name="line">The text line to produce the uncommented text line.</param> /// <returns>The uncommented text line</returns> private static ITextLine Uncomment(ITextLine line) { var cobol = line as CobolTextLine; if (cobol != null) { StringBuilder text = new StringBuilder(cobol.Text); text[6] = ' '; var lines = CobolTextLine.Create(text.ToString(), cobol.ColumnsLayout, cobol.LineIndex); foreach (var l in lines) { return(l);// there's only one in the collection } throw new System.NotImplementedException("I should have at least one item!"); } else { StringBuilder text = new StringBuilder(line.Text); int index = line.Text.IndexOf('*'); text[index] = ' '; return(new TextLineSnapshot(line.LineIndex, text.ToString(), null)); } }