{"id":20237733,"url":"https://github.com/ragmaanir/syntaks","last_synced_at":"2026-04-17T18:02:12.743Z","repository":{"id":136218392,"uuid":"44671519","full_name":"Ragmaanir/syntaks","owner":"Ragmaanir","description":"Parser combinators for crystal","archived":false,"fork":false,"pushed_at":"2021-05-04T22:39:47.000Z","size":181,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-30T21:39:25.319Z","etag":null,"topics":["crystal","ebnf","parser-combinators","peg"],"latest_commit_sha":null,"homepage":"","language":"C","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/Ragmaanir.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-21T11:24:28.000Z","updated_at":"2025-08-27T12:08:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"7395211f-756d-4a48-b805-0f6bf48f3a9e","html_url":"https://github.com/Ragmaanir/syntaks","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/Ragmaanir/syntaks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ragmaanir%2Fsyntaks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ragmaanir%2Fsyntaks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ragmaanir%2Fsyntaks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ragmaanir%2Fsyntaks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ragmaanir","download_url":"https://codeload.github.com/Ragmaanir/syntaks/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ragmaanir%2Fsyntaks/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31939788,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T17:29:20.459Z","status":"ssl_error","status_checked_at":"2026-04-17T17:28:47.801Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["crystal","ebnf","parser-combinators","peg"],"created_at":"2024-11-14T08:28:38.566Z","updated_at":"2026-04-17T18:02:12.710Z","avatar_url":"https://github.com/Ragmaanir.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# syntaks [![Crystal CI](https://github.com/Ragmaanir/syntaks/actions/workflows/crystal.yml/badge.svg)](https://github.com/Ragmaanir/syntaks/actions/workflows/crystal.yml)\n\n### Version 0.3.2\n\nA parser combinator framework.\n\n## Usage\n\n```crystal\nrequire \"syntaks\"\n```\n\n## Example\n\n```crystal\nclass ListParser \u003c Syntaks::Parser\n  rule(:root, Array(String), _os \u003e\u003e \"(\" \u003e\u003e _os \u0026 item_list \u0026 \")\") { |v| v[3] }\n  rule(:item_list, Array(String), item \u003e\u003e ~item_list_tail) do |v|\n    if tail = v[1]\n      [v[0]] + tail\n    else\n      [v[0]]\n    end\n  end\n\n  rule(:item_list_tail, Array(String), {\",\" \u0026 _os \u0026 item \u003e\u003e _os}) do |list|\n    list.map(\u0026.[2])\n  end\n\n  rule(:item, String, id \u003e\u003e _os) do |t|\n    t[0]\n  end\n\n  rule(:id, String, /[_a-z][_a-z0-9]*/, \u0026.content)\n\n  ignored(:_os, /\\s*/)\nend\n\n\nres = ListParser.new.call(\"(v1,v2)\").as(Success)\n\nassert res.value == [\"v1\", \"v2\"]\n\n```\n\n## Usage\n\nRules are specified in a format similar to EBNF:\n\n```crystal\n# literals/tokens\nignored(:space, /\\s+/) # generates nil as AST-node\nrule(:int, String, /[1-9][0-9]*/) { |m| m.content } # generates String as AST-node\n\n# sequence\nrule(:root, String, \"var \" \u003e\u003e id) { |m| m[1] } # use the second match (id) as AST-node\n\n# sequence with backtracking disabled\nrule(:root, String, \"var \" \u0026 id) { |m| m[1] }\n\n# alternatives\nrule(:root, String, a | b)\n\n# repetition\nrule(:root, Array(Int32), {\",\" \u003e\u003e int}) { |m| m.map(\u0026.[1]) }\n```\n\nWhen backtracking is disabled an parsing fails, a syntax error is produced:\n\n```crystal\nclass ErrorParser \u003c Syntaks::Parser\n  rule(:root, String, \"var\" \u003e\u003e space \u0026 /[a-z]+/) { |m| m[2].content }\n  ignored(:space, /\\s+/)\nend\n\n\nres = ErrorParser.new.call(\"var     1337\").as(Error)\n\nassert res.message == \u003c\u003c-MSG\nSyntax error at 1:9:\n\n1\u003evar     1337\n----------^\nRule: \"var\" \u003e\u003e space \u0026 /[a-z]+/\n\nMSG\n\n```\n\nA parse log can be printed to inspect the parsing process:\n\n```crystal\nsource = \u003c\u003c-SRC\n  def main\n    if true\n      x = 1\n      ⬤\n    end\n  end\nSRC\n\nctx = LoggingContext.new(ParseLog.new(Source.new(source)))\nres = ExampleParsers::MethodParser.new.call(source, ctx).as(Error)\n\nlog = ctx.parse_log.to_s\n\n# The syntax error entry marked with ⚡ should be on the line that contains ⬤\nassert(/⚡[^\\n]+(29-33)[^\\n]+⬤/ === log)\n\n```\n\n## TODO\n\n- simple token macro\n- rules that do not generate ast nodes\n- error-recovery productions / synchronization tokens\n- optional whitespace skippers\n- Simple lexer?\n- Packrat parsing / memoization\n- remember longest parsed prefix when parsing fails\n\n## DONE\n\n- Use ameba\n- Generated `README.md` with examples\n- LoggingContext with a ParseLog\n- ProfilingContext\n- EBNF DSL\n- Selectively disable backtracking\n- Detailed syntax errors: display production that failed and the location where exactly it failed\n\n\n## Contributing\n\n1. Fork it ( https://github.com/ragmaanir/syntaks/fork )\n2. Create your feature branch (git checkout -b my-new-feature)\n3. Commit your changes (git commit -am 'Add some feature')\n4. Push to the branch (git push origin my-new-feature)\n5. Create a new Pull Request\n\n## Contributors\n\n- [Ragmaanir](https://github.com/ragmaanir) - creator, maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fragmaanir%2Fsyntaks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fragmaanir%2Fsyntaks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fragmaanir%2Fsyntaks/lists"}