Beispiel #1
0
 protected void AppendMessage(StringBuilder str, MessageHolder.Message mhmsg)
 {
     str.Append(Localize.From(mhmsg.Severity.ToString()));
     str.Append(": ");
     str.AppendFormat(mhmsg.Format, mhmsg.Args);
 }
Beispiel #2
0
        void PrintMessages(InternalList <MacroResult> results, LNode input, int accepted, Severity maxSeverity)
        {
            if (accepted > 1)
            {
                // Multiple macros accepted the input. If AllowDuplicates is used,
                // this is fine if as long as they produced the same result.
                bool allowed, equal = AreAllOutcomesEqual(results, out allowed);
                if (!equal || !allowed)
                {
                    string list = results.Where(r => r.NewNode != null).Select(r => QualifiedName(r.Macro.Macro.Method)).Join(", ");
                    if (equal)
                    {
                        _sink.Write(Severity.Warning, input, "Ambiguous macro call. {0} macros accepted the input and produced identical results: {1}", accepted, list);
                    }
                    else
                    {
                        _sink.Write(Severity.Error, input, "Ambiguous macro call. {0} macros accepted the input: {1}", accepted, list);
                    }
                }
            }

            bool macroStyleCall = input.BaseStyle == NodeStyle.Special;

            if (accepted > 0 || macroStyleCall || maxSeverity >= Severity.Warning)
            {
                if (macroStyleCall && maxSeverity < Severity.Warning)
                {
                    maxSeverity = Severity.Warning;
                }
                var rejected = results.Where(r => r.NewNode == null && (r.Macro.Mode & MacroMode.Passive) == 0);
                if (accepted == 0 && macroStyleCall && _sink.IsEnabled(maxSeverity) && rejected.Any())
                {
                    _sink.Write(maxSeverity, input, "{0} macro(s) saw the input and declined to process it: {1}",
                                results.Count, rejected.Select(r => QualifiedName(r.Macro.Macro.Method)).Join(", "));
                }

                foreach (var result in results)
                {
                    bool printedLast = true;
                    foreach (var msg in result.Msgs)
                    {
                        // Print all messages from macros that accepted the input.
                        // For rejecting macros, print warning/error messages, and
                        // other messages when macroStyleCall.
                        if (_sink.IsEnabled(msg.Severity) && (result.NewNode != null ||
                                                              (msg.Severity == Severity.Detail && printedLast) ||
                                                              msg.Severity >= Severity.Warning ||
                                                              macroStyleCall))
                        {
                            var msg2 = new MessageHolder.Message(msg.Severity, msg.Context,
                                                                 QualifiedName(result.Macro.Macro.Method) + ": " + msg.Format, msg.Args);
                            msg2.WriteTo(_sink);
                            printedLast = true;
                        }
                        else
                        {
                            printedLast = false;
                        }
                    }
                }
            }
        }