PgRest.Grammar.Common (PgRest v0.2.0)

Copy Markdown View Source

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

blank__0(rest, acc, stack, context, line, offset)

blank__1(rest, acc, stack, context, comb__line, comb__offset)

blank__2(rest, acc, stack, context, comb__line, comb__offset)

blank__3(rest, user_acc, list, context, line, offset)

blank__4(rest, acc, stack, context, line, offset)

blank__5(rest, acc, stack, context, line, offset)

cast_name?(name)

@spec cast_name?(term()) :: boolean()

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.

field__0(rest, acc, stack, context, line, offset)

field__1(rest, acc, stack, context, line, offset)

field__2(rest, acc, stack, context, line, offset)

field__3(rest, user_acc, list, context, line, offset)

field__4(rest, acc, stack, context, line, offset)

field_name__0(rest, acc, stack, context, line, offset)

field_name__1(rest, acc, stack, context, line, offset)

field_name__2(rest, acc, stack, context, line, offset)

field_name__3(rest, acc, stack, context, line, offset)

field_name__4(rest, acc, stack, context, line, offset)

field_name__5(_, _, list, _, _, _)

field_name__6(rest, acc, stack, context, line, offset)

field_name__7(rest, acc, stack, context, comb__line, comb__offset)

field_name__8(rest, acc, stack, context, line, offset)

field_name__9(rest, user_acc, list, context, line, offset)

field_name__10(rest, acc, stack, context, line, offset)

field_name__11(inner_rest, inner_acc, list, inner_context, inner_line, inner_offset)

field_name__12(rest, user_acc, list, context, line, offset)

field_name__13(rest, acc, list, context, line, offset)

field_name__14(_, _, stack, _, _, _)

field_name__15(rest, acc, stack, context, line, offset)

field_name__16(rest, acc, list, context, line, offset)

identifier__0(rest, acc, stack, context, line, offset)

identifier__1(rest, acc, stack, context, line, offset)

identifier__2(rest, acc, stack, context, comb__line, comb__offset)

identifier__3(rest, acc, stack, context, comb__line, comb__offset)

identifier__4(rest, user_acc, list, context, line, offset)

identifier__5(rest, acc, stack, context, line, offset)

identifier__6(rest, user_acc, list, context, line, offset)

identifier__7(rest, acc, stack, context, line, offset)

json_path__0(rest, acc, stack, context, line, offset)

json_path__1(_, _, list, _, _, _)

json_path__2(rest, acc, stack, context, line, offset)

json_path__3(rest, acc, stack, context, comb__line, comb__offset)

json_path__4(rest, acc, stack, context, line, offset)

json_path__5(rest, user_acc, list, context, line, offset)

json_path__6(rest, acc, stack, context, line, offset)

json_path__7(rest, acc, list, context, line, offset)

json_path__8(rest, acc, stack, context, line, offset)

json_path__9(rest, acc, stack, context, line, offset)

json_path__10(rest, acc, stack, context, line, offset)

json_path__11(rest, acc, stack, context, comb__line, comb__offset)

json_path__12(rest, acc, stack, context, comb__line, comb__offset)

json_path__13(rest, user_acc, list, context, line, offset)

json_path__14(rest, acc, stack, context, line, offset)

json_path__15(rest, user_acc, list, context, line, offset)

json_path__16(rest, acc, stack, context, line, offset)

json_path__17(_, _, list, _, _, _)

json_path__18(rest, acc, stack, context, line, offset)

json_path__19(rest, acc, stack, context, comb__line, comb__offset)

json_path__20(rest, acc, stack, context, line, offset)

json_path__21(rest, user_acc, list, context, line, offset)

json_path__22(rest, acc, stack, context, line, offset)

json_path__23(rest, acc, stack, context, line, offset)

json_path__24(rest, acc, stack, context, comb__line, comb__offset)

json_path__25(rest, acc, stack, context, comb__line, comb__offset)

json_path__26(rest, user_acc, list, context, line, offset)

