Regex: whenever Kakoune compiles a regex, pass it to the custom impl as well
That way we can see which features are missing.
This commit is contained in:
parent
002aba562f
commit
eb1015cdfb
|
@ -1,6 +1,7 @@
|
||||||
#include "regex.hh"
|
#include "regex.hh"
|
||||||
|
|
||||||
#include "exception.hh"
|
#include "exception.hh"
|
||||||
|
#include "regex_impl.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
@ -9,7 +10,9 @@ using Utf8It = RegexUtf8It<const char*>;
|
||||||
|
|
||||||
Regex::Regex(StringView re, flag_type flags) try
|
Regex::Regex(StringView re, flag_type flags) try
|
||||||
: RegexBase{Utf8It{re.begin(), re}, Utf8It{re.end(), re}, flags}, m_str{re.str()}
|
: RegexBase{Utf8It{re.begin(), re}, Utf8It{re.end(), re}, flags}, m_str{re.str()}
|
||||||
{} catch (std::runtime_error& err) { throw regex_error(err.what()); }
|
{
|
||||||
|
validate_regex(re);
|
||||||
|
} catch (std::runtime_error& err) { throw regex_error(err.what()); }
|
||||||
|
|
||||||
String option_to_string(const Regex& re)
|
String option_to_string(const Regex& re)
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include "exception.hh"
|
#include "exception.hh"
|
||||||
#include "array_view.hh"
|
#include "array_view.hh"
|
||||||
|
|
||||||
|
#include "buffer_utils.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -114,13 +116,6 @@ AstNodePtr make_ast_node(Op op, Codepoint value = -1,
|
||||||
// standard, although the syntax is not fully compatible.
|
// standard, although the syntax is not fully compatible.
|
||||||
struct Parser
|
struct Parser
|
||||||
{
|
{
|
||||||
struct InvalidPolicy
|
|
||||||
{
|
|
||||||
Codepoint operator()(Codepoint cp) { throw runtime_error{"Invalid utf8 in regex"}; }
|
|
||||||
};
|
|
||||||
|
|
||||||
using Iterator = utf8::iterator<const char*, Codepoint, int, InvalidPolicy>;
|
|
||||||
|
|
||||||
static ParsedRegex parse(StringView re)
|
static ParsedRegex parse(StringView re)
|
||||||
{
|
{
|
||||||
ParsedRegex res;
|
ParsedRegex res;
|
||||||
|
@ -131,6 +126,13 @@ struct Parser
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct InvalidPolicy
|
||||||
|
{
|
||||||
|
Codepoint operator()(Codepoint cp) { throw runtime_error{"Invalid utf8 in regex"}; }
|
||||||
|
};
|
||||||
|
|
||||||
|
using Iterator = utf8::iterator<const char*, Codepoint, int, InvalidPolicy>;
|
||||||
|
|
||||||
static AstNodePtr disjunction(ParsedRegex& parsed_regex, Iterator& pos, Iterator end, unsigned capture = -1)
|
static AstNodePtr disjunction(ParsedRegex& parsed_regex, Iterator& pos, Iterator end, unsigned capture = -1)
|
||||||
{
|
{
|
||||||
AstNodePtr node = alternative(parsed_regex, pos, end);
|
AstNodePtr node = alternative(parsed_regex, pos, end);
|
||||||
|
@ -790,6 +792,18 @@ struct ThreadedRegexVM
|
||||||
Vector<const char*> m_captures;
|
Vector<const char*> m_captures;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void validate_regex(StringView re)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
RegexCompiler::Parser::parse(re);
|
||||||
|
}
|
||||||
|
catch (runtime_error& err)
|
||||||
|
{
|
||||||
|
write_to_debug_buffer(format("regex-impl: <<{}>> failed to parse: {}", re, err.what()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto test_regex = UnitTest{[]{
|
auto test_regex = UnitTest{[]{
|
||||||
{
|
{
|
||||||
auto program = RegexCompiler::compile(R"(a*b)");
|
auto program = RegexCompiler::compile(R"(a*b)");
|
||||||
|
|
|
@ -1,4 +1,13 @@
|
||||||
#ifndef regex_impl_hh_INCLUDED
|
#ifndef regex_impl_hh_INCLUDED
|
||||||
#define regex_impl_hh_INCLUDED
|
#define regex_impl_hh_INCLUDED
|
||||||
|
|
||||||
|
namespace Kakoune
|
||||||
|
{
|
||||||
|
|
||||||
|
class StringView;
|
||||||
|
|
||||||
|
void validate_regex(StringView re);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif // regex_impl_hh_INCLUDED
|
#endif // regex_impl_hh_INCLUDED
|
||||||
|
|
Loading…
Reference in New Issue
Block a user