{"id":15837798,"url":"https://github.com/sambacha/solidity-pegjs-parser","last_synced_at":"2025-03-15T17:31:38.001Z","repository":{"id":38246201,"uuid":"302880522","full_name":"sambacha/solidity-pegjs-parser","owner":"sambacha","description":"Solidity Parser for Coverage Testing utilizing new Peggy PEG.js Parser","archived":false,"fork":false,"pushed_at":"2022-06-08T10:10:22.000Z","size":837,"stargazers_count":3,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-08T20:06:25.813Z","etag":null,"topics":["ast","codecov","ethereum","evm","hardhat","parser","solhint","solidity","solium","testing"],"latest_commit_sha":null,"homepage":"","language":"PEG.js","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/sambacha.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}},"created_at":"2020-10-10T10:54:02.000Z","updated_at":"2023-01-22T22:31:34.000Z","dependencies_parsed_at":"2022-08-25T22:41:53.907Z","dependency_job_id":null,"html_url":"https://github.com/sambacha/solidity-pegjs-parser","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sambacha%2Fsolidity-pegjs-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sambacha%2Fsolidity-pegjs-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sambacha%2Fsolidity-pegjs-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sambacha%2Fsolidity-pegjs-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sambacha","download_url":"https://codeload.github.com/sambacha/solidity-pegjs-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243766779,"owners_count":20344811,"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":["ast","codecov","ethereum","evm","hardhat","parser","solhint","solidity","solium","testing"],"created_at":"2024-10-05T15:41:49.559Z","updated_at":"2025-03-15T17:31:37.480Z","avatar_url":"https://github.com/sambacha.png","language":"PEG.js","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Solidity PEGJS Grammar Parser\n\n![nodejs](https://github.com/sambacha/solidity-pegjs-parser/workflows/nodejs/badge.svg)\n\n\u003e [GitHub Source](https://github.com/sambacha/solidity-pegjs-parser)\n\n\u003e [npm solidity-pegjs-parser](https://www.npmjs.com/package/solidity-pegjs-parser)\n\n## Abstract\n\n`$ npm install pegis-solidity`\n\nIdeal for AST use-cases\n\n## Overview\n\npegis-solidity\n\n\u003e original\n\u003e [consensys/solidity-parser](https://github.com/ConsenSys/solidity-parser) with\n\u003e additional project specific grammar rules\n\n- Main change is adoption of `peggy` as the `peg.js` framework has been\n  stagnant, this is a drop in replacement.\n\n## Latest Changelog\n\n- Added support for `gwei` units.\n    ```solidity\n    uint256 gas = 10 gwei;\n    ```\n- Fixed a bug that didn't recognize empty TryCatch statements with a return expresion.\n    ```solidity\n    try Foo.bar() returns (uint result) {} catch {}\n    ```\n- Fixed a bug that didn't recognize Enum declarations\n    ```solidity\n    enum Foo {\n        bar\n    }\n    ```\n\nThanks to [https://github.com/wrong7](https://github.com/wrong7)\n\n\n## Reference for Changes\n\n\u003e v2 changes start here: 18 August 2021\n\n- feat(refactor): migrate to peggy and various improvements\n  [`87b594a`](https://github.com/sambacha/solidity-pegjs-parser/commit/87b594ad21e1221b5e3574ac8f69b5751a9ce4be)\n- build(refactor): improve build process\n  [`0de7a77`](https://github.com/sambacha/solidity-pegjs-parser/commit/0de7a774bf2edd51b03a865e435b30a02feb5313)\n- chore(repo): remove dead and legacy artifacts\n  [`012fec1`](https://github.com/sambacha/solidity-pegjs-parser/commit/012fec1b5000017a6125c38580d76a3299f597cc)\n\n\n### Usage\n\n```js\nimport { solidityparser } from 'pegis-solidity';\n```\n\n### command line\n\n`$ ./node_modules/.boin/pegis-solidity $PWD/file_name.js`\n\n#### Example\n\nConsider this solidity code as input:\n\n```solidity\nimport \"Foo.sol\";\n\ncontract MyContract {\n  mapping (uint =\u003e address) public addresses;\n}\n```\n\nGenerated output as AST output:\n\n```json\n{\n  \"type\": \"Program\",\n  \"body\": [\n    {\n      \"type\": \"ImportStatement\",\n      \"value\": \"Foo.sol\"\n    },\n    {\n      \"type\": \"ContractStatement\",\n      \"name\": \"MyContract\",\n      \"is\": [],\n      \"body\": [\n        {\n          \"type\": \"ExpressionStatement\",\n          \"expression\": {\n            \"type\": \"DeclarativeExpression\",\n            \"name\": \"addresses\",\n            \"literal\": {\n              \"type\": \"Type\",\n              \"literal\": {\n                \"type\": \"MappingExpression\",\n                \"from\": {\n                  \"type\": \"Type\",\n                  \"literal\": \"uint\",\n                  \"members\": [],\n                  \"array_parts\": []\n                },\n                \"to\": {\n                  \"type\": \"Type\",\n                  \"literal\": \"address\",\n                  \"members\": [],\n                  \"array_parts\": []\n                }\n              },\n              \"members\": [],\n              \"array_parts\": []\n            },\n            \"is_constant\": false,\n            \"is_public\": true\n          }\n        }\n      ]\n    }\n  ]\n}\n```\n\n```js\nvar SolidityParser = require('pegis-solidity');\n\n// Parse Solidity code as a string:\nvar result = SolidityParser.parse('contract { ... }');\n\n// Or, parse a file:\nvar result = SolidityParser.parseFile('./path/to/file.sol');\n```\n\n## Updates to Grammar\n\n\u003e A full list can be found under the `DIFF.md` document [here](/docs/DIFF.md)\n\n```diff\n HexStringLiteral\n-  = HexToken StringLiteral\n+  = HexToken val:StringLiteral {\n+    return {\n+      type: \"HexLiteral\",\n+      value: val,\n+      start: location().start.offset,\n+      end: location().end.offset\n+    };\n+  }\n```\n\n### License\n\nISC / MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsambacha%2Fsolidity-pegjs-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsambacha%2Fsolidity-pegjs-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsambacha%2Fsolidity-pegjs-parser/lists"}