Dust.Protocol.Glob (dustlayer v0.1.1)

Copy Markdown View Source

Segment-aware glob matching against Dust.Protocol.Path segment lists.

Mirrors DustProtocol.Glob from the canonical wire-protocol package.

Pattern grammar

A pattern is a non-empty list of pattern segments. Each segment is either:

  • "*" — matches exactly one path segment
  • "**" — matches one or more path segments; only valid in the tail position
  • "\*" — matches a path segment that is literally "*"
  • "\**" — matches a path segment that is literally "**"
  • any other string — matches that exact path segment

Patterns can also be given as rendered slash strings, decoded with the same JSON Pointer escape rules as Dust.Protocol.Path.

Summary

Types

compiled()

@type compiled() :: {:compiled, [token()]}

error()

@type error() ::
  :empty_path
  | :empty_segment
  | :invalid_escape
  | :not_a_string
  | :not_a_list
  | :wildcard_many_not_tail

pattern_input()

@type pattern_input() :: String.t() | [String.t(), ...]

token()

@type token() :: {:literal, String.t()} | :wildcard_one | :wildcard_many

Functions

compile(pattern)

@spec compile(pattern_input()) :: {:ok, compiled()} | {:error, error()}

compile!(pattern)

@spec compile!(pattern_input()) :: compiled()

match?(pattern, path)

@spec match?(compiled() | pattern_input(), [String.t()]) :: boolean()