Skip to content

Fix parser to reject incomplete reductions like ([, ({, (( - #3139

Open
jjtolton wants to merge 1 commit into
mthom:masterfrom
jjtolton:issue-3138
Open

Fix parser to reject incomplete reductions like ([, ({, ((#3139
jjtolton wants to merge 1 commit into
mthom:masterfrom
jjtolton:issue-3138

Conversation

@jjtolton

Copy link
Copy Markdown
Contributor

Closes: #3138

@jjtolton
jjtolton marked this pull request as ready for review October 26, 2025 15:50
@UWN

UWN commented Oct 26, 2025

Copy link
Copy Markdown

Can you give an example where (( is involved in an incomplete reduction?

@UWN

UWN commented Oct 26, 2025

Copy link
Copy Markdown

... and where is a problem with the comma?

Comment thread src/tests/syntax_errors.pl Outdated
% Test that (( produces syntax error
test("(( should produce syntax_error", (
catch(
(read_from_chars("((}.", _), false),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This example is not very convincing, since it always produced a syntax error (for whatever reason). So what is its point?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

multitasking error, stand by

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

(... divergent branches, git status says I should do git pull)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

perhaps looking at the combined testing branch would be better:

https://github.com/jjtolton/scryer-prolog/tree/combined-testing

That has digits, this, and double bars

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

(... divergent branches, git status says I should do git pull)

Forget it, your combined branch is it!

Comment thread src/tests/syntax_errors.pl Outdated
% Test that {( produces syntax error (already tested in ISO conformity)
test("{( should produce syntax_error", (
catch(
(read_from_chars("{(}.", _), false),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

idem

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixes mthom#3138

The parser was incorrectly accepting expressions like ([ and ({
as valid syntax, parsing them as atoms instead of rejecting them as
incomplete reductions.

This fix adds checks in reduce_brackets() to reject when an opening
parenthesis is followed by:
- Opening bracket [
- Opening curly brace {

Note: (, and (( were already correctly rejected by existing checks.

This brings the behavior in line with how curly braces work, where
{[ and {( correctly produce syntax errors.

Added tests in src/tests/syntax_errors.pl to verify the fix and
prevent regressions.
jjtolton added a commit to jjtolton/scryer-prolog that referenced this pull request Nov 29, 2025
Reject invalid bracket combinations like ([) and ({) where
parentheses would incorrectly close list or curly brackets.

Related: PR mthom#3139, Issue #3 (bracket mismatch detection)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

Syntax: unexpected extension

2 participants