Пример #1
0
        public static void CheckAllFilesForExceptions()
        {
            CompilationProject project = new CompilationProject("test",
                                                                PlatformUtils.GetPathForProjectFile(@"Compiler\Scanner\Samples"), new string[] { ".txt" },
                                                                IBMCodePages.GetDotNetEncodingFromIBMCCSID(1147), EndOfLineDelimiter.FixedLengthLines, 80, ColumnsLayout.CobolReferenceFormat, new TypeCobolOptions());

            //int filesCount = 0;
            //int linesCount = 0;
            //Stopwatch chrono = new Stopwatch();
            foreach (string fileName in PlatformUtils.ListFilesInSubdirectory(@"Compiler\Scanner\Samples"))
            {
                string textName = Path.GetFileNameWithoutExtension(fileName);

                // Initialize a CompilationDocument
                FileCompiler compiler = new FileCompiler(null, textName, project.SourceFileProvider, project, ColumnsLayout.CobolReferenceFormat, new TypeCobolOptions(), null, true, project);

                // Start compilation
                try
                {
                    //chrono.Start();
                    compiler.CompileOnce();
                    //chrono.Stop();
                }
                catch (Exception e)
                {
                    throw new Exception("Error while scanning file " + fileName, e);
                }

                // Stats
                //filesCount++;
                //linesCount += compiler.CompilationResultsForCopy.TokensDocumentSnapshot.Lines.Count;
                //string result = compiler.CompilationResultsForCopy.TokensDocumentSnapshot.GetDebugString();
            }
            // throw new Exception("Test OK for " + filesCount + " files and " + linesCount + " lines : " + chrono.ElapsedMilliseconds + " ms");
        }
Пример #2
0
        public static void Check_GetDotNetEncoding()
        {
            Encoding encoding1 = IBMCodePages.GetDotNetEncodingFromIBMCCSID(1147);

            if (encoding1.EncodingName != "IBM EBCDIC (France-Euro)")
            {
                throw new Exception(".Net encoding \"IBM EBCDIC (France-Euro)\" was expected");
            }

            Encoding encoding2 = IBMCodePages.GetDotNetEncodingFromIBMCCSID(1200);

            if (encoding2.EncodingName != "Unicode")
            {
                throw new Exception(".Net encoding \"Unicode\" was expected");
            }
        }
Пример #3
0
        public static void Check_IsEBCDICCodePage()
        {
            Encoding encoding1 = IBMCodePages.GetDotNetEncodingFromIBMCCSID(1148);
            bool     isEBCDIC1 = IBMCodePages.IsEBCDICCodePage(encoding1);

            if (!isEBCDIC1)
            {
                throw new Exception("Encoding 1148 should be detected as EBCDIC");
            }

            Encoding encoding2 = IBMCodePages.GetDotNetEncodingFromIBMCCSID(1252);
            bool     isEBCDIC2 = IBMCodePages.IsEBCDICCodePage(encoding2);

            if (isEBCDIC2)
            {
                throw new Exception("Encoding 1252 should not be detected as EBCDIC");
            }
        }
Пример #4
0
        public static void Check_DBCSCodePageNotSupported()
        {
            bool exceptionOK = false;

            try
            {
                Encoding encoding = IBMCodePages.GetDotNetEncodingFromIBMCCSID(930);
            }
            catch (Exception e)
            {
                if (e is NotSupportedException)
                {
                    exceptionOK = true;
                }
            }
            if (!exceptionOK)
            {
                throw new Exception("IBMCodePages should throw exception to ensure that no EBCDIC DBCS character set is used");
            }
        }
Пример #5
0
        /// <summary>
        /// Loads the content of a source file in the editor
        /// </summary>
        public TypeCobolEditor(CobolFile sourceFile)
        {
            TextView textView = TextArea.TextView;

            // Default text style
            FontFamily = new FontFamily("Consolas");
            FontSize   = 13;

            // Show line numbers
            ShowLineNumbers = true;

            // Activate search box
            SearchPanel.Install(this);

            // Plug in TypeCobol syntax highlighting
            syntaxHighlighter = new SyntaxHighlighter();
            textView.LineTransformers.Add(syntaxHighlighter);

            // Plug in TypeCobol error marker
            errorMarker = new ErrorMarker(this);
            textView.BackgroundRenderers.Add(errorMarker);
            textView.LineTransformers.Add(errorMarker);

            // Tooltip management
            tooltipManager               = new TooltipManager(this, errorMarker);
            textView.MouseHover         += tooltipManager.MouseHover;
            textView.MouseHoverStopped  += tooltipManager.MouseHoverStopped;
            textView.VisualLinesChanged += tooltipManager.VisualLinesChanged;

            // Initial load of the cobol file if necessary
            if (sourceFile != null)
            {
                Document = new ICSharpCode.AvalonEdit.Document.TextDocument(sourceFile.ReadChars());
            }

            // Wrap the AvalonEdit.Document in a ITextDocument interface
            textDocument = new AvalonEditTextDocument(Document, IBMCodePages.GetDotNetEncodingFromIBMCCSID(1147), ColumnsLayout.CobolReferenceFormat);
        }
Пример #6
0
        private static IList <Tuple <string, bool> > Split(string line, int max, int min)
        {
            var lines = new List <Tuple <string, bool> >();
            int nLine = (line.Length / max) + ((line.Length % max) != 0 ? 1 : 0);

            if (nLine == 1)
            {
                lines.Add(new Tuple <string, bool>(line, false));
                return(lines);
            }
            if (line.Length < 1)
            {
                lines.Add(new Tuple <string, bool>(line, false));
            }
            else
            {
                for (int i = 0; i < line.Length; i += (i == 0 ? max : min))
                {
                    lines.Add(new Tuple <string, bool>(line.Substring(i, Math.Min((i == 0 ? max : min), line.Length - i)), true));
                }
            }
            TokensLine tempTokensLine = TokensLine.CreateVirtualLineForInsertedToken(0, line);

            tempTokensLine.InitializeScanState(new MultilineScanState(false, false, false, IBMCodePages.GetDotNetEncodingFromIBMCCSID(1147)));

            Scanner.Scanner scanner          = new Scanner.Scanner(line, 0, line.Length - 1, tempTokensLine, null, false);
            Token           t                = null;
            int             nCurLength       = 0;
            int             nSpan            = max;
            int             index            = 0;
            bool            bNextNoIndicator = false;

            while ((t = scanner.GetNextToken()) != null)
            {
                nCurLength += t.Length;
                if (nCurLength >= nSpan)
                {
                    if (t.TokenFamily == TokenFamily.Whitespace || (nCurLength == nSpan))
                    {
                        bNextNoIndicator = true;
                    }
                    nSpan += min;
                    index++;
                }
                else if (bNextNoIndicator)
                {
                    lines[index]     = new Tuple <string, bool>(lines[index].Item1, false);
                    bNextNoIndicator = false;
                }
            }
            return(lines);
        }