Skip to content

Wildcards stop before later elements, not only the next one (#427) (4.2.27) - #783

Merged
ddehilster merged 1 commit into
masterfrom
feature/smart-wildcards-427
Oct 14, 2026
Merged

ddehilster merged 1 commit into
masterfrom
feature/smart-wildcards-427

Conversation

@ddehilster

Copy link
Copy Markdown
Member

Closes #427.

Problem. While a wildcard was pending, the matcher searched for an optional element past the elements after it. In:

_xNIL <- the _xWILD _xWILD [opt match=(three)] _xWILD [one match=(bears)] @@

on "the big bears met three bears", the wildcard ran past the first "bears" to reach "three", and matched big bears met. To get the intended match you had to repeat the later elements in a fail list: _xWILD [fail=(three bears)].

Fix. An optional element is now absent if a later element matches first. "Later" means any element up to and including the next required one. So the wildcard stops at the first "bears" (wild=big, three absent).

  • Ties: when the optional element and a later one both match the same node, the optional element still wins, as before.
  • Bare wildcards: a bare _xWILD among the later elements ends the look, because what it will cover isn't known yet.
  • Direction: it works the same when matching leftward from a trigger.
  • Runtimes: both have it, with the same behaviour. Interpreted: Pat::laterMatches in matchRealRight/Left. Compiled: Arun::later_matches in match_left/right and special_left/right, built on NLP++: Overly broad @PRE conditions fail #449's stop_match, so it tests nodes exactly as the generated code does.

On keeping _xWILD vs. a new _xSMART (the issue suggested either). The change only affects one rule shape: a bare wildcard, then an optional element, then more elements. All 20 analyzers in analyzers/ (21 inputs, including parse-en-us) produce byte-identical output to 4.2.18, and so does the -DEV Full English Test. So this improves _xWILD itself.

Testing

  • New fixture tests/smart-wildcard, with CI steps for Windows and Linux, covering the NLP++ multiple wildcards (enhancement) #427 case, an optional element that comes first, a tie, and leftward matching. 4.2.18 gives the old results for the NLP++ multiple wildcards (enhancement) #427 and leftward cases.
  • I also built the fixture as a compiled analyzer DLL; its output is identical to the interpreted run.
  • All other Windows CI steps pass locally (the compiled-bridge step needs CI's packaged libraries).

🤖 Generated with Claude Code

….2.27)

With a wildcard pending, the matcher searched for an optional element past
the elements after it. In
    the _xWILD _xWILD [opt match=(three)] _xWILD [one match=(bears)]
on "the big bears met three bears" the wildcard ran past the first "bears"
to reach "three". Now an optional element is absent if a later element (up to
and including the next required one) matches first, so the wildcard stops at
the first "bears". The optional element still wins a tie at the same node, a
bare wildcard among the later elements ends the look, and it works matching
leftward from a trigger too.

Interpreted: Pat::laterMatches, checked in matchRealRight/Left. Compiled:
Arun::later_matches (via stop_match) in match_left/right and
special_left/right. Same behaviour in both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ddehilster
ddehilster merged commit 4069b86 into master Oct 14, 2026
7 checks passed
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.

NLP++ multiple wildcards (enhancement)

1 participant