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 a7d731a
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 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,24 @@ custom tipe stringToSomething =
[]


{-| Parse all remaining path segments as a `List String`.
blog : Parser (List String -> a) a
blog =
s "blog" </> remainder
-- /blog ==> Just []
-- /blog/hello ==> Just [ "hello" ]
-- /blog/hello/world ==> Just [ "hello", "world" ]
-- /foo/bar ==> Nothing
-}
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 a7d731a

Please sign in to comment.