package cascade
Module Cascade.ErrorSource
Parse errors, sealed.
Every error is anchored to a Loc.t and labelled with the Sort.t of the IR node the parser was building when the failure occurred. The kind variant is closed: every CSS-syntax-level failure that the parser can emit is enumerated here.
type kind = | Sort_mismatch of {}(*Got a node of the wrong category, e.g. a component where a declaration was required.
*)| Unexpected_token of Token.kind(*Hit a token that has no place in the current production.
*)| Missing_token of string(*Expected a specific lexical thing, e.g.
*)"';'"or"')'".| Bad_selector of string(*Selector parser rejected the prelude; payload is a short reason.
*)| Bad_value of {}(*Property value validator rejected the right-hand side.
*)| Bad_condition of {}(*At-rule prelude (e.g.
*)@supports) rejected by its condition grammar.| Unknown_at_rule of string(*At-keyword name has no registered handler.
*)| Unterminated of Sort.t
pp_kind renders just the reason, e.g. expected <ident> but found <delim '.'>.
pp renders the located, sort-tagged error, e.g. expected <ident> but found <delim '.'> at [12-13] (in selector).
Construction and raising
Two flavours, Stdlib.failwith-style:
- Value constructors (
sort_mismatch,bad_selector, ...) build ant. Use when collecting non-fatal warnings, e.g.Parser.stylesheet. - Raising constructors (
fail_sort_mismatch,fail_bad_selector, ...) build the same error and immediately raiseParse_error. Use at the point of failure inside a decoder.
Raised by parsers (and the Cursor helpers) on the first unrecoverable failure.
Raises Parse_error with the given value.
with_context label f runs f () and, on a raised Parse_error, prepends label to the error's context path. Compose on every descent into a named sub-production (:is(), [attr], nth-child, ...) to build breadcrumb paths like ":is()/.foo".
val v :
?path:Loc.Path.t ->
?source:string ->
?filename:string ->
loc:Loc.t ->
sort:Sort.t ->
kind ->
tv ~loc ~sort kind builds an Error.t.
with_filename ~filename t stamps filename onto t when t does not already carry one. Used by entry points that know the source filename to annotate warnings collected by inner readers.
with_property property t fills in the property name of a Bad_value error raised without one - the typed value readers reject a right-hand side without knowing which property they serve, so the declaration parser stamps it back on. A non-Bad_value error, or one that already names a property, is returned unchanged.
context t is the structured error context.
Value constructors
sort_mismatch loc ~sort ~expected ~found flags a category mismatch.
unexpected_token loc ~sort k flags a stray token in a sort production.
missing_token loc ~sort what flags an expected lexeme that wasn't found.
bad_selector loc reason flags a selector the validator rejected.
bad_value loc ~property ~reason flags a failed property value.
bad_condition loc ~at_rule ~reason flags a failed at-rule prelude.
unknown_at_rule loc name flags an \@name keyword with no handler.
unterminated loc s flags an EOF inside an unclosed node of sort s.
Raising constructors
fail_x args is fail (x args).
fail_sort_mismatch loc ~sort ~expected ~found raises sort_mismatch.
fail_unexpected_token loc ~sort k raises unexpected_token.
fail_missing_token loc ~sort what raises missing_token.
fail_bad_selector loc reason raises bad_selector.
fail_bad_value loc ~property ~reason raises bad_value.
fail_bad_condition loc ~at_rule ~reason raises bad_condition.
fail_unknown_at_rule loc name raises unknown_at_rule.
fail_unterminated loc s raises unterminated.