summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCpp/Token.cpp
blob: 71f7bc768bb6d1c229c1ef44a0973b11f1d00aec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
 * Copyright (c) 2020, the SerenityOS developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include "Token.h"
#include <AK/String.h>

namespace Cpp {

bool Position::operator<(Position const& other) const
{
    return line < other.line || (line == other.line && column < other.column);
}
bool Position::operator>(Position const& other) const
{
    return !(*this < other) && !(*this == other);
}
bool Position::operator==(Position const& other) const
{
    return line == other.line && column == other.column;
}
bool Position::operator<=(Position const& other) const
{
    return !(*this > other);
}

String Token::to_string() const
{
    return String::formatted("{}  {}:{}-{}:{} ({})", type_to_string(m_type), start().line, start().column, end().line, end().column, text());
}

String Token::type_as_string() const
{
    return type_to_string(m_type);
}

}