Skip to content

Fix invalid (|) parsing when | is operator#3208

Open
jjtolton wants to merge 1 commit intomthom:masterfrom
jjtolton:fix-issue-7-bar-in-parens
Open

Fix invalid (|) parsing when | is operator#3208
jjtolton wants to merge 1 commit intomthom:masterfrom
jjtolton:fix-issue-7-bar-in-parens

Conversation

@jjtolton
Copy link
Contributor

@jjtolton jjtolton commented Dec 8, 2025

Summary

  • Fix bug where (|) incorrectly parsed when | is defined as an operator (e.g., via library(dcgs))
  • Two parser fixes in compute_arity_in_brackets() and reduce_brackets()
  • Update builtins.pl to use quoted '|' instead of (|)

Bug Report

jjtolton#7

Test Cases

All should throw syntax_error when | is operator (1105 xfy):

"(|)."           % bar alone in parens
"1*!(|)."        % in expression
"{1*!(|). }."    % in curly braces

Fix Details

  1. compute_arity_in_brackets(): Reject HeadTailSeparator at term positions
  2. reduce_brackets(): Reject HeadTailSeparator in bracket reduction per ISO s#360
  3. builtins.pl: Use '|' instead of (|) to reference bar operator

Related: PR #3206 (similar fix for [|] in lists)

Two fixes for (|) handling:

1. In compute_arity_in_brackets(): Reject HeadTailSeparator at term
   positions, since (|...) with nothing before | is invalid regardless
   of whether | is an operator.

2. In reduce_brackets(): Reject HeadTailSeparator in bracket reduction,
   since (|) must NEVER be converted to the atom | per ISO s#360.

3. In builtins.pl: Use quoted '|' instead of (|) to reference the bar
   operator, since (|) is no longer valid syntax.

Fixes: #7
( Priority >= 1001 ; Priority == 0 )
-> '$op'(Priority, OpSpec, Op)
; throw(error(permission_error(create, operator, (|)), op/3))) % www.complang.tuwien.ac.at/ulrich/iso-prolog/conformity_testing#72
; throw(error(permission_error(create, operator, '|'), op/3))) % www.complang.tuwien.ac.at/ulrich/iso-prolog/conformity_testing#72
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is properly fixed in a different PR addressing this syntax specifically, but a naked (|) is technically always invalid syntax and so must be changed. I need to change it here also for testing purposes.

@jjtolton jjtolton marked this pull request as ready for review December 8, 2025 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant