예제 #1
0
        private void HandleParsingErrors(OperationCanceledException ex, ParsingExceptionCollector collector, ScriptCompilerLogger logger)
        {
            StringBuilder sb = new StringBuilder();

            ParsingExceptionInformation[] errors = collector.GetExceptions().ToArray();
            int counter = errors.Length <= 10 ? errors.Length : 10;

            for (int i = 0; i < counter; i++)
            {
                string errorMessage = $"{i + 1}: {errors[i].Message}, Line: {errors[i].Line}, Column: {errors[i].Column}";
                sb.AppendLine(errorMessage);
                logger.Error("Parsing Error " + errorMessage);
            }

            var _ = MetroMessageBox.Show("Parsing Failed", sb.ToString(), MetroMessageBox.MessageBoxButtons.Ok);

            if (txtScript.TextArea.Focus())
            {
                // Go to the first error.
                var firstError = errors[0];
                if (firstError.Exception != null && firstError.Exception.OffendingToken != null)
                {
                    txtScript.Select(firstError.Exception.OffendingToken.StartIndex, firstError.Exception.OffendingToken.StopIndex + 1 - firstError.Exception.OffendingToken.StartIndex);
                }
                else
                {
                    txtScript.TextArea.Caret.Offset = txtScript.Document.GetOffset(firstError.Line, firstError.Column);
                }
                txtScript.ScrollToLine(firstError.Line);
            }
        }
예제 #2
0
        private void HandleCompilerErrors(CompilerException ex, ScriptCompilerLogger logger)
        {
            logger.Error(ex);
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(ex.Message);
            sb.AppendLine();
            sb.AppendLine($"Text: \"{ex.Text}\"");
            sb.AppendLine("Line: " + ex.Line);
            sb.AppendLine("Column: " + ex.Column);
            var _ = MetroMessageBox.Show("Compilation Failed", sb.ToString(), MetroMessageBox.MessageBoxButtons.Ok);

            if (txtScript.TextArea.Focus())
            {
                txtScript.TextArea.Caret.Offset = txtScript.Document.GetOffset(ex.Line, ex.Column);
                txtScript.ScrollToLine(ex.Line);
            }
        }