Skip to content

Commit

Permalink
Refactor DB.find fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mrichards30 committed Jul 15, 2024
1 parent caf8750 commit fbc606b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/postkernel/DB.sml
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,9 @@ fun thy s =
fun findpred pat =
let
val pat = toLower pat
open DBSearchParser regexpMatch
val r = translate_regexp $ parse_regexp pat
open DBSearchParser
in
match (contains r) o toLower
contains_regexp pat o toLower
end

fun find0 incprivatep s =
Expand Down
2 changes: 1 addition & 1 deletion src/postkernel/DBSearchParser.sig
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ sig
| Any
val parse_regexp : string -> search_regexp
val translate_regexp : search_regexp -> regexpMatch.regexp
val contains : regexpMatch.regexp -> regexpMatch.regexp
val contains_regexp : string -> string -> bool
end
11 changes: 8 additions & 3 deletions src/postkernel/DBSearchParser.sml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ fun parse_regexp input = let
| T(#"*")::(E a)::ts => E(Many(a))::ts
| T(#"*")::(T c)::ts => E(Many(Word [c]))::ts
| (T #")")::(E x)::(T #"(")::ts => E x::ts
| (T #")")::(E x)::(E y)::ts => (T #")")::E(Seq(y, x))::ts
| (E a)::(E b)::ts => E(Seq(b, a))::ts
| T(c)::E(Word cs)::ts => E(Word(cs@[c]))::ts
| T(c)::ts => E(Word [c])::ts
Expand Down Expand Up @@ -115,8 +116,12 @@ in
| Any => Symbs word_set
end

val is_regexp = List.exists is_special_char o String.explode

fun contains pat = Dot (any, Dot (pat, any))
fun contains_regexp pattern = let
val intermediate = parse_regexp pattern
val compiled_pattern = translate_regexp intermediate
fun contains pat = Dot (any, Dot (pat, any))
in
match (contains compiled_pattern)
end

end

0 comments on commit fbc606b

Please sign in to comment.