Skip to content

Commit d1b2fd4

Browse files
committed
Add atomic_group evaluation support*
Still a work in progress...
1 parent e6e01dd commit d1b2fd4

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

include/ctre/evaluation.hpp

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,115 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c
408408
}
409409
}
410410

411+
// atomic groups
412+
template <typename R, typename Iterator, typename EndIterator, typename HeadContent, typename... TailContent, typename... Tail>
413+
constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, const EndIterator end, R captures, ctll::list<atomic_group<HeadContent, TailContent...>, Tail...>) noexcept {
414+
if (auto r1 = evaluate(begin, current, end, captures, ctll::list<HeadContent, end_cycle_mark>())) { //find the first match like a regular sequence*
415+
captures = r1.unmatch();
416+
current = r1.get_end_position();
417+
if constexpr (sizeof...(TailContent) > 0) {
418+
return evaluate(begin, current, end, captures, ctll::list<atomic_group<TailContent...>, Tail...>()); //continue w/o being able to backtrack past the atomic group
419+
} else {
420+
return evaluate(begin, current, end, captures, ctll::list<Tail...>()); //continue w/o being able to backtrack past the atomic group
421+
}
422+
} else {
423+
return not_matched;
424+
}
425+
}
426+
427+
// turns sequences into atomic sequences...
428+
template <typename R, typename Iterator, typename EndIterator, typename HeadContent, typename... Content, typename... TailContent, typename... Tail>
429+
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 {
430+
if (auto r1 = evaluate(begin, current, end, captures, ctll::list<HeadContent, end_cycle_mark>())) { //find the first match like a regular sequence*
431+
captures = r1.unmatch();
432+
current = r1.get_end_position();
433+
//continue w/o being able to backtrack past the atomic group
434+
if constexpr (sizeof...(Content) > 0 && sizeof...(TailContent) > 0) {
435+
return evaluate(begin, current, end, captures, ctll::list<atomic_group<Content..., TailContent...>, Tail...>());
436+
} else if (sizeof...(Content) > 0) {
437+
return evaluate(begin, current, end, captures, ctll::list<atomic_group<Content...>, Tail...>());
438+
} else if (sizeof...(TailContent) > 0) {
439+
return evaluate(begin, current, end, captures, ctll::list<atomic_group<TailContent...>, Tail...>());
440+
} else {
441+
return evaluate(begin, current, end, captures, ctll::list<Tail...>());
442+
}
443+
} else {
444+
return not_matched;
445+
}
446+
}
447+
448+
// appends atomic sequences together...
449+
template <typename R, typename Iterator, typename EndIterator, typename HeadContent, typename... Content, typename... TailContent, typename... Tail>
450+
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 {
451+
if (auto r1 = evaluate(begin, current, end, captures, ctll::list<HeadContent, end_cycle_mark>())) { //find the first match like a regular sequence*
452+
captures = r1.unmatch();
453+
current = r1.get_end_position();
454+
//continue w/o being able to backtrack past the atomic group
455+
if constexpr (sizeof...(Content) > 0 && sizeof...(TailContent) > 0) {
456+
return evaluate(begin, current, end, captures, ctll::list<atomic_group<Content..., TailContent...>, Tail...>());
457+
} else if (sizeof...(Content) > 0) {
458+
return evaluate(begin, current, end, captures, ctll::list<atomic_group<Content...>, Tail...>());
459+
} else if (sizeof...(TailContent) > 0) {
460+
return evaluate(begin, current, end, captures, ctll::list<atomic_group<TailContent...>, Tail...>());
461+
} else {
462+
return evaluate(begin, current, end, captures, ctll::list<Tail...>());
463+
}
464+
} else {
465+
return not_matched;
466+
}
467+
}
468+
469+
// turns repeats into possessive repeats...
470+
template <typename R, typename Iterator, typename EndIterator, size_t A, size_t B, typename... Content, typename... TailContent, typename... Tail>
471+
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 {
472+
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*
473+
captures = r1.unmatch();
474+
current = r1.get_end_position();
475+
//continue w/o being able to backtrack past the atomic group
476+
if constexpr (sizeof...(TailContent) > 0) {
477+
return evaluate(begin, current, end, captures, ctll::list<atomic_group<TailContent...>, Tail...>());
478+
} else {
479+
return evaluate(begin, current, end, captures, ctll::list<Tail...>());
480+
}
481+
} else {
482+
return not_matched;
483+
}
484+
}
485+
486+
// makes captures atomic capture (string ID)
487+
template <typename R, typename Iterator, typename EndIterator, size_t Id, typename Name, typename... Content, typename... TailContent, typename... Tail>
488+
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 {
489+
if (auto r1 = evaluate(begin, current, end, captures, ctll::list<capture_with_name<Id, Name, atomic_group<Content...>>, end_cycle_mark>())) {
490+
captures = r1.unmatch();
491+
current = r1.get_end_position();
492+
//continue w/o being able to backtrack past the atomic group
493+
if constexpr (sizeof...(TailContent) > 0) {
494+
return evaluate(begin, current, end, captures, ctll::list<atomic_group<TailContent...>, Tail...>());
495+
} else {
496+
return evaluate(begin, current, end, captures, ctll::list<Tail...>());
497+
}
498+
} else {
499+
return not_matched;
500+
}
501+
}
502+
503+
// makes captures atomic (numeric ID)
504+
template <typename R, typename Iterator, typename EndIterator, size_t Id, typename... Content, typename... TailContent, typename... Tail>
505+
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 {
506+
if (auto r1 = evaluate(begin, current, end, captures, ctll::list<capture<Id,atomic_group<Content...>>, end_cycle_mark>())) {
507+
captures = r1.unmatch();
508+
current = r1.get_end_position();
509+
//continue w/o being able to backtrack past the atomic group
510+
if constexpr (sizeof...(TailContent) > 0) {
511+
return evaluate(begin, current, end, captures, ctll::list<atomic_group<TailContent...>, Tail...>());
512+
} else {
513+
return evaluate(begin, current, end, captures, ctll::list<Tail...>());
514+
}
515+
} else {
516+
return not_matched;
517+
}
518+
}
519+
411520
// property matching
412521

413522

0 commit comments

Comments
 (0)