SourceRange.h 686 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. * Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/NonnullRefPtr.h>
  9. #include <AK/StringView.h>
  10. #include <AK/Types.h>
  11. #include <LibJS/SourceCode.h>
  12. namespace JS {
  13. struct Position {
  14. size_t line { 0 };
  15. size_t column { 0 };
  16. size_t offset { 0 };
  17. };
  18. struct SourceRange {
  19. [[nodiscard]] bool contains(Position const& position) const { return position.offset <= end.offset && position.offset >= start.offset; }
  20. NonnullRefPtr<SourceCode const> code;
  21. Position start;
  22. Position end;
  23. DeprecatedString filename() const;
  24. };
  25. }