OCaml HTML5 parser/serialiser based on Python's JustHTML
at main 2.6 kB view raw
1(** HTML5 validation messages. 2 3 This module provides types for validation messages including errors, 4 warnings, and informational messages with source location tracking. *) 5 6(** Message severity levels. *) 7type severity = 8 | Error (** Conformance error - document is invalid *) 9 | Warning (** Conformance warning - likely problematic *) 10 | Info (** Informational - suggestions for improvement *) 11 12(** Source location information. *) 13type location = { 14 line : int; (** 1-indexed line number *) 15 column : int; (** 1-indexed column number *) 16 end_line : int option; (** Optional end line for ranges *) 17 end_column : int option; (** Optional end column *) 18 system_id : string option; (** File path or URL *) 19} 20 21(** Unified error code type covering both parse errors and conformance errors. *) 22type error_code = 23 | Parse_error of Html5rw.Parse_error_code.t 24 (** Parse error from the HTML5 tokenizer/parser *) 25 | Conformance_error of Error_code.t 26 (** Conformance error from semantic validation *) 27 28(** A validation message. *) 29type t = { 30 severity : severity; 31 message : string; (** Human-readable description *) 32 error_code : error_code; (** Typed error code *) 33 location : location option; 34 element : string option; (** Element name if relevant *) 35 attribute : string option; (** Attribute name if relevant *) 36 extract : string option; (** Source excerpt *) 37} 38 39(** {1 Constructors} *) 40 41(** Create a message from a conformance error code. *) 42val of_conformance_error : 43 ?location:location -> 44 ?element:string -> 45 ?attribute:string -> 46 ?extract:string -> 47 Error_code.t -> 48 t 49 50(** Create a message from a parse error code. *) 51val of_parse_error : 52 ?location:location -> 53 ?element:string -> 54 ?attribute:string -> 55 ?extract:string -> 56 message:string -> 57 Html5rw.Parse_error_code.t -> 58 t 59 60(** Create a location record. *) 61val make_location : 62 line:int -> 63 column:int -> 64 ?end_line:int -> 65 ?end_column:int -> 66 ?system_id:string -> 67 unit -> 68 location 69 70(** {1 Utilities} *) 71 72(** Get the string representation of an error code. *) 73val error_code_to_string : error_code -> string 74 75(** {1 Formatting} *) 76 77(** Convert severity to string representation. *) 78val severity_to_string : severity -> string 79 80(** Pretty-print severity. *) 81val pp_severity : Format.formatter -> severity -> unit 82 83(** Pretty-print location. *) 84val pp_location : Format.formatter -> location -> unit 85 86(** Pretty-print a validation message. *) 87val pp : Format.formatter -> t -> unit 88 89(** Convert a validation message to a string. *) 90val to_string : t -> string