Pudu programming language
Menu
API reference

Std.Glob.matches

1 declaration

fn

matches: Str -> Str -> Bool

This is a callable function.

What it does

Whether a path matches a pattern written the way a shell writes one.

The vocabulary is small and fixed, which is the point: a glob is written by

a person into a configuration file — files to include, paths to ignore,

routes to match — and every piece of it has to be guessable without a

reference.

- ? matches one character, but never a separator.

- * matches any run of characters within one segment, never a separator.

- ** matches whole segments, separators and all.

- [abc] and [a-z] match one of a set, [!abc] one outside it.

- \ makes the next character ordinary.

The separator rule is what makes a glob a path pattern rather than a text

pattern: src/*.pudu names files in one directory and src/**/*.pudu

names them at any depth. A * that crossed separators would make the two

the same, and there would be no way to write the first.

For matching text rather than paths, use Std.Regex.

Whether a path matches a pattern.

The pattern is read into pieces, and the path is walked once while holding

every piece the text so far could have reached. Each character advances all

of them together, so no choice is ever retried: the work is the path's

length times the pattern's, whatever the pattern holds. Trying each length

a * could take and backtracking made *a*a*a*a*a*a*a*b against forty

as run for over a minute, and recursed once per *.

Read the signature

  • The text after the name is the type checked by Pudu.
  • Read arrows from left to right: inputs come first, and the final type is returned.

Back to Std.GlobSearch related declarations