literals.h 1023 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #include <abnf/forward.h>
  3. #include <abnf/grammar.h>
  4. #include <cstddef>
  5. namespace abnf {
  6. char_range parse_char_range(std::string_view);
  7. }
  8. namespace abnf::literals {
  9. inline literal operator""_lit(char const * const str, size_t len) {
  10. return literal{{str, len}};
  11. }
  12. inline reference operator""_ref(char const * const str, size_t len) {
  13. return reference{{str, len}};
  14. }
  15. inline char_range operator""_range(char const * const str, size_t len) {
  16. return parse_char_range({str, len});
  17. }
  18. inline one_of operator/(one_of lhs, rule rhs) {
  19. lhs.rules.push_back(std::move(rhs));
  20. return lhs;
  21. }
  22. inline one_of operator/(rule_like auto const & lhs,
  23. rule_like auto const & rhs) {
  24. return one_of{rule{lhs}, rule{rhs}};
  25. }
  26. inline rule operator+(rule lhs, rule_part const & rhs) {
  27. lhs.rules.push_back(rhs);
  28. return lhs;
  29. }
  30. inline rule operator+(rule_part_like auto const & lhs, rule_part const & rhs) {
  31. return rule{lhs, rhs};
  32. }
  33. inline repeated operator*(rule v) { return repeated{v}; }
  34. }