OCaml HTML5 parser/serialiser based on Python's JustHTML
1(*---------------------------------------------------------------------------
2 Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved.
3 SPDX-License-Identifier: MIT
4 ---------------------------------------------------------------------------*)
5
6(** CSS selector parse error codes.
7
8 These represent all possible errors that can occur when parsing
9 CSS selectors.
10*)
11
12type t =
13 | Empty_selector
14 (** The selector string was empty or contained only whitespace. *)
15 | Unterminated_string
16 (** A quoted string was not closed before end of input. *)
17 | Unterminated_escape
18 (** An escape sequence was not completed before end of input. *)
19 | Expected_identifier_after_hash
20 (** Expected an identifier after [#] for ID selector. *)
21 | Expected_identifier_after_dot
22 (** Expected an identifier after [.] for class selector. *)
23 | Expected_attribute_name
24 (** Expected an attribute name inside an attribute selector. *)
25 | Expected_closing_bracket
26 (** Expected [\]] to close an attribute selector. *)
27 | Expected_equals_after_operator of char
28 (** Expected [=] after an attribute operator like [~], [|], [^], [$], or [*]. *)
29 | Unexpected_character_in_attribute_selector
30 (** Found an unexpected character inside an attribute selector. *)
31 | Expected_pseudo_class_name
32 (** Expected a pseudo-class name after [:]. *)
33 | Expected_closing_paren
34 (** Expected [)] to close a pseudo-class argument. *)
35 | Unexpected_character of char
36 (** Found an unexpected character in the selector. *)
37 | Expected_attribute_value
38 (** Expected a value after the attribute operator. *)
39 | Expected_closing_bracket_or_operator
40 (** Expected [\]] or an attribute operator like [=]. *)
41 | Expected_selector_after_combinator
42 (** Expected a selector after a combinator ([>], [+], [~], or space). *)
43 | Unexpected_token
44 (** Found an unexpected token in the selector. *)
45 | Expected_end_of_selector
46 (** Expected end of selector but found more tokens. *)
47
48val to_string : t -> string
49(** Convert to a kebab-case string identifier suitable for programmatic use.
50
51 Examples:
52 - [to_string Empty_selector] returns ["empty-selector"]
53 - [to_string (Unexpected_character 'x')] returns ["unexpected-character-x"]
54*)
55
56val to_human_string : t -> string
57(** Convert to a human-readable error message.
58
59 Examples:
60 - [to_human_string Empty_selector] returns ["Empty selector"]
61 - [to_human_string Expected_closing_bracket] returns ["Expected \]"]
62*)
63
64val pp : Format.formatter -> t -> unit
65(** Pretty-print a selector error code using its kebab-case string form. *)