Skip to content

Conversation

@NWilson
Copy link
Member

@NWilson NWilson commented May 13, 2025

Currently, pcre2test prints the erroroffset as a simple number, which makes it impossible in the test output to see where it's actually pointing.

I have added printing of the relevant portion of the pattern, to show visually where the offset points.

There is also a new function error_direction() where I have started to classify which PCRE2 errors point to the left or right of the erroroffset. When I have fixed this all to be consistent to my satisfaction, I will document this so that clients have a better way to indicate which character is wrong in a regex.

This PR is almost test-only, with just a handful of tiny changes in pcre2_compile.c.

@NWilson NWilson force-pushed the user/niwilson/erroroffset-existing-tests branch from 7e7730c to e83c753 Compare May 13, 2025 13:50
Copy link
Collaborator

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

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

Nice improvement!


/(?(n/utf
Failed: error 142 at offset 4: syntax error in subpattern name (missing terminator?)
here: (?(n |<--|
Copy link
Collaborator

Choose a reason for hiding this comment

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

I often see using the caret (^)

/(?(n/utf
     ^
Failed: error 142 at offset 4: syntax error in subpattern name (missing terminator?)

Copy link
Member Author

@NWilson NWilson May 14, 2025

Choose a reason for hiding this comment

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

That would be a better user interface for an actual tool using PCRE2. I did consider it, and even attempted it. However, editors and terminals differ in how they render Unicode combining characters with multiple codepoints, for example characters with decomposing accents. Rendering the caret on the line below would be less precise for the purpose of a testing tool.

So, I chose to use this approach in pcre2test for maximal clarity.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok

@NWilson NWilson force-pushed the user/niwilson/erroroffset-existing-tests branch from e8e39e0 to 534e04c Compare May 14, 2025 11:19
@NWilson NWilson merged commit 716c1fd into master May 21, 2025
35 checks passed
@NWilson NWilson deleted the user/niwilson/erroroffset-existing-tests branch May 21, 2025 18:51
carenas added a commit to carenas/pcre2 that referenced this pull request Aug 4, 2025
No longer needed Since 716c1fd (Add test output to make
erroroffsets more readable (PCRE2Project#750), 2025-05-21).
carenas added a commit to carenas/pcre2 that referenced this pull request Aug 6, 2025
No longer needed Since 716c1fd (Add test output to make
erroroffsets more readable (PCRE2Project#750), 2025-05-21).
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.

3 participants