Skip to content

Commit

Permalink
Add a function for parsing all remaining path segments.
Browse files Browse the repository at this point in the history
Having an operation like this is useful for cases where you need to
forward/process arbitrary requests for a certain path prefix.

Fixes: elm#9
  • Loading branch information
Ed Schouten committed Apr 11, 2019
1 parent 2b8c852 commit 36292a4
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Url/Parser.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Url.Parser exposing
( Parser, string, int, s
, (</>), map, oneOf, top, custom
, (</>), map, oneOf, top, custom, remainder
, (<?>), query
, fragment
, parse
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 36292a4

Please sign in to comment.