Exemple #1
0
        private void AddJavaScriptError()
        {
            //Absolute\Path\To\LexerOrParser.js:68
            //                break;
            //                ^^^^^
            //
            //SyntaxError: Unexpected token break
            //    at exports.runInThisContext (vm.js:53:16)
            //    at Module._compile (module.js:373:25)
            //    at Object.Module._extensions..js (module.js:416:10)
            //    at Module.load (module.js:343:32)
            //    at Function.Module._load (module.js:300:12)
            //    at Module.require (module.js:353:17)
            //    at require (internal/module.js:12:17)
            //    at Object.<anonymous> (Absolute\Path\To\AntlrJavaScriptTest.js:1:85)
            //    at Module._compile (module.js:409:26)
            //    at Object.Module._extensions..js (module.js:416:10)
            string   message         = "";
            string   grammarFileName = "";
            TextSpan errorSpan       = TextSpan.Empty;

            try
            {
                int    semicolonLastIndex = _buffer[0].LastIndexOf(':');
                string codeFileName       = Path.GetFileName(_buffer[0].Remove(semicolonLastIndex));
                if (_grammarCodeMapping.TryGetValue(codeFileName, out List <TextSpanMapping> mapping))
                {
                    int codeLine = int.Parse(_buffer[0].Substring(semicolonLastIndex + 1));
                    grammarFileName = GetGrammarFromCodeFileName(RuntimeInfo.Runtimes[Runtime.JavaScript], codeFileName);
                    errorSpan       = TextHelpers.GetSourceTextSpanForLine(mapping, codeLine, grammarFileName);
                }
            }
            catch
            {
            }
            if (_buffer.Count > 0)
            {
                message = _buffer.LastOrDefault(line => !line.StartsWith("    at")) ?? "";
            }
            string finalMessage = "";

            if (grammarFileName != "")
            {
                finalMessage = grammarFileName + ":";
            }
            if (!errorSpan.IsEmpty)
            {
                finalMessage += errorSpan.GetLineColumn().BeginLine + ":";
            }
            finalMessage += message == "" ? "Unknown Error" : message;
            AddError(new ParsingError(errorSpan, finalMessage, WorkflowStage.ParserCompilied));
        }
Exemple #2
0
 private void AddGoError(string data)
 {
     if (data.Contains(": syntax error:"))
     {
         // Format:
         // .\newgrammar_parser.go:169: syntax error: unexpected semicolon or newline, expecting expression
         string   grammarFileName = "";
         TextSpan errorSpan       = TextSpan.Empty;
         string   message         = "";
         var      strs            = data.Split(':');
         try
         {
             string codeFileName = strs[0].Substring(2);
             if (_grammarCodeMapping.TryGetValue(codeFileName, out var mapping))
             {
                 int codeLine = int.Parse(strs[1]);
                 grammarFileName = GetGrammarFromCodeFileName(RuntimeInfo.Runtimes[Runtime.Go], codeFileName);
                 errorSpan       = TextHelpers.GetSourceTextSpanForLine(mapping, codeLine, grammarFileName);
             }
             message = strs[3];
         }
         catch
         {
         }
         string finalMessage = "";
         if (grammarFileName != "")
         {
             finalMessage = grammarFileName + ":";
         }
         if (!errorSpan.IsEmpty)
         {
             finalMessage += errorSpan.GetLineColumn().BeginLine + ":";
         }
         finalMessage += message == "" ? "Unknown Error" : message;
         AddError(new ParsingError(errorSpan, finalMessage, WorkflowStage.ParserCompilied));
     }
     else
     {
         AddError(new ParsingError(TextSpan.Empty, data, WorkflowStage.ParserCompilied));
     }
 }
Exemple #3
0
        private void AddPythonError()
        {
            //Format:
            //Traceback(most recent call last):
            //  File "AntlrPythonCompileTest.py", line 1, in < module >
            //    from NewGrammarLexer import NewGrammarLexer
            //  File "Absolute\Path\To\LexerOrParser.py", line 23
            //    decisionsToDFA = [DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ]
            //    ^
            //IndentationError: unexpected indent
            string   message         = "";
            string   grammarFileName = "";
            TextSpan errorSpan       = TextSpan.Empty;

            for (int i = 0; i < _buffer.Count; i++)
            {
                if (_buffer[i].TrimStart().StartsWith("File"))
                {
                    if (grammarFileName != "")
                    {
                        continue;
                    }

                    string codeFileName = _buffer[i];
                    codeFileName = codeFileName.Substring(codeFileName.IndexOf('"') + 1);
                    codeFileName = codeFileName.Remove(codeFileName.IndexOf('"'));
                    codeFileName = Path.GetFileName(codeFileName);

                    List <TextSpanMapping> mapping;
                    if (_grammarCodeMapping.TryGetValue(codeFileName, out mapping))
                    {
                        try
                        {
                            var lineStr = "\", line ";
                            lineStr = _buffer[i].Substring(_buffer[i].IndexOf(lineStr) + lineStr.Length);
                            int commaIndex = lineStr.IndexOf(',');
                            if (commaIndex != -1)
                            {
                                lineStr = lineStr.Remove(commaIndex);
                            }
                            int codeLine = int.Parse(lineStr);
                            grammarFileName = GetGrammarFromCodeFileName(RuntimeInfo.Runtimes[Runtime.Python2], codeFileName);
                            errorSpan       = TextHelpers.GetSourceTextSpanForLine(mapping, codeLine, grammarFileName);
                        }
                        catch
                        {
                        }
                    }
                    else
                    {
                        grammarFileName = "";
                    }
                }
                else if (i == _buffer.Count - 1)
                {
                    message = _buffer[i].Trim();
                }
            }
            string finalMessage = "";

            if (grammarFileName != "")
            {
                finalMessage = grammarFileName + ":";
            }
            if (!errorSpan.IsEmpty)
            {
                finalMessage += errorSpan.GetLineColumn().BeginLine + ":";
            }
            finalMessage += message == "" ? "Unknown Error" : message;
            AddError(new ParsingError(errorSpan, finalMessage, WorkflowStage.ParserCompilied));
        }