Skip to content

Instantly share code, notes, and snippets.

@Akii
Created January 10, 2020 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akii/25ff228ca1f29c5b3653f8edb356f914 to your computer and use it in GitHub Desktop.
Save Akii/25ff228ca1f29c5b3653f8edb356f914 to your computer and use it in GitHub Desktop.
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