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
12class Label {
13public:
20 Label(std::string text, Span span);
21
30 friend bool operator<(const Label& lhs, const Label& rhs) {
31 return lhs._span < rhs._span;
32 }
33
42 friend bool operator<=(const Label& lhs, const Label& rhs) {
43 return rhs >= lhs;
44 }
45
54 friend bool operator>(const Label& lhs, const Label& rhs) {
55 return rhs < lhs;
56 }
57
66 friend bool operator>=(const Label& lhs, const Label& rhs) {
67 return !(lhs < rhs);
68 }
69
75 [[nodiscard]] const std::string& text() const { return _text; }
76
82 [[nodiscard]] const Span& span() const { return _span; }
83
84private:
85 std::string _text;
86 Span _span;
87};
88} // namespace pretty_diagnostics
89
90// BSD 3-Clause License
91//
92// Copyright (c) 2025, Timo Behrend
93//
94// Redistribution and use in source and binary forms, with or without
95// modification, are permitted provided that the following conditions are met:
96//
97// 1. Redistributions of source code must retain the above copyright notice, this
98// list of conditions and the following disclaimer.
99//
100// 2. Redistributions in binary form must reproduce the above copyright notice,
101// this list of conditions and the following disclaimer in the documentation
102// and/or other materials provided with the distribution.
103//
104// 3. Neither the name of the copyright holder nor the names of its
105// contributors may be used to endorse or promote products derived from
106// this software without specific prior written permission.
107//
108// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
109// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
110// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
111// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
112// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
113// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
114// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
115// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
116// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
117// 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:75
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:42
friend bool operator>(const Label &lhs, const Label &rhs)
Greater-than comparison derived from <
Definition: label.hpp:54
const Span & span() const
Returns the span associated with this label.
Definition: label.hpp:82
friend bool operator>=(const Label &lhs, const Label &rhs)
Greater-than-or-equal comparison derived from <
Definition: label.hpp:66
Represents a contiguous region within a Source
Definition: span.hpp:12
Definition: label.hpp:5