Building blocks shared by the PostgREST grammars: quoted values, identifiers, field names with JSON paths, tree paths, the cast-name rule, and error helpers.
The defcombinator pieces are reused by other grammar modules through
parsec({PgRest.Grammar.Common, name}).
Summary
Functions
Whether name is an acceptable cast type name (see the module attributes for the
rule). This is the single definition used by the select grammar and Builder.cast/2.
The expectation text for a missing field name.
Parses a field (name plus JSON path), ignoring spaces and tabs around it.
Like parse_field/1, but a failure is {:fail, input, expecting}.
Parses a bare name (no JSON path), returning it and the rest, or :no_match.
Parses dotted names (client.not.or), consuming the whole text. Returns the names or
a PGRST100 error naming what.
Parses a query-string key such as a.b.col->x into its embed path and column field
(upstream pTreePath). The whole key must be consumed.
Rejects a text (or a list of texts) that contains a NUL byte, for identifiers.
Builds a PostgREST-style parse error: the message names the parsed what and the
column of the failure, the details say what was found and what was expected.
Takes the cast name at the start of rest (after a ::) and validates it with
cast_name?/1. Returns the name and the rest with blanks skipped.
Rejects a field whose name or JSON-path keys contain a NUL byte.
Functions
Whether name is an acceptable cast type name (see the module attributes for the
rule). This is the single definition used by the select grammar and Builder.cast/2.
@spec name_expecting() :: String.t()
The expectation text for a missing field name.
@spec parse_field(String.t()) :: {:ok, PgRest.AST.Field.t(), String.t()} | {:error, String.t()}
Parses a field (name plus JSON path), ignoring spaces and tabs around it.
Returns the field and the unparsed rest, or {:error, input} when no field starts
the input.
@spec parse_field(String.t(), String.t()) :: {:ok, PgRest.AST.Field.t(), String.t()} | {:fail, String.t(), String.t()}
Like parse_field/1, but a failure is {:fail, input, expecting}.
Parses a bare name (no JSON path), returning it and the rest, or :no_match.
@spec parse_names(String.t(), String.t()) :: {:ok, [String.t()]} | {:error, PgRest.Error.t()}
Parses dotted names (client.not.or), consuming the whole text. Returns the names or
a PGRST100 error naming what.
@spec parse_tree_path(String.t()) :: {:ok, {[String.t()], PgRest.AST.Field.t()}} | {:error, PgRest.Error.t()}
Parses a query-string key such as a.b.col->x into its embed path and column field
(upstream pTreePath). The whole key must be consumed.
@spec reject_nul(String.t() | [String.t()]) :: :ok | {:error, PgRest.Error.t()}
Rejects a text (or a list of texts) that contains a NUL byte, for identifiers.
@spec syntax_error( String.t(), String.t(), String.t(), String.t(), String.t(), keyword() ) :: PgRest.Error.t()
Builds a PostgREST-style parse error: the message names the parsed what and the
column of the failure, the details say what was found and what was expected.
full_input is the text the parser saw, rest the unparsed remainder at the failure
point, shown the text echoed in the message. Option quote: :string shows the
unexpected character as a string ("x") even where Parsec would show a character.
Takes the cast name at the start of rest (after a ::) and validates it with
cast_name?/1. Returns the name and the rest with blanks skipped.
@spec validate_field(PgRest.AST.Field.t()) :: :ok | {:error, PgRest.Error.t()}
Rejects a field whose name or JSON-path keys contain a NUL byte.