The predicates of this section form a tightly related set for realising premature successful or failing exits from a block. These predicates are first of all useful for error-recovery. They were primarily implemented for compatibility reasons.
fail(Label) :- !(Label), fail. |
The example below illustrate these constructs to immediately report a syntax-error from a `deep-down' procedure to the outside world without passing it as an argument `all-over-the-place'.
parse(RuleSet, InputList, Rest) :- block(syntaxerror, phrase(RuleSet, InputList, Rest), Error), ( var(Error) -> true ; format('Syntax-error: ~w~n', Error), fail ). integer(N) --> digit(D1), !, digits(Ds), { name(N, [D1|Ds]) }. digits([D|R]) --> digit(D), digits(R). digits(_) --> letter(_), !, { exit(syntaxerror, 'Illegal number') }. digits([]) --> []. digit(D, [D|R], R) :- between(0'0, 0'9, D). letter(D, [D|R], R) :- between(0'a, 0'z, D). |