Token.cpp 870 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "Token.h"
  7. #include <AK/String.h>
  8. namespace Cpp {
  9. bool Position::operator<(const Position& other) const
  10. {
  11. return line < other.line || (line == other.line && column < other.column);
  12. }
  13. bool Position::operator>(const Position& other) const
  14. {
  15. return !(*this < other) && !(*this == other);
  16. }
  17. bool Position::operator==(const Position& other) const
  18. {
  19. return line == other.line && column == other.column;
  20. }
  21. bool Position::operator<=(const Position& other) const
  22. {
  23. return !(*this > other);
  24. }
  25. String Token::to_string() const
  26. {
  27. return String::formatted("{} {}:{}-{}:{} ({})", type_to_string(m_type), start().line, start().column, end().line, end().column, text());
  28. }
  29. String Token::type_as_string() const
  30. {
  31. return type_to_string(m_type);
  32. }
  33. }