-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimization: Check for implicit anchor
Improves code generation for cases where .* can be treated as an anchor
- Loading branch information
Showing
5 changed files
with
204 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#ifndef CTRE__HAS_IMPLICIT_ANCHOR__HPP | ||
#define CTRE__HAS_IMPLICIT_ANCHOR__HPP | ||
|
||
#include "atoms.hpp" | ||
#include "atoms_unicode.hpp" | ||
|
||
namespace ctre { | ||
|
||
template<typename... Content> | ||
constexpr bool has_implicit_anchor(ctll::list<repeat<0, 0, any>, Content...>) noexcept { | ||
return true; | ||
} | ||
template<typename... Content> | ||
constexpr bool has_implicit_anchor(ctll::list<repeat<1, 0, any>, Content...>) noexcept { | ||
return true; | ||
} | ||
|
||
template<typename... Content> | ||
constexpr bool has_implicit_anchor(ctll::list<possessive_repeat<0, 0, any>, Content...>) noexcept { | ||
return true; | ||
} | ||
|
||
template<typename... Content> | ||
constexpr bool has_implicit_anchor(ctll::list<possessive_repeat<1, 0, any>, Content...>) noexcept { | ||
return true; | ||
} | ||
|
||
template<typename... Content> | ||
constexpr bool has_implicit_anchor(ctll::list<lazy_repeat<0, 0, any>, Content...>) noexcept { | ||
return true; | ||
} | ||
|
||
template<typename... Content> | ||
constexpr bool has_implicit_anchor(ctll::list<lazy_repeat<1, 0, any>, Content...>) noexcept { | ||
return true; | ||
} | ||
|
||
template<typename... Content, typename... Tail> | ||
constexpr bool has_implicit_anchor(ctll::list<sequence<Content...>, Tail...>) noexcept { | ||
return has_implicit_anchor(ctll::list<Content..., Tail...>{}); | ||
} | ||
|
||
//TODO: we may check captures as implicit anchors*, but they must not be backreferenced because for example "(.+)X\1" will not work properly with "1234X2345" | ||
/* | ||
template<size_t Id, typename... Content, typename... Tail> | ||
constexpr bool has_implicit_anchor(ctll::list<capture<Id, Content...>, Tail...>) noexcept { | ||
//Id must not be backreferenced | ||
return !id_backreference(Id) && has_implicit_anchor(ctll::list<Content..., Tail...>{}); | ||
} | ||
template<size_t Id, typename Name, typename... Content, typename... Tail> | ||
constexpr bool has_implicit_anchor(ctll::list<capture_with_name<Id, Name, Content...>, Tail...>) noexcept { | ||
//Id must not be backreferenced | ||
return !id_backreference(Id) && has_implicit_anchor(ctll::list<Content..., Tail...>{}); | ||
} | ||
*/ | ||
|
||
template<typename... Opts, typename... Tail> | ||
constexpr bool has_implicit_anchor(ctll::list<select<Opts...>, Tail...>) noexcept { | ||
return (has_implicit_anchor(ctll::list<Opts, Tail...>{}) && ...); | ||
} | ||
|
||
constexpr bool has_implicit_anchor(...) noexcept { | ||
return false; | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters