From 36292a4810a3dbf0165b2cfaa81b62c08f684625 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Thu, 11 Apr 2019 09:26:06 +0200 Subject: [PATCH] Add a function for parsing all remaining path segments. Having an operation like this is useful for cases where you need to forward/process arbitrary requests for a certain path prefix. Fixes: #9 --- src/Url/Parser.elm | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Url/Parser.elm b/src/Url/Parser.elm index 4a9f4c9..83b43ae 100644 --- a/src/Url/Parser.elm +++ b/src/Url/Parser.elm @@ -1,6 +1,6 @@ module Url.Parser exposing ( Parser, string, int, s - , (), map, oneOf, top, custom + , (), map, oneOf, top, custom, remainder , (), query , fragment , parse @@ -23,7 +23,7 @@ This module is primarily for parsing the `path` part. @docs Parser, string, int, s # Path -@docs (), map, oneOf, top, custom +@docs (), map, oneOf, top, custom, remainder # Query @docs (), query @@ -156,6 +156,23 @@ custom tipe stringToSomething = [] +{-| Parse all remaining path segments as a `List String`. + + blog : Parser (List String -> a) a + blog = + s "blog" remainder + + -- /blog ==> [] + -- /blog/hello ==> [ "hello" ] + -- /blog/hello/world ==> [ "hello", "world" ] +-} +remainder : Parser (List String -> a) a +remainder = + Parser <| + \{ unvisited, params, frag, value } -> + [ State [] params frag (value unvisited) ] + + -- COMBINING PARSERS