mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57:59 +01:00
24 lines
No EOL
515 B
Elixir
24 lines
No EOL
515 B
Elixir
defmodule Search.IntParser do
|
|
import NimbleParsec
|
|
import Search.Helpers
|
|
|
|
fuzz =
|
|
string("~")
|
|
|> ignore()
|
|
|
|
int =
|
|
optional(ascii_char('-+'))
|
|
|> ascii_string([?0..?9], min: 1)
|
|
|> reduce({List, :to_string, []})
|
|
|> reduce(:to_int)
|
|
|
|
int_parser =
|
|
choice([
|
|
int |> concat(fuzz) |> integer(min: 1) |> reduce(:range) |> unwrap_and_tag(:int_range),
|
|
int |> unwrap_and_tag(:int)
|
|
])
|
|
|> eos()
|
|
|> label("an integer, like `3' or `-10'")
|
|
|
|
defparsec :parse, int_parser
|
|
end |