{"id":13726225,"url":"https://github.com/rescript-lang/syntax","last_synced_at":"2025-05-07T21:31:49.504Z","repository":{"id":37026787,"uuid":"276430238","full_name":"rescript-lang/syntax","owner":"rescript-lang","description":"ReScript's syntax as a standalone repo.","archived":true,"fork":false,"pushed_at":"2023-05-28T05:52:28.000Z","size":10038,"stargazers_count":256,"open_issues_count":0,"forks_count":38,"subscribers_count":21,"default_branch":"master","last_synced_at":"2024-08-04T01:28:40.502Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"OCaml","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/rescript-lang.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-07-01T16:36:04.000Z","updated_at":"2024-06-04T21:28:34.000Z","dependencies_parsed_at":"2024-01-10T18:34:58.515Z","dependency_job_id":null,"html_url":"https://github.com/rescript-lang/syntax","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rescript-lang%2Fsyntax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rescript-lang%2Fsyntax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rescript-lang%2Fsyntax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rescript-lang%2Fsyntax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rescript-lang","download_url":"https://codeload.github.com/rescript-lang/syntax/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224654175,"owners_count":17347683,"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-08-03T01:02:56.294Z","updated_at":"2024-11-14T16:33:30.136Z","avatar_url":"https://github.com/rescript-lang.png","language":"OCaml","funding_links":[],"categories":["OCaml"],"sub_categories":[],"readme":"# ⛔️ DEPRECATED ReScript Syntax\n\n**The ReScript syntax sources are now a part of the compiler repo (see https://github.com/rescript-lang/rescript-compiler/tree/master/res_syntax).**\n\n**Please create any new issues or PRs directly in the compiler repo.**\n\n## Contribute\n\n### Why\n\nA detailed discussion by Jonathan Blow and Casey Muratori on why you would hand-roll a parser for a production quality programming language\n[Discussion: Making Programming Language Parsers, etc](https://youtu.be/MnctEW1oL-E)\n\n\"One reason why I switched off these parser tools is that the promises didn't really materialize.\nThe amount of work that I had to do change a yacc script from one language to a variant of that language\nwas more than if I hand wrote the code myself.\n\"\nJ. Blow.\n\n### Setup \u0026 Usage (For Repo Devs Only)\n\nRequired:\n\n- OCaml 4.10 or later\n- Dune\n- Reanalyze\n- OS: macOS, Linux or Windows\n\n```sh\ngit clone https://github.com/rescript-lang/syntax.git\ncd syntax\nopam install . --deps-only --with-test\nmake # or \"dune build\"\n```\n\nThis will produce the three binaries `rescript`, `tests` and `bench` (with `.exe` extension on Windows).\n\nWe only build production binaries, even in dev mode. No need for a separate dev binary when the build is fast enough. Plus, this encourages proper benchmarking of the (production) binary each diff.\n\nAfter you make a change:\n\n```sh\nmake\n```\n\nRun the core tests:\n\n```sh\nmake test\n```\n\nRun the extended tests (not fully working on Windows yet):\n\n```sh\nmake roundtrip-test\n```\n\nThose will tell you whether you've got a test output difference. If it's intentional, check them in.\n\nDebug a file:\n\n```sh\n# write code in test.res\ndune exec -- rescript test.res # test printer\ndune exec -- rescript -print ast test.res # print ast\ndune exec -- rescript -print comments test.res # print comment table\ndune exec -- rescript -print ml test.res # show ocaml code\ndune exec -- rescript -print res -width 80 test.res # test printer and change default print width\n```\n\nBenchmark:\n\n```sh\nmake bench\n```\n\nEnable stack trace:\n\n```sh\n# Before you run the binary\nexport OCAMLRUNPARAM=\"b\"\n```\n\nThis is likely a known knowledge: add the above line into your shell rc file so that every shell startup you have OCaml stack trace enabled.\n\n### Development Docs\n\n#### Folder Structure\n\n- `src` contains all the parser/printer source code. Don't change folder structure without notice; The [rescript-compiler](https://github.com/rescript-lang/rescript-compiler) repo uses this repo as a submodule and assumes `src`.\n- `benchmarks`, `cli` and `tests` contain the source code for the executables used for testing/benchmarking. These are not used by the [rescript-compiler](https://github.com/rescript-lang/rescript-compiler) repo.\n\n#### Error Reporting Logic\n\nRight now, ReScript's compiler's error reporting mechanism, for architectural reasons, is independent from this syntax repo's error reporting mechanism. However, we do want a unified look when they report the errors in the terminal. This is currently achieved by (carefully...) duplicating the error report logic from the compiler repo to here (or vice-versa; either way, just keep them in sync). The files to sync are the compiler repo's [super_location.ml](https://github.com/rescript-lang/rescript-compiler/blob/fcb21790dfb0592f609818df7790192061360631/jscomp/super_errors/super_location.ml) and [super_code_frame.ml](https://github.com/rescript-lang/rescript-compiler/blob/fcb21790dfb0592f609818df7790192061360631/jscomp/super_errors/super_code_frame.ml), into this repo's [res_diagnostics_printing_utils.ml](https://github.com/rescript-lang/syntax/blob/ec5cefb23b659b0a7be170ae0ad26f3fe8a05456/src/res_diagnostics_printing_utils.ml). A few notes:\n\n- Some lines are lightly changed to fit this repo's needs; they're documented in the latter file.\n- Please keep these files lightweight and as dependency-less as possible, for easier syncing.\n- The syntax logic currently doesn't have warnings, only errors, and potentially more than one.\n- In the future, ideally, the error reporting logic would also be unified with GenType and Reanalyze's. It'd be painful to copy paste around all this reporting logic.\n- The errors are reported by the parser [here](https://github.com/rescript-lang/syntax/blob/ec5cefb23b659b0a7be170ae0ad26f3fe8a05456/src/res_diagnostics.ml#L146).\n- Our editor plugin parses the error report from the compiler and from the syntax [here](https://github.com/rescript-lang/rescript-vscode/blob/0dbf2eb9cdb0bd6d95be1aee88b73830feecb5cc/server/src/utils.ts#L129-L329).\n\n### Example API usage\n\n```ocaml\nlet filename = \"foo.res\"\nlet src = FS.readFile filename\n\nlet p =\n  (* intended for ocaml compiler *)\n  let mode = Res_parser.ParseForTypeChecker in\n  (* if you want to target the printer use: let mode = Res_parser.Default in*)\n  Res_parser.make ~mode src filename\n\nlet structure = Res_core.parseImplementation p\nlet signature = Res_core.parseSpecification p\n\nlet () = match p.diagnostics with\n| [] -\u003e () (* no problems *)\n| diagnostics -\u003e (* parser contains problems *)\n  Res_diagnostics.printReport diagnostics src\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frescript-lang%2Fsyntax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frescript-lang%2Fsyntax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frescript-lang%2Fsyntax/lists"}