Token.cpp 978 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2023, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "Token.h"
  7. #include <AK/String.h>
  8. namespace GLSL {
  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. ErrorOr<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. ErrorOr<String> Token::type_as_string() const
  30. {
  31. auto str = type_to_string(m_type);
  32. auto view = StringView(str, strlen(str));
  33. return String::from_utf8(view);
  34. }
  35. }