Skip to content

Commit 9322d19

Browse files
committed
Fix spaced bar syntax in codes mode
The spaced bar syntax `| |` failed with syntax_error(incomplete_reduction) when double_quotes flag was set to codes. The compact syntax `||` worked fine in both modes. Root cause: The spaced bar validation only accepted CompleteString and PartialString terms, but in codes mode "abc" becomes Term::Cons([97,98,99]). Fix: Add Term::Cons and empty list handling to spaced bar validation, matching the compact || validation logic. Also: - Add discontiguous(test/2) directive to double_bar.pl (needed because set_prolog_flag directives appear between test clauses) - Add double_bar_tests.stdout for proper CLI test registration
1 parent 49ec77c commit 9322d19

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

src/parser/parser.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,10 +1094,14 @@ impl<'a, R: CharRead> Parser<'a, R> {
10941094
}
10951095
}
10961096

1097+
// Check that the last term is a string literal (CompleteString, PartialString, or Cons from codes mode)
1098+
// Must match the validation for compact || below
10971099
let is_valid = if let Some(last_term) = self.terms.last() {
10981100
match last_term {
10991101
Term::CompleteString(_, _) => true,
11001102
Term::PartialString(_, _, _) => true,
1103+
Term::Cons(_, _, _) => true, // Allows codes mode: "abc" becomes [97,98,99]
1104+
Term::Literal(_, Literal::Atom(atom)) if *atom == atom!("[]") => true, // Empty string in codes mode
11011105
_ => false,
11021106
}
11031107
} else {

src/tests/double_bar.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
:- module(double_bar_tests, []).
22

33
:- use_module(test_framework).
4+
:- discontiguous(test/2).
45

56
% Tests for the double bar || operator
67
% Based on: https://www.complang.tuwien.ac.at/ulrich/iso-prolog/double_bar
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
All tests passed

0 commit comments

Comments
 (0)