route.ml 548 B

12345678910111213141516171819202122232425262728
  1. (*
  2. * Parse path and Query string
  3. *
  4. * We have either a
  5. *
  6. * path: /<geohash>/<format>
  7. * or
  8. * query_string: ?q=<lat><sep><lon>
  9. *)
  10. module P = struct
  11. open Tyre
  12. let lat_lon_pair = float <&> pcre "([,; +]|%2C|%3B|%20)+" *> float
  13. let geo_uri =
  14. opt (pcre "geo(:|%3A)") *> lat_lon_pair
  15. <* opt (pcre "(\\?|%3F)z(=|%3D)[0-9]+")
  16. let lat_lon = compile (geo_uri <* stop)
  17. let qs_lat_lon = compile (str "q=" *> geo_uri <* stop)
  18. end
  19. let coord_from_qs qs = qs |> Tyre.exec P.qs_lat_lon
  20. let coord_from_s s = s |> Tyre.exec P.lat_lon