parser_context.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. #include <functional>
  3. #include <optional>
  4. #include <jvalidate/detail/reference.h>
  5. #include <jvalidate/detail/vocabulary.h>
  6. #include <jvalidate/forward.h>
  7. namespace jvalidate::detail {
  8. template <Adapter A> class ReferenceManager;
  9. template <Adapter A> struct ParserContext {
  10. using Object = decltype(std::declval<A>().as_object());
  11. Schema & root;
  12. A schema;
  13. Vocabulary<A> const * vocab;
  14. ReferenceManager<A> & ref;
  15. std::optional<Object> parent = std::nullopt;
  16. Reference where = {};
  17. Reference dynamic_where = {};
  18. ParserContext rebind(A const & new_schema, Reference const & new_loc, Reference const & new_dyn,
  19. std::optional<Object> parent = std::nullopt) const {
  20. return {root, new_schema, vocab, ref, parent, new_loc, new_dyn};
  21. }
  22. ParserContext child(A const & child, std::string const & key) const {
  23. return rebind(child, where / key, dynamic_where / key, schema.as_object());
  24. }
  25. ParserContext child(A const & child, size_t index) const {
  26. return rebind(child, where / index, dynamic_where / index);
  27. }
  28. ParserContext neighbor(std::string const & key) const {
  29. return rebind((*parent)[key], where.parent() / key, dynamic_where.parent() / key, parent);
  30. }
  31. schema::Node const * node() const;
  32. schema::Node const * always() const;
  33. schema::Node const * fixed_schema(bool accept) const;
  34. };
  35. }