Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,9 @@ impl<'a, R: CharRead> Parser<'a, R> {
for (i, desc) in self.stack.iter().rev().enumerate() {
if i % 2 == 0 {
// expect a term or non-comma operator.
if let TokenType::Comma = desc.tt {
// HeadTailSeparator at a term position means [|...] with nothing before |
// which is invalid regardless of whether | is an operator.
if desc.tt == TokenType::Comma || desc.tt == TokenType::HeadTailSeparator {
return None;
} else if is_term!(desc.spec) || is_op!(desc.spec) || is_negate!(desc.spec) {
arity += 1;
Expand Down
23 changes: 23 additions & 0 deletions src/tests/issue_5_bar_list.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
:- module(issue_5_bar_list_tests, []).
:- use_module(test_framework).
:- use_module(library(charsio)).

setup :-
op(1105, xfy, '|').

throws_syntax_error(Input) :-
catch(
(read_from_chars(Input, _), fail),
error(syntax_error(_), _),
true
).

test("[|] in curly with space before }", throws_syntax_error("{1*[|]. }.")).
test("[|] in curly with spaces throughout", throws_syntax_error("{ ! * [ | ] * ! }.")).
test("[|] in curly no spaces", throws_syntax_error("{!*[|]*!}.")).
test("[|] without braces", throws_syntax_error("!*[|]*!.")).
test("[|] with parens", throws_syntax_error("(!*[|]*!).")).
test("[|] ending with number", throws_syntax_error("!*[|]*1.")).
test("[|] ending with variable", throws_syntax_error("!*[|]*A.")).
test("[|] simple case with space", throws_syntax_error("{1*[|]. }.")).
test("[|] simple case no space", throws_syntax_error("{1*[|].}.")).
1 change: 1 addition & 0 deletions tests/scryer/cli/src_tests/issue_5_bar_list.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
All tests passed
1 change: 1 addition & 0 deletions tests/scryer/cli/src_tests/issue_5_bar_list.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
args = ["-f", "--no-add-history", "src/tests/issue_5_bar_list.pl", "-f", "-g", "use_module(library(issue_5_bar_list_tests)), issue_5_bar_list_tests:setup, issue_5_bar_list_tests:main_quiet(issue_5_bar_list_tests)"]
Loading