OCaml HTML5 parser/serialiser based on Python's JustHTML
at main 2.8 kB view raw
1(** Structured expected messages from Nu validator. 2 3 This module parses Nu validator message strings into structured form, 4 enabling semantic comparison rather than string matching. *) 5 6(** Structured expected message *) 7type t = { 8 message: string; (** Full message text *) 9 error_code: Htmlrw_check.Error_code.t option; (** Parsed typed code *) 10 line: int option; (** Expected line number *) 11 column: int option; (** Expected column number *) 12 element: string option; (** Element context *) 13 attribute: string option; (** Attribute context *) 14 severity: [`Error | `Warning | `Info] option; (** Expected severity *) 15} 16 17(** Match quality - how well an actual message matches expected *) 18type match_quality = 19 | Exact_match 20 (** Perfect: message, code, and location all match *) 21 | Code_match 22 (** Error code matches but message text differs slightly *) 23 | Message_match 24 (** Full message matches but no typed code comparison *) 25 | Substring_match 26 (** Expected is substring of actual (legacy behavior) *) 27 | Severity_mismatch 28 (** Right message but wrong severity (error vs warning) *) 29 | No_match 30 (** Does not match *) 31 32(** Strictness configuration for matching *) 33type strictness = { 34 require_exact_message: bool; (** No substring matching *) 35 require_error_code: bool; (** Typed code must match if available *) 36 require_location: bool; (** Line/column must match *) 37 require_severity: bool; (** Severity must match *) 38} 39 40(** Lenient matching (current behavior) *) 41val lenient : strictness 42 43(** Exact message matching (no substring matching, but doesn't require typed codes) *) 44val exact_message : strictness 45 46(** Full strict matching (requires typed error code migration) *) 47val strict : strictness 48 49(** Parse a message string into structured form. 50 Attempts to recognize Nu validator message patterns and extract 51 element, attribute, and error code information. *) 52val parse : string -> t 53 54(** Parse a JSON-like structure. For internal use by the message loader. *) 55val parse_json_value : 56 get_string: (string -> string option) -> 57 get_int: (string -> int option) -> 58 message_field: string option -> 59 t 60 61(** Check if actual message matches expected. 62 Returns the quality of match achieved. *) 63val matches : strictness:strictness -> expected:t -> actual:Htmlrw_check.message -> match_quality 64 65(** Check if match quality is acceptable given strictness *) 66val is_acceptable : strictness:strictness -> match_quality -> bool 67 68(** Convert match quality to string for reporting *) 69val match_quality_to_string : match_quality -> string