OCaml HTML5 parser/serialiser based on Python's JustHTML

more errors

Changed files
+134
lib
+72
lib/html5rw/selector/selector_error_code.ml
··· 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 + 12 + type t = 13 + | Empty_selector 14 + | Unterminated_string 15 + | Unterminated_escape 16 + | Expected_identifier_after_hash 17 + | Expected_identifier_after_dot 18 + | Expected_attribute_name 19 + | Expected_closing_bracket 20 + | Expected_equals_after_operator of char 21 + | Unexpected_character_in_attribute_selector 22 + | Expected_pseudo_class_name 23 + | Expected_closing_paren 24 + | Unexpected_character of char 25 + | Expected_attribute_value 26 + | Expected_closing_bracket_or_operator 27 + | Expected_selector_after_combinator 28 + | Unexpected_token 29 + | Expected_end_of_selector 30 + 31 + let to_string = function 32 + | Empty_selector -> "empty-selector" 33 + | Unterminated_string -> "unterminated-string" 34 + | Unterminated_escape -> "unterminated-escape" 35 + | Expected_identifier_after_hash -> "expected-identifier-after-hash" 36 + | Expected_identifier_after_dot -> "expected-identifier-after-dot" 37 + | Expected_attribute_name -> "expected-attribute-name" 38 + | Expected_closing_bracket -> "expected-closing-bracket" 39 + | Expected_equals_after_operator c -> 40 + Printf.sprintf "expected-equals-after-%c" c 41 + | Unexpected_character_in_attribute_selector -> 42 + "unexpected-character-in-attribute-selector" 43 + | Expected_pseudo_class_name -> "expected-pseudo-class-name" 44 + | Expected_closing_paren -> "expected-closing-paren" 45 + | Unexpected_character c -> Printf.sprintf "unexpected-character-%c" c 46 + | Expected_attribute_value -> "expected-attribute-value" 47 + | Expected_closing_bracket_or_operator -> 48 + "expected-closing-bracket-or-operator" 49 + | Expected_selector_after_combinator -> "expected-selector-after-combinator" 50 + | Unexpected_token -> "unexpected-token" 51 + | Expected_end_of_selector -> "expected-end-of-selector" 52 + 53 + let to_human_string = function 54 + | Empty_selector -> "Empty selector" 55 + | Unterminated_string -> "Unterminated string" 56 + | Unterminated_escape -> "Unterminated escape" 57 + | Expected_identifier_after_hash -> "Expected identifier after #" 58 + | Expected_identifier_after_dot -> "Expected identifier after ." 59 + | Expected_attribute_name -> "Expected attribute name" 60 + | Expected_closing_bracket -> "Expected ]" 61 + | Expected_equals_after_operator c -> 62 + Printf.sprintf "Expected = after %c" c 63 + | Unexpected_character_in_attribute_selector -> 64 + "Unexpected character in attribute selector" 65 + | Expected_pseudo_class_name -> "Expected pseudo-class name" 66 + | Expected_closing_paren -> "Expected )" 67 + | Unexpected_character c -> Printf.sprintf "Unexpected character: %c" c 68 + | Expected_attribute_value -> "Expected attribute value" 69 + | Expected_closing_bracket_or_operator -> "Expected ] or attribute operator" 70 + | Expected_selector_after_combinator -> "Expected selector after combinator" 71 + | Unexpected_token -> "Unexpected token" 72 + | Expected_end_of_selector -> "Expected end of selector"
+62
lib/html5rw/selector/selector_error_code.mli
··· 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 + 12 + type 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 + 48 + val 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 + 56 + val 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 + *)