コード例 #1
0
        private ParsingError GenerateError(string data, string codeFileName, int line, int column, string rest)
        {
            ParsingError error;
            TextSpan     textSpan;

            if (_grammarCodeMapping.TryGetValue(codeFileName, out List <TextSpanMapping> textSpanMappings))
            {
                string grammarFileName = GetGrammarFromCodeFileName(_currentRuntimeInfo, codeFileName);
                textSpan = TextHelpers.GetSourceTextSpanForLine(textSpanMappings, line, grammarFileName);
                error    = new ParsingError(textSpan, $"{grammarFileName}:{textSpan.GetLineColumn().BeginLine}:{rest}", WorkflowStage.ParserCompilied);
            }
            else
            {
                Dictionary <string, CodeSource> grammarFilesData = _result.ParserGeneratedState.GrammarCheckedState.GrammarFilesData;
                CodeSource codeSource =
                    grammarFilesData.FirstOrDefault(file => file.Key.EndsWith(codeFileName, StringComparison.OrdinalIgnoreCase)).Value;

                textSpan = codeSource != null
                    ? new LineColumnTextSpan(line, column, codeSource).GetTextSpan()
                    : TextSpan.Empty;
                error = new ParsingError(textSpan, data, WorkflowStage.ParserCompilied);
            }

            return(error);
        }
コード例 #2
0
        private void AddCSharpError(string data)
        {
            if (data.Contains(": error CS"))
            {
                var          errorString = Helpers.FixEncoding(data);
                ParsingError error;
                CodeSource   grammarSource = CodeSource.Empty;
                try
                {
                    // Format:
                    // Lexer.cs(106,11): error CS0103: The  name 'a' does not exist in the current context
                    var    strs             = errorString.Split(':');
                    int    leftParenInd     = strs[0].IndexOf('(');
                    string codeFileName     = strs[0].Remove(leftParenInd);
                    string grammarFileName  = GetGrammarFromCodeFileName(_currentRuntimeInfo, codeFileName);
                    string lineColumnString = strs[0].Substring(leftParenInd);
                    lineColumnString = lineColumnString.Substring(1, lineColumnString.Length - 2); // Remove parenthesis.
                    var    strs2  = lineColumnString.Split(',');
                    int    line   = int.Parse(strs2[0]);
                    int    column = int.Parse(strs2[1]);
                    string rest   = string.Join(":", strs.Skip(1));

                    error = GenerateError(data, codeFileName, line, column, rest);
                }
                catch
                {
                    error = new ParsingError(errorString, grammarSource, WorkflowStage.ParserCompilied);
                }
                AddError(error);
            }
        }
コード例 #3
0
ファイル: AntlrErrorListener.cs プロジェクト: ag-csharp/DAGE
        public void SyntaxError(IRecognizer recognizer, int offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e)
        {
            var message     = FormatErrorMessage(line, charPositionInLine, msg);
            var parserError = new ParsingError(line, charPositionInLine, message, CodeSource, WorkflowStage.GrammarChecked);

            ErrorEvent?.Invoke(this, parserError);
        }
コード例 #4
0
        private void ParserGeneration_ErrorDataReceived(object sender, DataReceivedEventArgs e)
        {
            if (!string.IsNullOrEmpty(e.Data) && !e.IsIgnoreJavaError())
            {
                var strs = e.Data.Split(':');
                int line = 1, column = 1;

                int locationIndex = strs.Length > 2 && strs[2].Length > 0 && strs[2][0] == '\\' ? 3 : 2;
                if (strs.Length > locationIndex)
                {
                    if (!int.TryParse(strs[locationIndex], out line))
                    {
                        line = 1;
                    }
                    if (strs.Length > locationIndex + 1)
                    {
                        if (!int.TryParse(strs[locationIndex + 1], out column))
                        {
                            column = 1;
                        }
                    }
                }
                ParsingError error = new ParsingError(line, column, e.Data, _currentGrammarSource, WorkflowStage.ParserGenerated);
                if (strs.Length > 0 && strs[0].StartsWith("warning"))
                {
                    error.IsWarning = true;
                }
                ErrorEvent?.Invoke(this, error);
                _result.Errors.Add(error);
            }
        }
コード例 #5
0
        public void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e)
        {
            var message    = Helpers.FormatErrorMessage(CodeSource, line, charPositionInLine, msg);
            var textSpan   = TextSpan.FromBounds(offendingSymbol.StartIndex, offendingSymbol.StopIndex + 1, CodeSource);
            var lexerError = new ParsingError(textSpan, message, WorkflowStage.GrammarChecked);

            ErrorEvent?.Invoke(this, lexerError);
        }
コード例 #6
0
        private void AddJavaError(string data)
        {
            if (data.Count(c => c == ':') >= 2)
            {
                ParsingError error;
                try
                {
                    // Format:
                    // Lexer.java:98: error: cannot find symbol
                    string[] strs = data.Split(':');

                    string rest = string.Join(":", strs.Skip(2));
                    if (rest.Contains("warning: [deprecation] ANTLRInputStream"))
                    {
                        return;
                    }

                    string codeFileName = strs[0];
                    if (int.TryParse(strs[1], out int codeLine))
                    {
                        bool isWarning = strs[2].Trim() == "warning";
                        error           = GenerateError(data, codeFileName, codeLine, 1, rest);
                        error.IsWarning = isWarning;
                    }
                    else
                    {
                        error = null;
                    }
                }
                catch
                {
                    error = null;
                }

                if (error == null)
                {
                    error = new ParsingError(data, CodeSource.Empty, WorkflowStage.ParserCompilied);
                }

                AddError(error);
            }
            else
            {
                //AddError(new ParsingError(TextSpan.Empty, data, WorkflowStage.ParserCompilied));
            }
        }
コード例 #7
0
 private void AddError(ParsingError error)
 {
     ErrorEvent?.Invoke(this, error);
     _result.Errors.Add(error);
 }