Snex.Sigils (Snex v0.4.1)

Copy Markdown View Source

Sigils for creating Snex.Code structs.

~p, ~P and ~PY sigils create Snex.Code structs with location metadata. This is used for accurate stacktraces on Python side.

iex> Snex.pyeval(env, ~p"raise RuntimeError('test')")

{:error,
%Snex.Error{
code: :python_runtime_error,
reason: "test",
traceback: [...,
  "  File \"/Users/me/snex/sigils.ex\", line 8, in <module>\n    raise RuntimeError(\"test\")\n",
  "RuntimeError: test\n"]
}}

Summary

Functions

Handles the sigil ~P for location-annotated Python code.

Handles the sigil ~PY for location-annotated Python code.

Handles the sigil ~p for location-annotated Python code.

Functions

sigil_P(src, opts)

(macro)

Handles the sigil ~P for location-annotated Python code.

Returns a %Snex.Code{} struct built from the given code, without interpolations and without unescaping characters.

sigil_PY(src, opts)

(macro)

Handles the sigil ~PY for location-annotated Python code.

This is a more readable alias for sigil ~P.

sigil_p(src, opts)

(macro)

Handles the sigil ~p for location-annotated Python code.

Returns a %Snex.Code{} struct built from the given code, unescaping characters and replacing interpolations.

Note: using interpolation with multi-line strings will break the mapping between what Python thinks is the line number, and the actual line number in the Elixir source file.