Current section
Files
Jump to
Current section
Files
src/pathern.erl
-module(pathern).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([match/2, match_patterns/2]).
-export_type([pathern/0]).
-type pathern() :: {pathern,
binary(),
binary(),
gleam@dict:dict(binary(), binary())}.
-file("/home/ram/code/gleam/pathern/src/pathern.gleam", 34).
-spec match(binary(), binary()) -> {ok, pathern()} | {error, nil}.
match(Path, Pattern) ->
Tokens = pathern@internal@lexer:tokenize(Pattern, [], 0),
case pathern@internal@parser:parse(Path, Tokens) of
{ok, Params} ->
{ok, {pathern, Path, Pattern, Params}};
{error, _} ->
{error, nil}
end.
-file("/home/ram/code/gleam/pathern/src/pathern.gleam", 61).
-spec match_patterns(binary(), list(binary())) -> {ok, pathern()} | {error, nil}.
match_patterns(Path, Patterns) ->
case Patterns of
[Head | Rest] ->
case match(Path, Head) of
{ok, Pattern} ->
{ok, Pattern};
{error, _} ->
match_patterns(Path, Rest)
end;
[] ->
{error, nil}
end.