{"id":17921861,"url":"https://github.com/zth/rescript-embed-lang","last_synced_at":"2025-04-03T10:45:30.153Z","repository":{"id":196705334,"uuid":"696959718","full_name":"zth/rescript-embed-lang","owner":"zth","description":"A general purpose PPX and library for embedding other languages into ReScript, via code generation.","archived":false,"fork":false,"pushed_at":"2024-06-21T16:56:27.000Z","size":77,"stargazers_count":19,"open_issues_count":4,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-09T00:25:30.714Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"ReScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zth.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-LICENSE","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":"2023-09-26T19:05:19.000Z","updated_at":"2024-10-23T06:19:08.000Z","dependencies_parsed_at":"2023-09-27T02:20:47.280Z","dependency_job_id":"a78dc406-71b2-48af-8cec-ead16209b9a8","html_url":"https://github.com/zth/rescript-embed-lang","commit_stats":null,"previous_names":["zth/rescript-embed-lang"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Frescript-embed-lang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Frescript-embed-lang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Frescript-embed-lang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Frescript-embed-lang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zth","download_url":"https://codeload.github.com/zth/rescript-embed-lang/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246989498,"owners_count":20865306,"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","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":"2024-10-28T20:36:30.273Z","updated_at":"2025-04-03T10:45:30.128Z","avatar_url":"https://github.com/zth.png","language":"ReScript","readme":"# rescript-embed-lang\n\nA general purpose PPX and library for embedding other languages into ReScript, via code generation.\n\nThe PPX itself is very very simple - just swap out the embedded language string with a reference to the code generated for that embed. The code generation **happens elsewhere**. This way embedding languages is flexible and light weight.\n\n\u003e This package will eventually ship with a set of utils for making the code generation part easy to set up as well.\n\n## Installation\n\n```bash\nnpm i rescript-embed-lang\n```\n\nAnd then add the PPX to your `bsconfig.json`:\n\n```json\n\"ppx-flags\": [\"rescript-embed-lang/ppx\"]\n```\n\nThere, all set!\n\n### Why one general PPX\n\nPPXes can be complex and difficult to maintain, and costs at bit of performance. Therefore, this PPX is intended to be extended to support as many use cases around embedding other languages into ReScript as possible. This way, all language embeds built can use one central PPX rather than implementing their own. Maintenance becomes drastically easier, and performance is only hit once if you use several language embeds.\n\n## Supported extensions\n\n### EdgeQL\n\nYou can embed [EdgeQL](https://www.edgedb.com/) directly as an assignment to a `let` binding:\n\n```rescript\n// Movies.res\nlet findMovieQuery = %edgeql(`\n  # @name findMovieQuery\n  select Movie {\n    id\n    title\n  } filter .id = \u003cuuid\u003e$movieId\n`)\n```\n\nIs transformed into:\n\n```rescript\n// Movies.res\nlet findMovieQuery = Movies__edgedb.FindMovieQuery.query\n```\n\nYou can also embed it via a module, in case you want easy access to all of the things emitted in the generated code:\n\n```rescript\n// Movies.res\nmodule FindMovieQuery = %edgeql(`\n  # @name findMovieQuery\n  select Movie {\n    id\n    title\n  } filter .id = \u003cuuid\u003e$movieId\n`)\n```\n\nIs transformed into:\n\n```rescript\n// Movies.res\nmodule FindMovieQuery = Movies__edgedb.FindMovieQuery\n```\n\n### Generic transform\n\n`rescript-embed-lang` ships with a _generic transform_, intended to make experimenting with writing new language embeds + generating code for them much easier in user land, without needing you to add a full transform to this PPX. It expects a specific structure (more below) in order to connect your generated code with your ReScript source.\n\nYou turn it on by passing `-enable-generic-transform` in your PPX flags config:\n\n```json\n\"ppx-flags\": [[\"rescript-embed-lang/ppx\", \"-enable-generic-transform\"]]\n```\n\nIt works like this:\n\n```rescript\n// SomeFile.res\nlet myThing = %generated.css(`\n  .button {\n    color: blue;\n  }\n`)\n```\n\nThis will be transformed into:\n\n```rescript\n// SomeFile.res\nlet myThing = SomeFile__css.M1.default\n```\n\nIt also works with module references:\n\n```rescript\n// SomeFile.res\nmodule MyThing = %generated.css(`\n  .button {\n    color: blue;\n  }\n`)\n```\n\nIs transformed into:\n\n```rescript\n// SomeFile.res\nmodule MyThing = SomeFile__css.M1\n```\n\n\u003e Notice that you can put anything to the right of `%generated`. The example shows `css`, but you could use anything else as well. Example: `%generated.openapi(\"...\")`.\n\nThe formula for what code to refer to when transforming is be: `\u003cfilename\u003e__\u003cgenerated-extension\u003e.M\u003cmodule-count-for-extension\u003e.default`. When using module bindings, the last part `.default` is omitted.\n\n1. We're in `SomeFile.res` and using `generated.css`, so the generated module is expected to be called `SomeFile__css`.\n2. Each submodule in your generated file will be called `M` + what number of transform for that extension it is, in the local file. So, the first `%generated.css` module is `M1`, the second in that same file is `M2`, and so on.\n3. Finally, we add a generic `default` a target value name, just to have something to refer to.\n\n\u003e Remember, the actual codegen creating the module we're referring to here from the source `css` text isn't part of this package. This package is just about making it simple to tie together generated things with its source in ReScript.\n\n### SQL\n\nEmbedding for Postgres SQL via [pgtyped-rescript](https://github.com/zth/pgtyped-rescript).\n\n```rescript\n// Movies.res\nlet findMovieQuery = %sql.one(`\n  /* @name findMovieQuery */\n  select id, title from movies where id = :id\n`)\n```\n\nIs transformed into:\n\n```rescript\n// Movies.res\nlet findMovieQuery = Movies__sql.FindMovieQuery.one\n```\n\n## Adding more language embeds\n\nAdding more embeds should be straight forward. Reach out if you're interested!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzth%2Frescript-embed-lang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzth%2Frescript-embed-lang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzth%2Frescript-embed-lang/lists"}