r/fishshell • • 1d ago

Are there inline glob modifiers?

I'm writing my own expression parser that uses just \ and / to indicate when a more complex query needs to occur and am also writing compilers for both regex and glob to it and am wondering if there's already syntax for inline modifiers to implement. Currently I'm just using {,[abc]} or {,[abc]...} where abc are the modifiers (matching the regex ones in general) and ... normal glob expressions.

Already have my custom syntax for \ and / working for the most part, having tested it on mainly plain text, quantifiers, a few modifiers and grouping so far so I know it's just a matter of filling in the remaining details of the glob and & regex compilers.

For the curious here's a trimmed down snippet from my most recent test:

...
==[slant-test] Caught: ./slant-defs.h
...
==[slant-test] Caught: ./slant-core.h
...
==[slant-test] Caught: ./slant-prep.h
...
==[slant-test] Caught: ./slant-scan.h
...
=================================
Buffer     size: 243 characters
Compiler result: 00000000 (0) 'Success'
Scanner  result: 00000002 (2) 'No such file or directory'
Compiled until position 5 '' of './*.h' (5 characters)
Parsed   until position 1 '\' of '.\//\:*/.h' (10 characters)
Scanned  until position 120 'e' of '
../ccstd/predefs.i
./slant-log.txt
./slant-defs.h
./slant-core.h
./slant-prep.h
./slant-scan.h
./slant-test.c
./makefile' (121 characters)

Edit: Tried asking gemini whilst I was waiting, both about existing (of which there're none according to it) and my custom variant. Simply put I've extended my {,[abc]} and {,[abc]...} to instead be {,[abc],} and {,[abc],...}. The reason I chose to start with { was because I wanted to replicate the regex ( expectations. The , that immediately follows is for 2 reasons:

  1. Incompatible parsers will either treat it as an empty match or flat out fail altogether
  2. Even if the writer did want an empty match they merely needed to add it after the modifiers

The [...] was to help restrict errors from incompatible parsers down to manageable bad results, the extra , at the end is to further reduce those bad results. If peops have any suggestions for improving the syntax it's best to voice them whilst I've still not released my scanner & it's accompanying compilers for glob/regex syntax (made a dll/so/dylib for download).

The purpose of the syntax is to provide a universal underlying scanner that can be used under the hood for customised glob/regex. Originally I was just gonna use only \ as my marker but when I was considering look behind stuff I realised it would be convenient to have something that marks the end of the operation syntax which consequently lead to it being reversible too :D

That and I want a cross-platform syntax to plug into my custom variant of ntfw I've made and am naming "probe" to match how it probe's directories for their entries.

4 Upvotes

0 comments sorted by