diff --git a/include/ctre/evaluation.hpp b/include/ctre/evaluation.hpp index ea090718..7a05b81b 100644 --- a/include/ctre/evaluation.hpp +++ b/include/ctre/evaluation.hpp @@ -408,6 +408,115 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c } } +// atomic groups +template +constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list, Tail...>) noexcept { + if (auto r1 = evaluate(begin, current, end, captures, ctll::list())) { //find the first match like a regular sequence* + captures = r1.unmatch(); + current = r1.get_end_position(); + if constexpr (sizeof...(TailContent) > 0) { + return evaluate(begin, current, end, captures, ctll::list, Tail...>()); //continue w/o being able to backtrack past the atomic group + } else { + return evaluate(begin, current, end, captures, ctll::list()); //continue w/o being able to backtrack past the atomic group + } + } else { + return not_matched; + } +} + +// turns sequences into atomic sequences... +template +constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list, TailContent...>, Tail...>) noexcept { + if (auto r1 = evaluate(begin, current, end, captures, ctll::list())) { //find the first match like a regular sequence* + captures = r1.unmatch(); + current = r1.get_end_position(); + //continue w/o being able to backtrack past the atomic group + if constexpr (sizeof...(Content) > 0 && sizeof...(TailContent) > 0) { + return evaluate(begin, current, end, captures, ctll::list, Tail...>()); + } else if (sizeof...(Content) > 0) { + return evaluate(begin, current, end, captures, ctll::list, Tail...>()); + } else if (sizeof...(TailContent) > 0) { + return evaluate(begin, current, end, captures, ctll::list, Tail...>()); + } else { + return evaluate(begin, current, end, captures, ctll::list()); + } + } else { + return not_matched; + } +} + +// appends atomic sequences together... +template +constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list, TailContent...>, Tail...>) noexcept { + if (auto r1 = evaluate(begin, current, end, captures, ctll::list())) { //find the first match like a regular sequence* + captures = r1.unmatch(); + current = r1.get_end_position(); + //continue w/o being able to backtrack past the atomic group + if constexpr (sizeof...(Content) > 0 && sizeof...(TailContent) > 0) { + return evaluate(begin, current, end, captures, ctll::list, Tail...>()); + } else if (sizeof...(Content) > 0) { + return evaluate(begin, current, end, captures, ctll::list, Tail...>()); + } else if (sizeof...(TailContent) > 0) { + return evaluate(begin, current, end, captures, ctll::list, Tail...>()); + } else { + return evaluate(begin, current, end, captures, ctll::list()); + } + } else { + return not_matched; + } +} + +// turns repeats into possessive repeats... +template +constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list, TailContent...>, Tail...>) noexcept { + if (auto r1 = evaluate(begin, current, end, captures, ctll::list, end_cycle_mark>())) { //find the first match like a regular sequence* + captures = r1.unmatch(); + current = r1.get_end_position(); + //continue w/o being able to backtrack past the atomic group + if constexpr (sizeof...(TailContent) > 0) { + return evaluate(begin, current, end, captures, ctll::list, Tail...>()); + } else { + return evaluate(begin, current, end, captures, ctll::list()); + } + } else { + return not_matched; + } +} + +// makes captures atomic capture (string ID) +template +constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list, TailContent...>, Tail...>) noexcept { + if (auto r1 = evaluate(begin, current, end, captures, ctll::list>, end_cycle_mark>())) { + captures = r1.unmatch(); + current = r1.get_end_position(); + //continue w/o being able to backtrack past the atomic group + if constexpr (sizeof...(TailContent) > 0) { + return evaluate(begin, current, end, captures, ctll::list, Tail...>()); + } else { + return evaluate(begin, current, end, captures, ctll::list()); + } + } else { + return not_matched; + } +} + +// makes captures atomic (numeric ID) +template +constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list, TailContent...>, Tail...>) noexcept { + if (auto r1 = evaluate(begin, current, end, captures, ctll::list>, end_cycle_mark>())) { + captures = r1.unmatch(); + current = r1.get_end_position(); + //continue w/o being able to backtrack past the atomic group + if constexpr (sizeof...(TailContent) > 0) { + return evaluate(begin, current, end, captures, ctll::list, Tail...>()); + } else { + return evaluate(begin, current, end, captures, ctll::list()); + } + } else { + return not_matched; + } +} + // property matching