{"id":29141200,"url":"https://github.com/ponylang/peg","last_synced_at":"2026-03-12T03:02:58.109Z","repository":{"id":43583729,"uuid":"87013021","full_name":"ponylang/peg","owner":"ponylang","description":"A parsing expression grammar package for Pony","archived":false,"fork":false,"pushed_at":"2026-03-11T20:47:46.000Z","size":191,"stargazers_count":18,"open_issues_count":2,"forks_count":6,"subscribers_count":11,"default_branch":"main","last_synced_at":"2026-03-11T22:36:14.748Z","etag":null,"topics":["parser-combinators","peg","pony-core-team-library","pony-language"],"latest_commit_sha":null,"homepage":"","language":"Pony","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ponylang.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"open_collective":"ponyc"}},"created_at":"2017-04-02T20:11:58.000Z","updated_at":"2026-03-11T20:47:50.000Z","dependencies_parsed_at":"2024-01-06T21:05:35.014Z","dependency_job_id":"75f9b96f-541f-4165-bcab-5598f48a27ed","html_url":"https://github.com/ponylang/peg","commit_stats":{"total_commits":154,"total_committers":7,"mean_commits":22.0,"dds":"0.49350649350649356","last_synced_commit":"358856e5111a87436a2a17364ffb31be33da35d6"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/ponylang/peg","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ponylang%2Fpeg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ponylang%2Fpeg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ponylang%2Fpeg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ponylang%2Fpeg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ponylang","download_url":"https://codeload.github.com/ponylang/peg/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ponylang%2Fpeg/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30413618,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-12T00:40:14.898Z","status":"online","status_checked_at":"2026-03-12T02:00:07.260Z","response_time":114,"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":["parser-combinators","peg","pony-core-team-library","pony-language"],"created_at":"2025-06-30T18:05:41.725Z","updated_at":"2026-03-12T03:02:58.102Z","avatar_url":"https://github.com/ponylang.png","language":"Pony","funding_links":["https://opencollective.com/ponyc"],"categories":[],"sub_categories":[],"readme":"# PEG\n\nParser Expression Grammar compiler and combinators\n\n## Installation\n\n- Install [corral](https://github.com/ponylang/corral)\n- `corral add github.com/ponylang/peg.git --version 0.1.7`\n- `corral fetch` to fetch your dependencies\n- `use \"peg\"` to include this package\n- `corral run -- ponyc` to compile your application\n\n## API Documentation\n\n[https://ponylang.github.io/peg/](https://ponylang.github.io/peg/)\n\n## Resources for PEGs\n\n- [Wikipedia](https://en.wikipedia.org/wiki/Parsing_expression_grammar)\n- [PEG Paper and Slides by Bryan Ford](https://bford.info/pub/lang/peg/)\n\n## JSON Example\n\n### Parser Compiler\n\nA parser for JSON may be compiled from a PEG file such as the following:\n\n```peg\n// examples/json.peg\n\nDIGIT19 \u003c- '1'..'9'\nDIGIT \u003c- '0'..'9'\nDIGITS \u003c- DIGIT+\nINT \u003c- '-' DIGIT19 DIGITS / '-' DIGIT / DIGIT19 DIGITS / DIGIT\nFRAC \u003c- '.' DIGITS\nEXP \u003c- ('e' / 'E') ('-' / '+')? DIGITS\nNUMBER \u003c- INT FRAC? EXP?\n\nHEX \u003c- DIGIT / 'a'..'f' / 'A'..'F'\nCHAR \u003c-\n  \"\\\\\\\"\" / \"\\\\\\\\\" / \"\\\\/\" / \"\\\\b\" / \"\\\\f\" / \"\\\\n\" / \"\\\\r\" / \"\\\\t\" /\n  \"\\\\u\" HEX HEX HEX HEX / !\"\\\"\" !\"\\\\\" .\nSTRING \u003c- \"\\\"\" CHAR* \"\\\"\"\nBOOL \u003c- \"true\" / \"false\"\n\nvalue \u003c- \"null\" / BOOL / NUMBER / STRING / object / array\npair \u003c- STRING -':' value\n\nobject \u003c- -'{' (pair % ',') -'}'\narray \u003c- -'[' (value % ',') -']'\n\nwhitespace \u003c- (' ' / '\\t' / '\\r' / '\\n')+\nlinecomment \u003c- \"//\" (!'\\r' !'\\n' .)*\nnestedcomment \u003c- \"/*\" ((!\"/*\" !\"*/\" .) / nestedcomment)* \"*/\"\n\nstart \u003c- value\nhidden \u003c- (whitespace / linecomment / nestedcomment)+\n```\n\n### Combinators\n\nA parser for JSON may also be constructed from combinators at compile time:\n\n```pony\n// peg/json.pony\n\nprimitive JsonParser\n  fun apply(): Parser val =\u003e\n    recover\n      let obj = Forward\n      let array = Forward\n\n      let digit19 = R('1', '9')\n      let digit = R('0', '9')\n      let digits = digit.many1()\n      let int =\n        (L(\"-\") * digit19 * digits) / (L(\"-\") * digit) /\n        (digit19 * digits) / digit\n      let frac = L(\".\") * digits\n      let exp = (L(\"e\") / L(\"E\")) * (L(\"+\") / L(\"-\")).opt() * digits\n      let number = (int * frac.opt() * exp.opt()).term(TNumber)\n\n      let hex = digit / R('a', 'f') / R('A', 'F')\n      let char =\n        L(\"\\\\\\\"\") / L(\"\\\\\\\\\") / L(\"\\\\/\") / L(\"\\\\b\") / L(\"\\\\f\") / L(\"\\\\n\") /\n        L(\"\\\\r\") / L(\"\\\\t\") / (L(\"\\\\u\") * hex * hex * hex * hex) /\n        (not L(\"\\\"\") * not L(\"\\\\\") * R(' '))\n\n      let string = (L(\"\\\"\") * char.many() * L(\"\\\"\")).term(TString)\n      let value =\n        L(\"null\").term(TNull) / L(\"true\").term(TBool) / L(\"false\").term(TBool) /\n        number / string / obj / array\n      let pair = (string * -L(\":\") * value).node(TPair)\n      obj() = -L(\"{\") * pair.many(L(\",\")).node(TObject) * -L(\"}\")\n      array() = -L(\"[\") * value.many(L(\",\")).node(TArray) * -L(\"]\")\n\n      let whitespace = (L(\" \") / L(\"\\t\") / L(\"\\r\") / L(\"\\n\")).many1()\n      let linecomment =\n        (L(\"#\") / L(\"//\")) * (not L(\"\\r\") * not L(\"\\n\") * Unicode).many()\n      let nestedcomment = Forward\n      nestedcomment() =\n        L(\"/*\") *\n        ((not L(\"/*\") * not L(\"*/\") * Unicode) / nestedcomment).many() *\n        L(\"*/\")\n      let hidden = (whitespace / linecomment / nestedcomment).many()\n\n      value.hide(hidden)\n    end\n\nprimitive TObject is Label fun text(): String =\u003e \"Object\"\nprimitive TPair is Label fun text(): String =\u003e \"Pair\"\nprimitive TArray is Label fun text(): String =\u003e \"Array\"\nprimitive TString is Label fun text(): String =\u003e \"String\"\nprimitive TNumber is Label fun text(): String =\u003e \"Number\"\nprimitive TBool is Label fun text(): String =\u003e \"Bool\"\nprimitive TNull is Label fun text(): String =\u003e \"Null\"\n```\n\n## Executable Parser Compiler\n\nAn executable example of the parser compiler is found in examples/compiler.\nYou can compile the executable by running `make examples`.\n\n```console\nUsage:\n  ./build/release/compiler \u003csource-file\u003e\n      Run a PEG/JSON parser over some source file and print the AST.\n  ./build/release/compiler \u003cpeg-file\u003e \u003csource-file\u003e\n      Compile a parser from the first file, then run it over the second file and\n      print the AST.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fponylang%2Fpeg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fponylang%2Fpeg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fponylang%2Fpeg/lists"}