{"id":19991162,"url":"https://github.com/tupac-amaru/yacep","last_synced_at":"2025-04-09T18:20:26.309Z","repository":{"id":144135584,"uuid":"173533703","full_name":"tupac-amaru/yacep","owner":"tupac-amaru","description":"yet another csharp expression parser","archived":false,"fork":false,"pushed_at":"2022-07-15T17:16:16.000Z","size":175,"stargazers_count":122,"open_issues_count":2,"forks_count":18,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-04-29T20:05:34.740Z","etag":null,"topics":["ast","cross-platform","csharp","dotnet-core","evaluator","expression-evaluator","expression-parser","netstandard20","parsing"],"latest_commit_sha":null,"homepage":null,"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/tupac-amaru.png","metadata":{"files":{"readme":"README-en_US.adoc","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":"2019-03-03T05:13:11.000Z","updated_at":"2024-03-24T14:56:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"a3a16934-847a-4754-8f09-fe21539bf3bb","html_url":"https://github.com/tupac-amaru/yacep","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tupac-amaru%2Fyacep","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tupac-amaru%2Fyacep/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tupac-amaru%2Fyacep/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tupac-amaru%2Fyacep/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tupac-amaru","download_url":"https://codeload.github.com/tupac-amaru/yacep/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248085324,"owners_count":21045139,"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","cross-platform","csharp","dotnet-core","evaluator","expression-evaluator","expression-parser","netstandard20","parsing"],"created_at":"2024-11-13T04:51:38.490Z","updated_at":"2025-04-09T18:20:26.259Z","avatar_url":"https://github.com/tupac-amaru.png","language":"C#","funding_links":[],"categories":["C\\#"],"sub_categories":[],"readme":"English (United States) | link:README.adoc[中文]\n\n# _YACEP_ : yet another csharp expression parser\n\nimage:https://dev.azure.com/tupac-amaru/yacep/_apis/build/status/tupac-amaru.yacep?branchName=master[\"Build Status\", link=\"https://dev.azure.com/tupac-amaru/yacep/_build/latest?definitionId=5\u0026branchName=master\"]\nimage:https://img.shields.io/azure-devops/coverage/tupac-amaru/yacep/5.svg?label=azure%20pipelines%20coverage\u0026color=#49bb1e[Azure DevOps coverage, link=\"https://dev.azure.com/tupac-amaru/yacep/_build/latest?definitionId=5\u0026branchName=master\"]\nimage:https://codecov.io/gh/tupac-amaru/yacep/branch/master/graph/badge.svg[\"Build Status\", link=\"https://codecov.io/gh/tupac-amaru/yacep\"]\nimage:https://travis-ci.com/tupac-amaru/yacep.svg?branch=master[\"Build Status\", link=\"https://travis-ci.com/tupac-amaru/yacep\"]\nimage:https://img.shields.io/appveyor/ci/wushilong/yacep.svg?color=#49bb1e[AppVeyor, link=\"https://ci.appveyor.com/project/wushilong/yacep/branch/master\"]\nimage:https://img.shields.io/sonar/https/sonarcloud.io/tupac-amaru_yacep/quality_gate.svg?color=#49bb1e[Sonar Quality Gate, link=\"https://sonarcloud.io/dashboard?id=tupac-amaru_yacep\"]\nimage:https://img.shields.io/appveyor/tests/wushilong/yacep.svg?color=#49bb1e[AppVeyor tests, link=\"https://ci.appveyor.com/project/wushilong/yacep/branch/master\"]\nimage:https://img.shields.io/nuget/v/TupacAmaru.Yacep.svg?color=#49bb1e[Nuget, link=\"https://www.nuget.org/packages/TupacAmaru.Yacep\"]\nimage:https://img.shields.io/github/license/tupac-amaru/yacep.svg?color=#49bb1e[\"License\",link=\"https://opensource.org/licenses/MIT\"]\n\n## Profile\n\n_YACEP_ is a small and tiny csharp expression parser, can parse a valid single-line string to an abstract syntax tree. It also provides a simple compiler that can compile an abstract syntax tree to an `IEvaluator` instance, \n`IEvaluator` instance can be executed as C# delegate.\n\nhttps://github.com/tupac-amaru/yacep/wiki[Document]\n\nhttps://github.com/tupac-amaru/yacep/tree/_benchmark[Benchmark report]\n\n[IMPORTANT] \n_YACEP_ not supported multi-line expressions and will not be supported in the future. if you need multi-line expressions, my recommendation is https://github.com/IronLanguages[IronLanguages]\n\n[source,csharp]\n----\n\"x+', '+y\".Compile().EvaluateAs\u003cstring\u003e(new { x = \"hello\", y = \"world\" });\n// value is  \"hello, world\"\n\"x + y\".Compile().EvaluateAs\u003cint\u003e(new { x = 1, y = 2 });\n// value is  3\n\nvar state = new\t\n{\t\n    x = 7,\n    y = 43.0f,\n    z = new Dictionary\u003cstring, string\u003e\t\n    {\t\n        [\"yacep\"] = \"yet another csharp expression parser\",\t\n        [\"tupac-amaru\"] = \"was the last indigenous monarch (Sapa Inca) of the Neo-Inca State\"\t\n    },\t\n    rand = new Func\u003cobject\u003e(() =\u003e new Random().Next(1, 3)),\t\n    array = Enumerable.Range(1971, 1996 - 1971)\t\n};\t\nvar expr = \"x + y - z['yacep'].Length + max([1, 2, 3]) + (this.rand() \u003e 2 ? 1971 : 1996) - len(array)\";\t\nvar evaluator = expr.Compile();\t\nvar value = evaluator.EvaluateAs\u003cdecimal\u003e(state); \n----\n\n### Why _YACEP_ ?\n- I found a very interesting thing when using https://www.docker.com/[docker], https://casbin.org/[Casbin]. After reading the source code of https://casbin.org/[Casbin], found that https://casbin.org/[Casbin] used a very simple DSL to solve a series of authorization problems. You can see it on https://casbin.org/[Casbin]'s official website. There are many implementations of the language, but the work of the .net platform https://github.com/Devolutions/casbin-net[Casbin-Net] has been in the WIP state for long time. After reading the source code of https://github.com/Devolutions/casbin-net[Casbin-Net], I found that the library did not continue to write down because it could not find a good expression parser. So I used a simplified  https://en.wikibooks.org/wiki/Algorithms/Hill_Climbing[hill climbing] algorithm to write a simple implementation.\n\n## Features\n- **Out of the box** - Zero-Configuration \n- **Custom unary operator** - support custom a string as an unary operator\n- **Custom binary operator** - support custom a string as a binary operator and set an https://en.wikipedia.org/wiki/Order_of_operations#Programming_language[order] for it\n- **Custom literal** - support custom a literal as a value\n- **Custom function** - support custom function\n- **Conditional expression** - like https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/conditional-operator[?:] operator in C#\n- **In expression** - evaluates to true if it finds a variable in an array and false otherwise\n- **Cross platform** - build with https://github.com/dotnet/standard/blob/master/docs/versions/netstandard2.0.md[netstandard2.0]\n- **Small and tiny** - the core parser code is only 500+ lines \n- **Low consumption** - use https://docs.microsoft.com/en-za/dotnet/api/system.readonlyspan-1?view=netcore-2.2[ReadOnlySpan\u003cT\u003e Struct] to read string\n- **High Performance** - good performance to access object's public method, field, property value instance over using C# reflection. https://github.com/tupac-amaru/yacep/tree/_benchmark[Benchmark report]\n\n## Quick Start\nhttps://github.com/tupac-amaru/yacep/wiki[Document]\n\n- Create a console application\n[source,shell]\n----\nmkdir yacep-demo\ncd yacep-demo\ndotnet new console\n----\n\n- add TupacAmaru.Yacep\n[source,shell]\n----\ndotnet add package TupacAmaru.Yacep\n----\n\n- update Program.cs\n[source,shell]\n----\ncat\u003eProgram.cs\u003c\u003cEOF\nusing TupacAmaru.Yacep.Extensions;\n\nnamespace yacep_demo\n{\n    class Program\n    {\n        static void Main()\n          =\u003e System.Console.WriteLine(\"x+', '+y\".Compile().EvaluateAs\u003cstring\u003e(new { x = \"hello\", y = \"world\" }));\n    }\n}\nEOF\n----\n#### _If using a windows system, please copy the following to Program.cs_\n\n[source,csharp]\n----\nusing TupacAmaru.Yacep.Extensions;\n\nnamespace yacep_demo\n{\n    class Program\n    {\n        static void Main()\n          =\u003e System.Console.WriteLine(\"x+', '+y\".Compile().EvaluateAs\u003cstring\u003e(new { x = \"hello\", y = \"world\" }));\n    }\n}\n----\n\n- Run\n[source,shell]\n----\ndotnet run\n----\n#### _Seeing the output `hello, world` means succeeded._\n## Thanks\n\n### Tool\u0026Library\n- https://github.com/xunit/xunit[xUnit.net]: a free, open source, community-focused unit testing tool for the .NET Framework\n- https://github.com/dotnet/BenchmarkDotNet[BenchmarkDotNet]: Powerful .NET library for benchmarking \n- https://github.com/tonerdo/coverlet[Coverlet]: Cross platform code coverage for .NET Core\n- https://github.com/danielpalme/ReportGenerator[ReportGenerator]: ReportGenerator converts coverage reports generated by OpenCover, dotCover, Visual Studio, NCover, Cobertura, JaCoCo or Clover into human readable reports in various formats.\n\n### Services\n- https://dev.azure.com/[Azure DevOps]\n- https://codecov.io/[Codecov]\n- https://travis-ci.com[travis-ci]\n- https://www.appveyor.com/[AppVeyor]\n- https://sonarcloud.io/about[SonarCloud]","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftupac-amaru%2Fyacep","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftupac-amaru%2Fyacep","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftupac-amaru%2Fyacep/lists"}