| 1 |
module Re = Core |
| 2 |
|
| 3 |
let of_name = function |
| 4 |
| "alpha" -> Re.alpha |
| 5 |
| "alnum" -> Re.alnum |
| 6 |
| "ascii" -> Re.ascii |
| 7 |
| "blank" -> Re.blank |
| 8 |
| "cntrl" -> Re.cntrl |
| 9 |
| "digit" -> Re.digit |
| 10 |
| "lower" -> Re.lower |
| 11 |
| "print" -> Re.print |
| 12 |
| "space" -> Re.space |
| 13 |
| "upper" -> Re.upper |
| 14 |
| "word" -> Re.wordc |
| 15 |
| "punct" -> Re.punct |
| 16 |
| "graph" -> Re.graph |
| 17 |
| "xdigit" -> Re.xdigit |
| 18 |
| class_ -> invalid_arg ("Invalid pcre class: " ^ class_) |
| 19 |
;; |
| 20 |
|
| 21 |
let names = |
| 22 |
[ "alpha" |
| 23 |
; "alnum" |
| 24 |
; "ascii" |
| 25 |
; "blank" |
| 26 |
; "cntrl" |
| 27 |
; "digit" |
| 28 |
; "lower" |
| 29 |
; "print" |
| 30 |
; "space" |
| 31 |
; "upper" |
| 32 |
; "word" |
| 33 |
; "punct" |
| 34 |
; "graph" |
| 35 |
; "xdigit" |
| 36 |
] |
| 37 |
;; |
| 38 |
|
| 39 |
let parse buf = |
| 40 |
let accept = Parse_buffer.accept buf in |
| 41 |
let accept_s = Parse_buffer.accept_s buf in |
| 42 |
match accept ':' with |
| 43 |
| false -> None |
| 44 |
| true -> |
| 45 |
let compl = accept '^' in |
| 46 |
let cls = |
| 47 |
try List.find accept_s names with |
| 48 |
| Not_found -> raise Parse_buffer.Parse_error |
| 49 |
in |
| 50 |
if not (accept_s ":]") then raise Parse_buffer.Parse_error; |
| 51 |
let posix_class = of_name cls in |
| 52 |
Some (if compl then Re.compl [ posix_class ] else posix_class) |
| 53 |
;; |