Esempio n. 1
0
        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);
                }
            }
        }
Esempio n. 2
0
        /// <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);
        }
Esempio n. 3
0
 /// <summary>
 /// Insert in the buffer a text line that can be split.
 /// </summary>
 /// <param name="text">The text</param>
 /// <param name="from">from position in the buffer</param>
 /// <param name="to">to position in the buffer</param>
 /// <param name="bInsertSplit">true if splitting must handle, false otherwise</param>
 private void InsertLineMaybeSplit(SourceText buffer, string text, int from, int to, bool bInsertSplit)
 {
     if (bInsertSplit && this.Layout == ColumnsLayout.CobolReferenceFormat)
     {
         int crPos = text.LastIndexOf('\r');
         int lfPos = text.LastIndexOf('\n');
         int crlf  = 0;
         crlf += crPos >= 0 ? 1 : 0;
         crlf += lfPos >= 0 ? 1 : 0;
         int lineStartOffset;
         int lineEndOffset;
         int lineLen = buffer.GetLineInfo(from, out lineStartOffset, out lineEndOffset);
         if (((from - lineStartOffset) + (text.Length - crlf)) >= LEGAL_COBOL_LINE_LENGTH)
         {
             string lefttext = buffer.GetTextAt(lineStartOffset, from);
             ICollection <ITextLine> lines = CobolTextLine.CreateCobolLines(this.Layout, -1, ' ', "",
                                                                            lefttext + (crlf > 0 ? text.Substring(0, text.Length - crlf) : text), LEGAL_COBOL_LINE_LENGTH, 65, false);
             StringWriter sw  = new StringWriter();
             string       sep = "";
             foreach (var line in lines)
             {
                 sw.Write(sep);
                 sw.WriteLine(line.Text);
                 sep = Environment.NewLine;
             }
             //We must insert "\r\n" if the target line is empty and the inserted test has one.
             if ((lineEndOffset == lineStartOffset) && crlf > 0)
             {
                 sw.Write(Environment.NewLine);
             }
             sw.Flush();
             text = sw.ToString();
             buffer.Insert(text, lineStartOffset, to);
         }
         else
         {
             buffer.Insert(text, from, to);
         }
     }
     else
     {
         buffer.Insert(text, from, to);
     }
 }
Esempio n. 4
0
        /// <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));
            }
        }
Esempio n. 5
0
        /// <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));
            }
        }
Esempio n. 6
0
 public TextChangeMap(TextChange change, ColumnsLayout columnsLayout) :
     base(change.Type, change.LineIndex, change.NewLine)
 {
     NewLineMap = new CobolTextLine(NewLine, columnsLayout);
 }