{"id":15435263,"url":"https://github.com/neuodev/calc-rs","last_synced_at":"2025-07-17T14:08:13.280Z","repository":{"id":139101066,"uuid":"527119846","full_name":"neuodev/calc-rs","owner":"neuodev","description":"Calculator to perform basic and nested arithmetic operations on raw expressions.","archived":false,"fork":false,"pushed_at":"2023-10-02T06:18:45.000Z","size":3474,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-05T03:40:51.330Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/neuodev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-08-21T06:01:18.000Z","updated_at":"2023-05-05T20:16:20.000Z","dependencies_parsed_at":"2024-10-21T20:04:12.555Z","dependency_job_id":null,"html_url":"https://github.com/neuodev/calc-rs","commit_stats":{"total_commits":17,"total_committers":4,"mean_commits":4.25,"dds":0.4117647058823529,"last_synced_commit":"04d5a147c3db75660e02269a1c464b1660ad5a6b"},"previous_names":["neuodev/calc-rs"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/neuodev/calc-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuodev%2Fcalc-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuodev%2Fcalc-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuodev%2Fcalc-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuodev%2Fcalc-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neuodev","download_url":"https://codeload.github.com/neuodev/calc-rs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuodev%2Fcalc-rs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265614332,"owners_count":23798427,"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-01T18:43:16.772Z","updated_at":"2025-07-17T14:08:12.868Z","avatar_url":"https://github.com/neuodev.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `calc-rs`\n\nCalculator to perform basic arithmetic operations on raw expressions.\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"./icon.gif\" alt=\"Numbers Adventure\" title=\"Numbers Adventure\"/\u003e\n\u003cp\u003e\n\n## Preview\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"./preview.gif\" alt=\"preview\" title=\"preview\"/\u003e\n\u003cp\u003e\n\n## Examples\n\n```bash\n? Expression: (2 * 2) + (4 * 3)\n#\u003e 16\n? Expression: (12 / 2) * [30 * 3]\n#\u003e 540\n? Expression: 1.0 * 0.1\n#\u003e 0.1\n? Expression: 0.1 * (100 * 14)\n#\u003e 140\n? Expression: 0.1 / 20 + 14\n#\u003e 14.005\n? Expression: (1 * (2 + 1)) + 1\n#\u003e 4\n```\n\n# How it works\nwe call the whole input an **experssion** (`expr` for short). Every `expr` might be made of combination of `terms`, `operators` and other `expr`.\nFor example take this input `1 + 2 [14 * (22 + 4)] + 7`. \n\n- `1 + 2 [14 * (22 + 4)] + 7` this is as whole called `expr`\n- `1` is a `term`\n- `+` is an operator\n- `[14 * (22 + 4)]` another `expr`\n- `(22 + 4)` another `expr`\n\nUsing this recursive relationship we can evaluate the `expr` in this manner \n```bash\nResult (+)\n├── 1\n├── 2\n├── [14 * (22 + 4)] (*)\n│   ├── 14 \n│   └── (22 + 4) (+)\n│       ├── 22 \n│       └── 4   \n└── 7\n```\n\nI am using a combination of **recursion** and **regular expressions** to be able to perform **nested** operations.\n\nat the core you will find this single `regexp`\n\n```rs\nlet re = Regex::new(r\"(\\(|\\[)(?P\u003cexpr\u003e[^\\)\\(\\]\\[]+)(\\)|\\])\").unwrap();\n```\n\nThis regexp should match any nested experssion that is inside `()` or `[]` or both. It will match **_from inside out_** for example consider this experssion `[()()]` it will match `()` then `()` then the whole `[() ()]` experssion\n\nI am sure if i tried to read this `regexp` on week from now I will not be able to do so! for this reason I am using interactive tool called [regexp101.com](https://regex101.com/r/Z8ELny/1) that make `regexp` easy to develop\n\nif you follow [this link](https://regex101.com/r/Z8ELny/1) you should see this\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"./regexp101.png\" alt=\"Numbers Adventure\" title=\"Numbers Adventure\"/\u003e\n\u003cp\u003e\n\n## Supported operations\n\n```rs\nenum Op {\n    Plus, // '+'\n    Mins, // '-'\n    Multi, // '*' | 'x'\n    Div, // '/'\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneuodev%2Fcalc-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneuodev%2Fcalc-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneuodev%2Fcalc-rs/lists"}