From 40619c8184b9886fd709d0a046de21a0ac609f43 Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Sat, 25 Apr 2020 19:59:12 +0200 Subject: [PATCH] ENHANCED: Throw domain errors in char_type/2 for wrong types This is especially important because a few of our names diverge from ctype(3), and we better inform programmers when the type they are using is not available at all. --- src/prolog/lib/charsio.pl | 58 ++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/src/prolog/lib/charsio.pl b/src/prolog/lib/charsio.pl index df0e050b..ead86e23 100644 --- a/src/prolog/lib/charsio.pl +++ b/src/prolog/lib/charsio.pl @@ -60,36 +60,44 @@ extend_var_list_([V|Vs], N, VarList, NewVarList, VarType) :- char_type(Char, Type) :- ( var(Char) -> throw(error(instantiation_error, char_type/2)) ; atom_length(Char, 1) -> - ( ground(Type) -> '$char_type'(Char, Type) - ; Type = symbolic_control, '$char_type'(Char, Type) - ; Type = layout, '$char_type'(Char, Type) - ; Type = symbolic_hexadecimal, Char = x - ; Type = octal_digit, '$char_type'(Char, Type) - ; Type = binary_digit, '$char_type'(Char, Type) - ; Type = hexadecimal_digit, '$char_type'(Char, Type) - ; Type = exponent, '$char_type'(Char, Type) - ; Type = sign, '$char_type'(Char, Type) - ; Type = upper, '$char_type'(Char, Type) - ; Type = lower, '$char_type'(Char, Type) - ; Type = graphic, '$char_type'(Char, Type) - ; Type = alpha, '$char_type'(Char, Type) - ; Type = decimal_digit, '$char_type'(Char, Type) - ; Type = alnum, '$char_type'(Char, Type) - ; Type = meta, '$char_type'(Char, Type) - ; Type = solo, '$char_type'(Char, Type) - ; Type = prolog, '$char_type'(Char, Type) - ; Type = alphabetic, '$char_type'(Char, Type) - ; Type = whitespace, '$char_type'(Char, Type) - ; Type = control, '$char_type'(Char, Type) - ; Type = numeric, '$char_type'(Char, Type) - ; Type = ascii, '$char_type'(Char, Type) - ; Type = ascii_punctuation, '$char_type'(Char, Type) - ; Type = ascii_graphic, '$char_type'(Char, Type) + ( ground(Type) -> + ( ctype(Type) -> + '$char_type'(Char, Type) + ; throw(error(domain_error(char_type, Type), char_type/2)) + ) + ; ctype(Type), + '$char_type'(Char, Type) ) ; throw(error(type_error(in_character, Char), char_type/2)) ). +ctype(alnum). +ctype(alpha). +ctype(alphabetic). +ctype(ascii). +ctype(ascii_graphic). +ctype(ascii_punctuation). +ctype(binary_digit). +ctype(control). +ctype(decimal_digit). +ctype(exponent). +ctype(graphic). +ctype(hexadecimal_digit). +ctype(layout). +ctype(lower). +ctype(meta). +ctype(numeric). +ctype(octal_digit). +ctype(prolog). +ctype(sign). +ctype(solo). +ctype(symbolic_control). +ctype(symbolic_hexadecimal). +ctype(upper). +ctype(whitespace). + + get_single_char(C) :- ( var(C) -> '$get_single_char'(C) ; atom_length(C, 1) -> '$get_single_char'(C) -- 2.54.0