Created
January 10, 2020 17:45
-
-
Save Akii/25ff228ca1f29c5b3653f8edb356f914 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse_range(range, max_limit \\ 500) do | |
range_p = | |
either( | |
many1(alphanumeric()) |> ignore(space()) |> string() |> ignore(char(";")), | |
many1(alphanumeric()) |> ignore(char(";")) | |
) | |
limit_p = fn a -> a |> ignore(string("limit ")) |> integer() |> ignore(char(";")) end | |
offset_p = fn a -> a |> ignore(string("offset ")) |> integer() |> ignore(char(";")) end | |
order_p = fn a -> | |
a | |
|> ignore(string("order ")) | |
|> either( | |
string("asc"), | |
string("desc") | |
) | |
end | |
content_range = | |
Combine.parse( | |
range, | |
range_p | |
|> limit_p | |
|> offset_p | |
|> order_p | |
) | |
IO.inspect(content_range) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment