Skip to content

Commit 203dfa9

Browse files
committed
Tweaks
1 parent 9d3e3de commit 203dfa9

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

src/soup.ml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
(* This file is part of Lambda Soup, released under the MIT license. See
22
LICENSE.md for details, or visit https://github.com/aantron/lambdasoup. *)
33

4-
exception Parse_error of string
5-
64
module String =
75
struct
86
include String
@@ -433,6 +431,8 @@ let trimmed_texts node =
433431
|> List.map String.trim
434432
|> List.filter (fun s -> String.length s > 0)
435433

434+
exception Parse_error of string
435+
436436
module Selector :
437437
sig
438438
type t
@@ -807,12 +807,9 @@ struct
807807
| "$=" -> Suffix (name, value)
808808
| "*=" -> Substring (name, value)
809809
| _ ->
810-
Printf.sprintf
811-
"invalid attribute operator '%s'" operator
812-
|> parse_error)
813-
| Some _ ->
814-
parse_error
815-
"expected end of attribute selector (']')")))
810+
Printf.ksprintf parse_error
811+
"invalid attribute operator '%s'" operator)
812+
| Some _ -> parse_error "expected end of attribute selector (']')")))
816813

817814
let parse_class_selector stream =
818815
Stream.junk stream;
@@ -908,10 +905,8 @@ struct
908905
let selector = parse_parenthesized_value parse_simple_selector stream in
909906
Not selector
910907
| _ ->
911-
Printf.sprintf
912-
"unknown pseudo-class or pseudo-element ':%s'"
913-
function_
914-
|> parse_error)
908+
Printf.ksprintf parse_error
909+
"unknown pseudo-class or pseudo-element ':%s'" function_)
915910

916911
and parse_simple_selector stream =
917912
match Stream.peek stream with

src/soup.mli

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ let _ = ul |> previous_siblings |> elements in
6767
for other versions can be downloaded from the
6868
{{:https://github.com/aantron/lambdasoup/releases} releases page}. *)
6969

70-
(** {2 Exceptions} *)
7170

72-
(** Raised when a CSS selector given to {!select} and similar functions is syntactically invalid. *)
73-
exception Parse_error of string
7471

7572
(** {2 Types} *)
7673

@@ -110,6 +107,14 @@ val parse : string -> soup node
110107
Lambda Soup something other than bytes, see {{:#2_Parsingsignals} Parsing
111108
signals}. *)
112109

110+
exception Parse_error of string
111+
(** Raised when a CSS selector given to {!select} and similar functions is
112+
syntactically invalid.
113+
114+
Note that {!parse} does not raise this exception, because the parsing of
115+
HTML is done by {{:https://github.com/aantron/markup.ml} Markup.ml}. Lambda
116+
Soup proper only parses CSS selectors. *)
117+
113118
val select : string -> (_ node) -> element nodes
114119
(** [select selector node] is all the descendants of [node] matching CSS
115120
selector [selector]. All

test/test.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,9 @@ let suites = [
216216
assert_failure (Printf.sprintf "%s: got \"%s\"" selector s)
217217
| Soup.Parse_error message ->
218218
if (message <> expected_message) then assert_failure
219-
(Printf.sprintf "Incorrect parse error for selector '%s': expected '%s' but got '%s'"
220-
selector expected_message message)
219+
(Printf.sprintf
220+
"Incorrect parse error for '%s': expected '%s' but got '%s'"
221+
selector expected_message message)
221222
else true
222223
in
223224
if not result then

0 commit comments

Comments
 (0)