Skip to content

Commit 36292a4

Browse files
author
Ed Schouten
committed
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
1 parent 2b8c852 commit 36292a4

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/Url/Parser.elm

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Url.Parser exposing
22
( Parser, string, int, s
3-
, (</>), map, oneOf, top, custom
3+
, (</>), map, oneOf, top, custom, remainder
44
, (<?>), query
55
, fragment
66
, parse
@@ -23,7 +23,7 @@ This module is primarily for parsing the `path` part.
2323
@docs Parser, string, int, s
2424
2525
# Path
26-
@docs (</>), map, oneOf, top, custom
26+
@docs (</>), map, oneOf, top, custom, remainder
2727
2828
# Query
2929
@docs (<?>), query
@@ -156,6 +156,23 @@ custom tipe stringToSomething =
156156
[]
157157

158158

159+
{-| Parse all remaining path segments as a `List String`.
160+
161+
blog : Parser (List String -> a) a
162+
blog =
163+
s "blog" </> remainder
164+
165+
-- /blog ==> []
166+
-- /blog/hello ==> [ "hello" ]
167+
-- /blog/hello/world ==> [ "hello", "world" ]
168+
-}
169+
remainder : Parser (List String -> a) a
170+
remainder =
171+
Parser <|
172+
\{ unvisited, params, frag, value } ->
173+
[ State [] params frag (value unvisited) ]
174+
175+
159176

160177
-- COMBINING PARSERS
161178

0 commit comments

Comments
 (0)