package syto
All checked builds passInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=4af63e149ba034dfd123ad452712d2c2dc21679c5547af671c48eb07a14e9c54
sha512=dcd7c47d117a31b5549727ec9c86902fa139deaaa1481ec0505a6f95cf4cbd5361f382ee2ceedc8ad4e402a46e3f2e18079fe48a8b20ef4113e6ca2d03d80a3d
Description
Dependency-free OCaml library implementing POSIX fnmatch(3) filename pattern matching. Supports PATHNAME, NOESCAPE, PERIOD flags and CASEFOLD, GLOBSTAR extensions. UTF-8 codepoint-aware.
Added to opam-repository:
README
syto
POSIX fnmatch(3) filename pattern matching for OCaml.
Installation
opam install sytoMinimum OCaml version: 4.14.
Examples
All examples run in utop after #require "syto";;.
Literal and wildcard
Syto.match_pattern ~pattern:"*.ml" ~name:"foo.ml";;
(* - : bool = true *)
Syto.filter ~pattern:"*.ml" ["foo.ml"; "bar.txt"; "baz.ml"];;
(* - : string list = ["foo.ml"; "baz.ml"] *)PATHNAME — slashes are path boundaries
* and ? do not cross / when PATHNAME is set.
(* Without PATHNAME: * matches anything including / *)
Syto.match_pattern ~pattern:"*.ml" ~name:"src/foo.ml";;
(* - : bool = true *)
(* With PATHNAME: * stops at / *)
Syto.match_pattern ~flags:[`PATHNAME] ~pattern:"*.ml" ~name:"src/foo.ml";;
(* - : bool = false *)
Syto.match_pattern ~flags:[`PATHNAME] ~pattern:"src/*.ml" ~name:"src/foo.ml";;
(* - : bool = true *)PERIOD — dotfiles require an explicit dot
With PERIOD, a name component beginning with . is matched only by a pattern with a literal . at that position. Wildcards do not match it.
Syto.match_pattern ~flags:[`PERIOD] ~pattern:"*" ~name:".gitignore";;
(* - : bool = false *)
Syto.match_pattern ~flags:[`PERIOD] ~pattern:".*" ~name:".gitignore";;
(* - : bool = true *)
(* PERIOD applies after each / when PATHNAME is also set *)
Syto.match_pattern ~flags:[`PATHNAME; `PERIOD]
~pattern:"src/*" ~name:"src/.hidden";;
(* - : bool = false *)CASEFOLD — case-insensitive matching (ASCII)
Syto.match_pattern ~flags:[`CASEFOLD] ~pattern:"*.ML" ~name:"foo.ml";;
(* - : bool = true *)
Syto.filter ~flags:[`CASEFOLD] ~pattern:"readme*"
["README.md"; "readme.txt"; "notes.md"];;
(* - : string list = ["README.md"; "readme.txt"] *)GLOBSTAR — recursive path matching
With PATHNAME and GLOBSTAR, ** matches zero or more path components.
let flags = [`PATHNAME; `GLOBSTAR];;
Syto.match_pattern ~flags ~pattern:"src/**/*.ml" ~name:"src/lib/foo.ml";;
(* - : bool = true *)
Syto.match_pattern ~flags ~pattern:"src/**/*.ml" ~name:"src/foo.ml";;
(* - : bool = true — ** matches zero components *)
Syto.match_pattern ~flags ~pattern:"a/**" ~name:"a";;
(* - : bool = false — trailing ** requires at least one boundary *)
Syto.filter ~flags ~pattern:"**/*.ml"
["src/a.ml"; "src/lib/b.ml"; "other.txt"];;
(* - : string list = ["src/a.ml"; "src/lib/b.ml"] *)Flags
Flag | POSIX? | Effect |
|---|---|---|
| yes |
|
| yes |
|
| yes | a leading |
| no (GNU) | ASCII A–Z folded to a–z before comparison |
| no (bash) |
|
Flags may be combined freely. GLOBSTAR without PATHNAME makes ** behave identically to *.
filter vs match_pattern
Syto.filter ~pattern names and List.filter (fun n -> Syto.match_pattern ~pattern ~name:n) names produce the same result. Use filter when applying one pattern to many names; it parses the pattern once. Use match_pattern for one-off checks or when testing multiple patterns against one name.
POSIX deviations
- Matching operates on UTF-8 codepoints, not locale-dependent bytes.
?matches one Unicode codepoint. - Collating elements
[.ch.]and equivalence classes[=a=]raiseError. [a-b-c]raisesError; POSIX parses it as rangea-bplus literal-c.CASEFOLDfolds ASCII A–Z only. Cyrillic and other non-ASCII letters are compared by codepoint value.GLOBSTARis a non-POSIX extension (common in bash and gitignore).
Documentation
Extended examples and integration patterns: docs/guide.md.
API reference: dune build @doc or the opam package documentation.
License
ISC. See LICENSE.
Optional Dependencies
None
Used by
None
Conflicts
None
Build status
Results of building syto with each compiler on check.ci.ocaml.org, run of against opam-repository 8a77e58. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 0.1.0 (this version) | n/a | good | good | good | good |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure