mthom / scryer-prolog

A modern Prolog implementation written mostly in Rust.
BSD 3-Clause "New" or "Revised" License
2.04k stars 118 forks source link

String parsing incorrect #1969

Open triska opened 1 year ago

triska commented 1 year ago

Currently, I get:

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

Also:

?- "\x0\\x0\" = [_,_].
   false, unexpected.
   true. % expected
UWN commented 1 year ago
?- "\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
triska commented 1 year ago

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.

UWN commented 1 year ago

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'.