scryer-prolog
scryer-prolog copied to clipboard
split_string & error(syntax_error(missing_quote),read_term
Using scryer-prolog v0.9.4-12-g6f7f979c
I get
?- split_string("8/8/8/4p1K1/2k1P3/8/8/8 b - - 0 1", " ", "\s\t\n", Args).
error(syntax_error(missing_quote),read_term/3:0).
With trealla I get
?- split_string("8/8/8/4p1K1/2k1P3/8/8/8 b - - 0 1", " ", "\s\t\n", Args).
Args = ["8/8/8/4p1K1/2k1P3/8/8/8 b - - 0 1","b","-","-","0","1"].
We can also observe the syntax error with the following generalization of the query:
?- split_string(_, _, "\s\t\n", _). error(syntax_error(missing_quote),read_term/3:0).
No further instantiation can remove this syntax error. To remove it, we must change the remaining fragment.
A shorter example:
?- Cs = "\s". error(syntax_error(missing_quote),read_term/3:0).
The ISO standard states:
A control escape sequence denotes the control character
indicated by the name of the symbolic control char,
iff that control character is an extended character of the
processor character set (6.5).
control escape sequence (* 6.4.2.1 *)
= backslash char (* 6.5.5 *),
symbolic control char (* 6.4.2.1 *) ;
symbolic control char (* 6.4.2.1 *)
= symbolic alert char (* 6.4.2.1 *)
| symbolic backspace char (* 6.4.2.1 *)
| symbolic carriage return char (* 6.4.2.1 *)
| symbolic form feed char (* 6.4.2.1 *)
| symbolic horizontal tab char (* 6.4.2.1 *)
| symbolic new line char (* 6.4.2.1 *)
| symbolic vertical tab char (* 6.4.2.1 *) ;
symbolic alert char (* 6.4.2.1 *)
= "a" ;
symbolic backspace char (* 6.4.2.1 *)
= "b" ;
symbolic carriage return char (* 6.4.2.1 *)
= "r" ;
symbolic form feed char (* 6.4.2.1 *)
= "f" ;
symbolic horizontal tab char (* 6.4.2.1 *)
= "t" ;
symbolic new line char (* 6.4.2.1 *)
= "n" ;
symbolic vertical tab char (* 6.4.2.1 *)
= "v" ;
Since \s is not among these control escape sequences, Scryer is correct to raise a syntax error in this example. In this manner, Scryer Prolog allows us to reliably detect non-portable syntax.
GNU Prolog uses a better description for the syntax error:
| ?- T = "\s".
uncaught exception: error(syntax_error('user_input:1 (char:7) unknown escape sequence'),read_term/3)
I have filed #2400 for this.