exvalibur v0.5.0 Exvalibur.Sigils View Source

Implementation of sigils ~v and ~V to allow patterns inside matches in rules.

Import this module to get an access to sigils.

Link to this section Summary

Functions

Handles the sigil ~V for non-interpolated match expressions

Handles the sigil ~v for interpolated match expressions

Link to this section Functions

Link to this macro sigil_V(term, modifiers) View Source (macro)
sigil_V(term :: binary(), modifiers :: list()) :: any()

Handles the sigil ~V for non-interpolated match expressions.

It returns an AST that might be used as is in Exvalibur.validator!/2’s rules.

Examples

iex> import Exvalibur.Sigils
iex> ~V[%{} = _]
{:=, [line: 15], [{:%{}, [line: 15], []}, {:_, [line: 15], nil}]}
iex> ~V[<<"foo", _ :: binary>>]
{:<<>>, [line: 14],
  ["foo", {:::, [line: 14], [{:_, [line: 14], nil}, {:binary, [line: 14], nil}]}]}
iex> ~V[<<invalid]
** (TokenMissingError) nofile:14: missing terminator: >> (for "<<" starting at line 14)
Link to this macro sigil_v(term, modifiers) View Source (macro)
sigil_v(term :: binary(), modifiers :: list()) :: any()

Handles the sigil ~v for interpolated match expressions.

It behaves exactly as sigil_V save for it interpolates the string passed to sigil.