Token.cpp 896 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/ByteString.h>
  8. namespace Cpp {
  9. bool Position::operator<(Position const& other) const
  10. {
  11. return line < other.line || (line == other.line && column < other.column);
  12. }
  13. bool Position::operator>(Position const& other) const
  14. {
  15. return !(*this < other) && !(*this == other);
  16. }
  17. bool Position::operator==(Position const& other) const
  18. {
  19. return line == other.line && column == other.column;
  20. }
  21. bool Position::operator<=(Position const& other) const
  22. {
  23. return !(*this > other);
  24. }
  25. ByteString Token::to_byte_string() const
  26. {
  27. return ByteString::formatted("{} {}:{}-{}:{} ({})", type_to_string(m_type), start().line, start().column, end().line, end().column, text());
  28. }
  29. ByteString Token::type_as_byte_string() const
  30. {
  31. return type_to_string(m_type);
  32. }
  33. }