コード例 #1
0
        public virtual void Warning(ANTLRMessage msg)
        {
            Template msgST = tool.errMgr.GetMessageTemplate(msg);
            string outputMsg = msgST.Render();
            if (tool.errMgr.FormatWantsSingleLineMessage())
            {
                outputMsg = outputMsg.Replace('\n', ' ');
            }

            Console.Error.WriteLine(outputMsg);
        }
コード例 #2
0
        public virtual void Warning(ANTLRMessage msg)
        {
            Template msgST     = tool.errMgr.GetMessageTemplate(msg);
            string   outputMsg = msgST.Render();

            if (tool.errMgr.FormatWantsSingleLineMessage())
            {
                outputMsg = outputMsg.Replace('\n', ' ');
            }

            tool.ConsoleError.WriteLine(outputMsg);
        }
コード例 #3
0
        public virtual Template GetMessageTemplate(ANTLRMessage msg)
        {
            Template messageST       = msg.GetMessageTemplate(tool.longMessages);
            Template locationST      = GetLocationFormat();
            Template reportST        = GetReportFormat(msg.GetErrorType().severity);
            Template messageFormatST = GetMessageFormat();

            bool locationValid = false;

            if (msg.line != -1)
            {
                locationST.Add("line", msg.line);
                locationValid = true;
            }
            if (msg.charPosition != -1)
            {
                locationST.Add("column", msg.charPosition);
                locationValid = true;
            }
            if (msg.fileName != null)
            {
                string f = msg.fileName;
                // Don't show path to file in messages; too long.
                string displayFileName = msg.fileName;
                if (File.Exists(f))
                {
                    displayFileName = Path.GetFileName(f);
                }
                locationST.Add("file", displayFileName);
                locationValid = true;
            }

            messageFormatST.Add("id", msg.GetErrorType().code);
            messageFormatST.Add("text", messageST);

            if (locationValid)
            {
                reportST.Add("location", locationST);
            }
            reportST.Add("message", messageFormatST);
            //((DebugST)reportST).inspect();
            //		reportST.impl.dump();
            return(reportST);
        }
コード例 #4
0
ファイル: ErrorManager.cs プロジェクト: sharwell/antlr4cs
        public virtual Template GetMessageTemplate(ANTLRMessage msg)
        {
            Template messageST = msg.GetMessageTemplate(tool.longMessages);
            Template locationST = GetLocationFormat();
            Template reportST = GetReportFormat(msg.GetErrorType().severity);
            Template messageFormatST = GetMessageFormat();

            bool locationValid = false;
            if (msg.line != -1)
            {
                locationST.Add("line", msg.line);
                locationValid = true;
            }
            if (msg.charPosition != -1)
            {
                locationST.Add("column", msg.charPosition);
                locationValid = true;
            }
            if (msg.fileName != null)
            {
                string f = msg.fileName;
                // Don't show path to file in messages; too long.
                string displayFileName = msg.fileName;
                if (File.Exists(f))
                {
                    displayFileName = Path.GetFileName(f);
                }
                locationST.Add("file", displayFileName);
                locationValid = true;
            }

            messageFormatST.Add("id", msg.GetErrorType().code);
            messageFormatST.Add("text", messageST);

            if (locationValid)
                reportST.Add("location", locationST);
            reportST.Add("message", messageFormatST);
            //((DebugST)reportST).inspect();
            //		reportST.impl.dump();
            return reportST;
        }
コード例 #5
0
        // S U P P O R T  C O D E

        public virtual void Emit(ErrorType etype, ANTLRMessage msg)
        {
            var severity = etype.severity;

            if (severity == ErrorSeverity.WARNING_ONE_OFF || severity == ErrorSeverity.WARNING)
            {
                if (severity == ErrorSeverity.WARNING || !errorTypes.Contains(etype))
                {
                    warnings++;
                    tool.Warning(msg);
                }
            }
            else if (severity == ErrorSeverity.ERROR_ONE_OFF || severity == ErrorSeverity.ERROR)
            {
                if (severity == ErrorSeverity.ERROR || !errorTypes.Contains(etype))
                {
                    errors++;
                    tool.Error(msg);
                }
            }

            errorTypes.Add(etype);
        }
コード例 #6
0
ファイル: ErrorManager.cs プロジェクト: sharwell/antlr4cs
        // S U P P O R T  C O D E

        public virtual void Emit(ErrorType etype, ANTLRMessage msg)
        {
            var severity = etype.severity;
            if (severity == ErrorSeverity.WARNING_ONE_OFF || severity == ErrorSeverity.WARNING)
            {
                if (severity == ErrorSeverity.WARNING || !errorTypes.Contains(etype))
                {
                    warnings++;
                    tool.Warning(msg);
                }
            }
            else if (severity == ErrorSeverity.ERROR_ONE_OFF || severity == ErrorSeverity.ERROR)
            {
                if (severity == ErrorSeverity.ERROR || !errorTypes.Contains(etype))
                {
                    errors++;
                    tool.Error(msg);
                }
            }

            errorTypes.Add(etype);
        }
コード例 #7
0
ファイル: AntlrTool.cs プロジェクト: sharwell/antlr4cs
        public virtual void Warning(ANTLRMessage msg)
        {
            if (listeners.Count == 0)
            {
                defaultListener.Warning(msg);
            }
            else
            {
                foreach (ANTLRToolListener l in listeners)
                    l.Warning(msg);
            }

            if (warnings_are_errors)
            {
                errMgr.Emit(ErrorType.WARNING_TREATED_AS_ERROR, new ANTLRMessage(ErrorType.WARNING_TREATED_AS_ERROR));
            }
        }
コード例 #8
0
ファイル: AntlrTool.cs プロジェクト: sharwell/antlr4cs
        public virtual void Error(ANTLRMessage msg)
        {
            if (listeners.Count == 0)
            {
                defaultListener.Error(msg);
                return;
            }

            foreach (ANTLRToolListener l in listeners)
                l.Error(msg);
        }