Pretty Diagnostics
Create your own pretty diagnostics
Loading...
Searching...
No Matches
label.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "span.hpp"
4
5namespace pretty_diagnostics {
12class Label {
13public:
20 Label(std::string text, Span span);
21
30 friend bool operator<(const Label& lhs, const Label& rhs) { return lhs._span < rhs._span; }
31
40 friend bool operator<=(const Label& lhs, const Label& rhs) { return rhs >= lhs; }
41
50 friend bool operator>(const Label& lhs, const Label& rhs) { return rhs < lhs; }
51
60 friend bool operator>=(const Label& lhs, const Label& rhs) { return !(lhs < rhs); }
61
67 [[nodiscard]] const std::string& text() const { return _text; }
68
74 [[nodiscard]] const Span& span() const { return _span; }
75
76private:
77 std::string _text;
78 Span _span;
79};
80} // namespace pretty_diagnostics
81
82// BSD 3-Clause License
83//
84// Copyright (c) 2025, Timo Behrend
85//
86// Redistribution and use in source and binary forms, with or without
87// modification, are permitted provided that the following conditions are met:
88//
89// 1. Redistributions of source code must retain the above copyright notice, this
90// list of conditions and the following disclaimer.
91//
92// 2. Redistributions in binary form must reproduce the above copyright notice,
93// this list of conditions and the following disclaimer in the documentation
94// and/or other materials provided with the distribution.
95//
96// 3. Neither the name of the copyright holder nor the names of its
97// contributors may be used to endorse or promote products derived from
98// this software without specific prior written permission.
99//
100// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
101// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
102// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
103// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
104// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
105// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
106// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
107// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
108// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
109// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Represents a short textual annotation attached to a Span in a source.
Definition: label.hpp:12
friend bool operator<(const Label &lhs, const Label &rhs)
Orders labels by their span to allow placement within a line/group.
Definition: label.hpp:30
const std::string & text() const
Returns the label text.
Definition: label.hpp:67
Label(std::string text, Span span)
Constructs a label with a human-readable message and the span it refers to.
friend bool operator<=(const Label &lhs, const Label &rhs)
Less-than-or-equal comparison derived from >=
Definition: label.hpp:40
friend bool operator>(const Label &lhs, const Label &rhs)
Greater-than comparison derived from <
Definition: label.hpp:50
const Span & span() const
Returns the span associated with this label.
Definition: label.hpp:74
friend bool operator>=(const Label &lhs, const Label &rhs)
Greater-than-or-equal comparison derived from <
Definition: label.hpp:60
Represents a contiguous region within a Source
Definition: span.hpp:12
Definition: color.hpp:5