Exploring re2, doesn't really work

This commit is contained in:
Roberto Alsina 2024-08-07 14:41:02 -03:00
parent ff1c0012ec
commit b9e51824df
5 changed files with 16 additions and 5 deletions

View File

@ -22,6 +22,7 @@ OPT_bool(longest_match)
OPT_bool(log_errors)
OPT_bool(literal)
OPT_bool(never_nl)
OPT_bool(dot_nl)
OPT_bool(case_sensitive)
OPT_bool(perl_classes)
OPT_bool(word_boundary)

View File

@ -14,6 +14,7 @@ lib LibCre2
fun opt_perl_classes = cre2_opt_perl_classes(op : Options, flag : Bool) : Nil
fun opt_word_boundary = cre2_opt_word_boundary(op : Options, flag : Bool) : Nil
fun opt_one_line = cre2_opt_one_line(op : Options, flag : Bool) : Nil
fun opt_dot_nl = cre2_opt_dot_nl(op : Options, flag : Bool) : Nil
fun opt_encoding = cre2_opt_encoding(op : Options, encoding : Int32) : Nil
fun opt_max_mem = cre2_opt_max_mem(op : Options, flag : Bool) : Nil

View File

@ -21,6 +21,7 @@ void cre2_opt_case_sensitive(cre2_options *opt, int flag);
void cre2_opt_perl_classes(cre2_options *opt, int flag);
void cre2_opt_word_boundary(cre2_options *opt, int flag);
void cre2_opt_one_line(cre2_options *opt, int flag);
void cre2_opt_dot_nl(cre2_options *opt, int flag);
void cre2_opt_encoding(cre2_options *opt, encoding_t enc);
void cre2_opt_max_mem(cre2_options *opt, int m);

Binary file not shown.

View File

@ -125,12 +125,16 @@ module Tartrazine
ignorecase = false, anchored = false)
@opts = LibCre2.opt_new
LibCre2.opt_posix_syntax(@opts, false)
LibCre2.opt_longest_match(@opts, true)
LibCre2.opt_perl_classes(@opts, true)
LibCre2.opt_longest_match(@opts, false)
# These 3 are ignored when posix_syntax is false
# LibCre2.opt_one_line(@opts, !multiline)
# LibCre2.opt_perl_classes(@opts, true)
# LibCre2.opt_word_boundary(@opts, true)
LibCre2.opt_encoding(@opts, 1)
LibCre2.opt_one_line(@opts, !multiline)
LibCre2.opt_case_sensitive(@opts, !ignorecase)
LibCre2.opt_dot_nl(@opts, dotall)
pattern = "(m?)#{pattern}" if multiline
p! pattern
@re = LibCre2.new(pattern, pattern.size, @opts)
end
@ -142,6 +146,10 @@ module Tartrazine
end
end
re = Tartrazine::Re3.new("(require-instance|fraction-digits|error-app-tag|error-message|min-elements|max-elements|yin-element|ordered-by|position|modifier|default|pattern|length|status|units|value|range|type|path|enum|base|bit)(?=[^\w\-\:])")
p! re.match("value ", 0)
# I can't find a combination of flags that makes this match "#foo"
# and without that this is never going to work.
re = Tartrazine::Re3.new("#.*$", multiline: true, dotall: false)
m = re.match("#foo\nbar", 0)
p m[0], m[1][0]