-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: support posix classes in Re.Posix
Signed-off-by: Rudi Grinberg <[email protected]> <!-- ps-id: 0d54478a-0925-4ca9-bf78-c0d887a94d80 -->
- Loading branch information
Showing
6 changed files
with
87 additions
and
66 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
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,40 @@ | ||
module Re = Core | ||
|
||
let of_name = function | ||
| "alpha" -> Re.alpha | ||
| "alnum" -> Re.alnum | ||
| "ascii" -> Re.ascii | ||
| "blank" -> Re.blank | ||
| "cntrl" -> Re.cntrl | ||
| "digit" -> Re.digit | ||
| "lower" -> Re.lower | ||
| "print" -> Re.print | ||
| "space" -> Re.space | ||
| "upper" -> Re.upper | ||
| "word" -> Re.wordc | ||
| "punct" -> Re.punct | ||
| "graph" -> Re.graph | ||
| "xdigit" -> Re.xdigit | ||
| class_ -> invalid_arg ("Invalid pcre class: " ^ class_) | ||
|
||
let names = | ||
[ "alpha" ; "alnum" ; "ascii" | ||
; "blank" ; "cntrl" ; "digit" | ||
; "lower" ; "print" ; "space" | ||
; "upper" ; "word" ; "punct" | ||
; "graph" ; "xdigit" ] | ||
|
||
let parse buf = | ||
let accept = Parse_buffer.accept buf in | ||
let accept_s = Parse_buffer.accept_s buf in | ||
match accept ':' with | ||
| false -> None | ||
| true -> | ||
let compl = accept '^' in | ||
let cls = | ||
try List.find accept_s names | ||
with Not_found -> raise Parse_buffer.Parse_error | ||
in | ||
if not (accept_s ":]") then raise Parse_buffer.Parse_error; | ||
let posix_class = of_name cls in | ||
Some (if compl then Re.compl [posix_class] else posix_class) |
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,3 @@ | ||
val names : string list | ||
val of_name : string -> Core.t | ||
val parse : Parse_buffer.t -> Core.t option |
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