Skip to content

[WIP] atomic_sequence support: needs testing #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions include/ctre/evaluation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,115 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c
}
}

// atomic groups
template <typename R, typename Iterator, typename EndIterator, typename HeadContent, typename... TailContent, typename... Tail>
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<atomic_group<HeadContent, TailContent...>, Tail...>) noexcept {
if (auto r1 = evaluate(begin, current, end, captures, ctll::list<HeadContent, end_cycle_mark>())) { //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<atomic_group<TailContent...>, Tail...>()); //continue w/o being able to backtrack past the atomic group
} else {
return evaluate(begin, current, end, captures, ctll::list<Tail...>()); //continue w/o being able to backtrack past the atomic group
}
} else {
return not_matched;
}
}

// turns sequences into atomic sequences...
template <typename R, typename Iterator, typename EndIterator, typename HeadContent, typename... Content, typename... TailContent, typename... Tail>
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<atomic_group<sequence<HeadContent, Content...>, TailContent...>, Tail...>) noexcept {
if (auto r1 = evaluate(begin, current, end, captures, ctll::list<HeadContent, 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...(Content) > 0 && sizeof...(TailContent) > 0) {
return evaluate(begin, current, end, captures, ctll::list<atomic_group<Content..., TailContent...>, Tail...>());
} else if (sizeof...(Content) > 0) {
return evaluate(begin, current, end, captures, ctll::list<atomic_group<Content...>, Tail...>());
} else if (sizeof...(TailContent) > 0) {
return evaluate(begin, current, end, captures, ctll::list<atomic_group<TailContent...>, Tail...>());
} else {
return evaluate(begin, current, end, captures, ctll::list<Tail...>());
}
} else {
return not_matched;
}
}

// appends atomic sequences together...
template <typename R, typename Iterator, typename EndIterator, typename HeadContent, typename... Content, typename... TailContent, typename... Tail>
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<atomic_group<atomic_group<HeadContent, Content...>, TailContent...>, Tail...>) noexcept {
if (auto r1 = evaluate(begin, current, end, captures, ctll::list<HeadContent, 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...(Content) > 0 && sizeof...(TailContent) > 0) {
return evaluate(begin, current, end, captures, ctll::list<atomic_group<Content..., TailContent...>, Tail...>());
} else if (sizeof...(Content) > 0) {
return evaluate(begin, current, end, captures, ctll::list<atomic_group<Content...>, Tail...>());
} else if (sizeof...(TailContent) > 0) {
return evaluate(begin, current, end, captures, ctll::list<atomic_group<TailContent...>, Tail...>());
} else {
return evaluate(begin, current, end, captures, ctll::list<Tail...>());
}
} else {
return not_matched;
}
}

// turns repeats into possessive repeats...
template <typename R, typename Iterator, typename EndIterator, size_t A, size_t B, typename... Content, typename... TailContent, typename... Tail>
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<atomic_group<repeat<A,B, Content...>, TailContent...>, Tail...>) noexcept {
if (auto r1 = evaluate(begin, current, end, captures, ctll::list<possessive_repeat<A,B,Content...>, 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<atomic_group<TailContent...>, Tail...>());
} else {
return evaluate(begin, current, end, captures, ctll::list<Tail...>());
}
} else {
return not_matched;
}
}

// makes captures atomic capture (string ID)
template <typename R, typename Iterator, typename EndIterator, size_t Id, typename Name, typename... Content, typename... TailContent, typename... Tail>
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<atomic_group<capture_with_name<Id, Name, Content...>, TailContent...>, Tail...>) noexcept {
if (auto r1 = evaluate(begin, current, end, captures, ctll::list<capture_with_name<Id, Name, atomic_group<Content...>>, 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<atomic_group<TailContent...>, Tail...>());
} else {
return evaluate(begin, current, end, captures, ctll::list<Tail...>());
}
} else {
return not_matched;
}
}

// makes captures atomic (numeric ID)
template <typename R, typename Iterator, typename EndIterator, size_t Id, typename... Content, typename... TailContent, typename... Tail>
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<atomic_group<capture<Id, Content...>, TailContent...>, Tail...>) noexcept {
if (auto r1 = evaluate(begin, current, end, captures, ctll::list<capture<Id,atomic_group<Content...>>, 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<atomic_group<TailContent...>, Tail...>());
} else {
return evaluate(begin, current, end, captures, ctll::list<Tail...>());
}
} else {
return not_matched;
}
}

// property matching


Expand Down