scryer-prolog icon indicating copy to clipboard operation
scryer-prolog copied to clipboard

String parsing incorrect

Open triska opened this issue 2 years ago • 4 comments

Currently, I get:

$ scryer-prolog
?- use_module(library(lists)).
   true.
?- length("\x0\\x0\", L).
   L = 1, unexpected.
   L = 2. % expected

triska avatar Aug 20 '23 12:08 triska

Also:

?- "\x0\\x0\" = [_,_].
   false, unexpected.
   true. % expected

triska avatar Aug 20 '23 13:08 triska

?- "\x0\" = [Null].
   Null = '\x0\'. % ok
?- "ab\x0\" = [A,B,Null].
   false, unexpected.
   A = a, B = b, Null = '\x0\'.
?- "ab\x0\" = [A,B].
   A = a, B = b, unexpected.
   false. % expected, but not found

UWN avatar Aug 20 '23 17:08 UWN

This issue may be confined to parsing strings, at least the following works exactly as expected:

?- A = '\x0\\x0\', atom_chars(A, Cs), Cs = [_,_].
   A = '\x0\\x0\', Cs = "\x0\\x0\".

So, 0-bytes are correctly handled in this case.

triska avatar Aug 23 '23 22:08 triska

So in a (single) quoted token (* 6.4.2 *) the null character is handled correctly whereas in a double quoted list token (* 6.4.6 *) it is ignored, but only if double quotes denote a list of characters! So it is not the parsing process as such which is incorrect, but rather this conversion.

?- set_prolog_flag(double_quotes,chars).
   true.
?- Cs = "a\x0\b".
   Cs = "ab", unexpected.
?- set_prolog_flag(double_quotes,codes).
   true.
?- Cs = "a\x0\b".
   Cs = [97,0,98].
?- set_prolog_flag(double_quotes,atom).
   true.
?- Cs = "a\x0\b".
   Cs = 'a\x0\b'.

UWN avatar Aug 24 '23 06:08 UWN