{"id":27226482,"url":"https://github.com/williamthome/custom_sigils","last_synced_at":"2025-11-09T23:03:44.891Z","repository":{"id":284539520,"uuid":"955253016","full_name":"williamthome/custom_sigils","owner":"williamthome","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-26T11:54:09.000Z","size":3,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-06T21:29:53.001Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/erlang/otp/pull/9647","language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/williamthome.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-26T10:57:01.000Z","updated_at":"2025-03-27T14:48:27.000Z","dependencies_parsed_at":"2025-03-26T12:41:23.005Z","dependency_job_id":null,"html_url":"https://github.com/williamthome/custom_sigils","commit_stats":null,"previous_names":["williamthome/custom_sigils"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/williamthome/custom_sigils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamthome%2Fcustom_sigils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamthome%2Fcustom_sigils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamthome%2Fcustom_sigils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamthome%2Fcustom_sigils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/williamthome","download_url":"https://codeload.github.com/williamthome/custom_sigils/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamthome%2Fcustom_sigils/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281748716,"owners_count":26554822,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-30T02:00:06.501Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-10T11:58:36.057Z","updated_at":"2025-10-30T05:10:34.779Z","avatar_url":"https://github.com/williamthome.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"# custom_sigils\n\nThis is a POC of custom sigils implementation for Erlang/OTP.\n\nIt is based on [this comment](https://erlangforums.com/t/proposal-introduce-f-sigils-for-string-interpolation/4551/21?u=williamthome)\non the Erlang Forums.\n\nThis is a minimal change and does not break any existing code.\n\n## How it works\n\nThe developer can use the built-in sigils, like `s`, `S`, `b`, and `B`, but it\ncan also use any sigil it wants. However, it is obligated to handle the custom\nsigil with parse transform, otherwise, an `invalid sigil` exception will be raised\nat the compile time.\n\n### Why parse transform?\n\nIt was the first idea and seems to be the simplest one to implement this feature.\n\n## Examples\n\nThere are two functions of custom sigils implemented in this project:\n\n- `json`: Decodes a JSON into an Erlang term via `json:decode/1`\n- `sql`: Transforms a SQL query into a tuple based on the `f_sigil` proposal.\n  This sigil extracts the params and replaces them with `$N`, where N is the\n  param index of that param.\n\n### The code of the `example` module\n\n```erlang\n-module(example).\n-compile({parse_transform, json_sigil}).\n-compile({parse_transform, sql_sigil}).\n%% Sigils can be defined globally in rebar3.config (applies to all .erl files), e.g.:\n%{erl_opts, [\n%    {parse_transform, json_sigil},\n%    {parse_transform, sql_sigil}\n%]}.\n-export([json/0]).\n-export([sql/2]).\n\njson() -\u003e\n    ~json\"\"\"\n    {\"key\": \"value\"}\n    \"\"\".\n\nsql(Name, MinAge) when is_binary(Name); is_integer(MinAge) -\u003e\n    ~sql\"\"\"\n    SELECT *\n      FROM users\n     WHERE name = {Name}\n       AND age \u003e= {MinAge}\n    \"\"\".\n\n%% Uncomment this function to raise an invalid sigil exception.\n%invalid() -\u003e\n%    ~invalid\"\".\n```\n\n### The `json_sigil` code\n\n```erlang\n-module(json_sigil).\n-export([parse_transform/2]).\n\nparse_transform(Forms0, _Options) -\u003e\n    Forms = [erl_syntax_lib:map(fun(Node) -\u003e\n                 transform_node(erl_syntax:revert(Node))\n             end, F) || F \u003c- Forms0],\n    erl_syntax:revert_forms(Forms).\n\ntransform_node({sigil, _Anno, json, String, _Suffix}) -\u003e\n    Bin = erl_syntax:binary([erl_syntax:binary_field(\n                             String,\n                             [erl_syntax:atom(utf8)])]),\n    erl_syntax:application(erl_syntax:atom(json),\n                           erl_syntax:atom(decode),\n                           [Bin]);\ntransform_node(Node) -\u003e\n    Node.\n```\n\n### The `sql_sigil` code\n\nPlease refer to the project module for the complete code.\n\n### Running the examples\n\n```erlang\n1\u003e c(json_sigil), c(sql_sigil), c(example).\n{ok,example}\n2\u003e example:json().\n#{\u003c\u003c\"key\"\u003e\u003e =\u003e \u003c\u003c\"value\"\u003e\u003e}\n3\u003e example:sql(~\"Bob\", 18).\n{sql,\u003c\u003c\"SELECT *\\n  FROM users\\n WHERE name = $1\\n   AND age \u003e= $2\"\u003e\u003e,\n     [\u003c\u003c\"Bob\"\u003e\u003e,18]}\n4\u003e ~invalid\"\".\n* 1:1: invalid sigil\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilliamthome%2Fcustom_sigils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwilliamthome%2Fcustom_sigils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilliamthome%2Fcustom_sigils/lists"}