json_path__27(rest, acc, stack, context, line, offset)

json_path__28(rest, user_acc, list, context, line, offset)

json_path__29(inner_rest, inner_acc, list, inner_context, inner_line, inner_offset)

json_path__30(rest, user_acc, list, context, line, offset)

json_path__31(rest, acc, list, context, line, offset)

json_path__32(_, _, stack, _, _, _)

json_path__33(rest, acc, stack, context, line, offset)

json_path__34(rest, acc, list, context, line, offset)

json_path__35(_, _, stack, _, _, _)

json_path__36(rest, acc, stack, context, line, offset)

json_path__37(arg, acc, stack, context, comb__line, comb__offset)

json_path__38(rest, acc, stack, context, line, offset)

json_path__39(rest, acc, stack, context, comb__line, comb__offset)

json_path__40(rest, acc, stack, context, comb__line, comb__offset)

json_path__41(rest, user_acc, list, context, line, offset)

json_path__42(rest, acc, stack, context, line, offset)

json_path__43(rest, acc, stack, context, line, offset)

json_path__44(rest, user_acc, list, context, line, offset)

json_path__45(rest, acc, list, context, line, offset)

json_path__46(inner_rest, inner_acc, list, inner_context, inner_line, inner_offset)

json_path__47(rest, acc, stack, context, line, offset)

name_expecting()

@spec name_expecting() :: String.t()

The expectation text for a missing field name.

parse_field(input)

@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.

parse_field(input, expecting)

@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}.

parse_name(input)

@spec parse_name(String.t()) :: {:ok, String.t(), String.t()} | :no_match

Parses a bare name (no JSON path), returning it and the rest, or :no_match.

parse_names(key, what)

@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.

parse_tree_path(key)

@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.

quoted_value__0(rest, acc, stack, context, line, offset)

quoted_value__1(rest, acc, stack, context, comb__line, comb__offset)

quoted_value__2(rest, acc, stack, context, line, offset)

quoted_value__3(_, _, list, _, _, _)

quoted_value__4(rest, acc, stack, context, line, offset)

quoted_value__5(inner_rest, inner_acc, list, inner_context, inner_line, inner_offset)

quoted_value__6(rest, acc, stack, context, comb__line, comb__offset)

quoted_value__7(rest, acc, list, context, line, offset)

quoted_value__8(_, _, stack, _, _, _)

quoted_value__9(rest, acc, stack, context, line, offset)

quoted_value__10(rest, acc, stack, context, comb__line, comb__offset)

quoted_value__11(rest, acc, stack, context, comb__line, comb__offset)

quoted_value__12(rest, user_acc, list, context, line, offset)

quoted_value__13(rest, acc, stack, context, line, offset)

quoted_value__14(rest, acc, list, context, line, offset)

quoted_value__15(rest, acc, stack, context, comb__line, comb__offset)

quoted_value__16(rest, user_acc, list, context, line, offset)

quoted_value__17(rest, acc, stack, context, line, offset)

raw_value__0(rest, acc, stack, context, line, offset)

raw_value__1(rest, acc, stack, context, line, offset)

raw_value__2(rest, user_acc, list, context, line, offset)

raw_value__3(rest, acc, list, context, line, offset)

raw_value__4(_, _, stack, _, _, _)

raw_value__5(rest, acc, stack, context, line, offset)

raw_value__6(rest, acc, stack, context, comb__line, comb__offset)

raw_value__7(rest, acc, stack, context, comb__line, comb__offset)

raw_value__8(rest, user_acc, list, context, line, offset)

raw_value__9(rest, acc, stack, context, line, offset)

raw_value__10(rest, acc, list, context, line, offset)

raw_value__11(rest, acc, stack, context, line, offset)

reject_nul(texts)

@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.

syntax_error(what, shown, full_input, rest, expecting, opts \\ [])

@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.

take_cast(rest)

@spec take_cast(String.t()) ::
  {:ok, String.t(), String.t()} | {:fail, String.t(), String.t()}

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.

validate_field(field)

@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.