package bonsai

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type 'a t

'a t represents a parser that can parse a URL into 'a and unparse 'a into a URL.

val check_ok_and_print_urls_or_errors : 'a t -> unit

Make an expect test with this function! It will make your life easier!

Runs static checks, and shows all of the url shapes that the parser can parse. It lets you know if a URL shape sneakily changes or if there is any ambiguity in your parser. It tries its best to suggest possible fixes too.

val eval : 'a t -> (Components.t, 'a Parse_result.t) Projection.t

"Evaluates" a 'a t into a projection that parses to/from Components.t to 'a Parse_result.t.

val eval_for_uri : 'a t -> (Uri.t, 'a Parse_result.t) Projection.t

Like eval but parses/unparses from/into a Uri.t

val all_urls : 'a t -> string list

Returns a list of the shapes of all the URLs given that the parser can parse.

val project : 'a t -> parse_exn:('a -> 'b) -> unparse:('b -> 'a) -> 'b t

Like Value_parser.project, but works at the Parser.t level.

val optional_query_fields : 'a t -> 'a option t

Runs the given 'a t, if at any point its given parse fails due to a missing query_field, this fill parse into None, otherwise, this will parse into Some (* What 'a t would've parsed to *).

When this parses to None, the components that will be given to the next parse will be the same ones that optional_query_fields received, as if it were a no-op regardless if a subset of the parser suceeded.

val from_query_required : ?key:string -> 'a Value_parser.t -> 'a t

Looks up a key from components. If it's missing, parsing fails.

The key is determined with the following priority: 1. If ?key is given, then the given key is used. 2. If the parser is inside of a record or variant parser, then the field name/constructor name that the parser name is in will be the key that is used. 3. Key can't be inferred and an exception will be raised.

If you use check_ok_and_print_urls_or_errors, your parser will statically fail in an expect test, rather than failing on runtime.

val from_query_optional : ?key:string -> 'a Value_parser.t -> 'a option t

Like from_query_required, but parses into None if key is missing from URL's query.

val from_query_optional_with_default : ?key:string -> equal:('a -> 'a -> bool) -> 'a Value_parser.t -> default:'a -> 'a t

Like from_query_required, but parses into the 'a default value that's given to it.

if equal is passed over, when the unparsing occurs, if equal curr_value default_value, then the key/value pair is not included in the URL.

val from_query_many : ?key:string -> 'a Value_parser.t -> 'a list t

Like from_query_required, but will parse into a list of values rather than just one. (e.g. ?foo=1,2,3,4 => 1; 2; 3; 4) with from_query_many ~key:"foo" Value_parser.int

from_query_many ~key:"q" Value_parser.int parses into:

"?q=1,2,3" => 1; 2; 3 "?q=1" => 1 "?q" => "?" =>

val from_query_many_at_least_1 : ?key:string -> 'a Value_parser.t -> 'a list t

Like from_query_many, but fails if there is not a single element in the list.

val unit : unit t

No-op parser, does not consume anything. Useful for Variants that don't have a payload.

val from_path : 'a Value_parser.t -> 'a t

Reads the next value that is available in the path, parses it, and removes it from the path so that the next parsers move on an parse the remainder of the path.

val from_remaining_path : 'a Value_parser.t -> 'a list t

from_paths equivalent of from_query_many. Like from_path except that instead of just taking one element from the path list, it will take everything from the path list and run the given 'a Value_parser.t through it.

val with_prefix : string list -> 'a t -> 'a t

with_prefix prefix next will fail if the path that it receives does not start with prefix. If there is a prefix match, then next will continue parsing.

val with_remaining_path : string list -> 'a t -> 'a t

with_remaining_path is just like with_prefix just that instead of only needing the string list that it receives to match like a prefix, the entire path needs to equal the string that its given. No more path parsing is allowed inside of the parser that's given to with_remaining_path.

val end_of_path : 'a t -> 'a t

Fails to parse if path is not empty. If path is empty, its input parser continues parsing. end_of_path next is equivalent to with_remaining_path [] next.

module Variant : sig ... end
module Record : sig ... end
val sexp_of_t : 'a t -> Core.Sexp.t
OCaml

Innovation. Community. Security.