glob and fnmatch - #33
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds POSIX-style filename pattern matching and globbing to ListTalk, exposing them both as ListTalk:OS module primitives and as convenience methods on String, with accompanying evaluation tests.
Changes:
- Add
ListTalk:OS:fnmatch?(keyword-flagged) andListTalk:OS:globprimitives backed by libcfnmatch(3)/glob(3). - Add
String>>fnMatch?:andString>>fnMatchPathname?:methods for common matching modes. - Add evaluation tests covering default vs pathname matching and basic glob behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/eval-objects.lt | Adds tests for new String pattern-matching methods. |
| tests/eval-modules-os.lt | Adds tests for ListTalk:OS:fnmatch? and ListTalk:OS:glob. |
| src/modules/os.c | Implements fnmatch? and glob primitives and keyword-to-flag mapping. |
| src/classes/String.c | Implements two new String methods backed by fnmatch(). |
Suppressed comments (1)
src/classes/String.c:1033
- String>>fnMatchPathname?: also treats any nonzero fnmatch() result as a non-match. Consider distinguishing FNM_NOMATCH from other error returns and raising for the latter so invalid patterns/flags don't get swallowed.
return fnmatch(
LT_String_value_cstr(pattern),
LT_String_value_cstr(self),
FNM_PATHNAME
) == 0 ? LT_TRUE : LT_FALSE;
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+902
to
+906
| return fnmatch( | ||
| LT_String_value_cstr(pattern), | ||
| LT_String_value_cstr(string), | ||
| flags | ||
| ) == 0 ? LT_TRUE : LT_FALSE; |
Comment on lines
+1007
to
+1011
| return fnmatch( | ||
| LT_String_value_cstr(pattern), | ||
| LT_String_value_cstr(self), | ||
| 0 | ||
| ) == 0 ? LT_TRUE : LT_FALSE; |
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Suppressed comments (3)
src/modules/os.c:954
- primitive_os_glob currently returns an empty list for all non-zero glob() return codes, which masks real failures (e.g. GLOB_ABORTED/GLOB_NOSPACE) and makes flags like :err ineffective. Only GLOB_NOMATCH should be silently mapped to an empty list; other errors should raise.
result = glob(LT_String_value_cstr(pattern), flags, NULL, &matches);
builder = LT_ListBuilder_new();
if (result == 0){
for (index = 0; index < matches.gl_pathc; index++){
LT_ListBuilder_append(
src/modules/os.c:9
- _GNU_SOURCE is currently defined unconditionally for this translation unit. Elsewhere (e.g. src/classes/Thread.c:6-15) feature-test macros are gated per-platform; defining _GNU_SOURCE on non-glibc targets can inadvertently change header visibility/ABI and may trigger warnings.
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
src/modules/os.c:931
- The docstring says "glob errors produce an empty list", but the tests/expected behavior only mention ignoring the no-match case. If non-NOMATCH errors are intended to be surfaced (e.g. :err, OOM, permission errors), the docstring should reflect that more precisely.
This issue also appears on line 950 of the same file.
"Return paths matching a POSIX glob pattern; glob errors produce an empty list."
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.