lexer fixups

This commit is contained in:
Liam P. White 2019-08-26 10:23:16 -04:00
parent a4c4afa350
commit a2638288a3

View file

@ -34,8 +34,7 @@ defmodule Philomena.Search.Lexer do
int = int =
optional(ascii_char('-+')) optional(ascii_char('-+'))
|> ascii_char([?0..?9]) |> ascii_string([?0..?9], min: 1)
|> times(min: 1)
|> reduce({List, :to_string, []}) |> reduce({List, :to_string, []})
|> reduce(:to_number) |> reduce(:to_number)
|> unwrap_and_tag(:int) |> unwrap_and_tag(:int)
@ -43,9 +42,8 @@ defmodule Philomena.Search.Lexer do
number = number =
optional(ascii_char('-+')) optional(ascii_char('-+'))
|> ascii_char([?0..?9]) |> ascii_string([?0..?9], min: 1)
|> times(min: 1) |> optional(ascii_char('.') |> ascii_string([?0..?9], min: 1))
|> optional(ascii_char('.') |> ascii_char([?0..?9]) |> times(min: 1))
|> reduce({List, :to_string, []}) |> reduce({List, :to_string, []})
|> reduce(:to_number) |> reduce(:to_number)
|> unwrap_and_tag(:number) |> unwrap_and_tag(:number)
@ -381,13 +379,13 @@ defmodule Philomena.Search.Lexer do
literal = literal =
full_choice(unquote(for f <- literal_fields, do: [string: f])) full_choice(unquote(for f <- literal_fields, do: [string: f]))
|> unwrap_and_tag(:literal_field) |> unwrap_and_tag(:literal_field)
|> ignore(eq) |> concat(eq)
|> concat(text) |> concat(text)
ngram = ngram =
full_choice(unquote(for f <- ngram_fields, do: [string: f])) full_choice(unquote(for f <- ngram_fields, do: [string: f]))
|> unwrap_and_tag(:ngram_field) |> unwrap_and_tag(:ngram_field)
|> ignore(eq) |> concat(eq)
|> concat(text) |> concat(text)
custom = custom =
@ -400,7 +398,7 @@ defmodule Philomena.Search.Lexer do
ignore(quot) ignore(quot)
|> full_choice(unquote(for f <- literal_fields, do: [string: f])) |> full_choice(unquote(for f <- literal_fields, do: [string: f]))
|> unwrap_and_tag(:literal_field) |> unwrap_and_tag(:literal_field)
|> ignore(eq) |> concat(eq)
|> concat(quoted_text) |> concat(quoted_text)
|> ignore(quot) |> ignore(quot)
@ -408,7 +406,7 @@ defmodule Philomena.Search.Lexer do
ignore(quot) ignore(quot)
|> full_choice(unquote(for f <- ngram_fields, do: [string: f])) |> full_choice(unquote(for f <- ngram_fields, do: [string: f]))
|> unwrap_and_tag(:ngram_field) |> unwrap_and_tag(:ngram_field)
|> ignore(eq) |> concat(eq)
|> concat(quoted_text) |> concat(quoted_text)
|> ignore(quot) |> ignore(quot)