{"id":42511271,"url":"https://github.com/bhmj/xpression","last_synced_at":"2026-01-28T14:12:34.348Z","repository":{"id":45193313,"uuid":"423798161","full_name":"bhmj/xpression","owner":"bhmj","description":"Expression parser written in Go","archived":false,"fork":false,"pushed_at":"2023-04-17T13:13:38.000Z","size":81,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-06-21T04:30:24.371Z","etag":null,"topics":["expression","go","golang","library","parser"],"latest_commit_sha":null,"homepage":"","language":"Go","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/bhmj.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":"2021-11-02T10:25:54.000Z","updated_at":"2024-03-22T11:45:24.000Z","dependencies_parsed_at":"2024-06-20T02:51:59.363Z","dependency_job_id":"280d7765-8dd3-4de2-b679-516142a94ff9","html_url":"https://github.com/bhmj/xpression","commit_stats":null,"previous_names":["bhmj/expression_parser"],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/bhmj/xpression","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhmj%2Fxpression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhmj%2Fxpression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhmj%2Fxpression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhmj%2Fxpression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bhmj","download_url":"https://codeload.github.com/bhmj/xpression/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhmj%2Fxpression/sbom","scorecard":{"id":236598,"data":{"date":"2025-08-11","repo":{"name":"github.com/bhmj/xpression","commit":"358241ccdecd2622ceb47559438b4e2062971e27"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.5,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":0,"reason":"Found 0/27 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENCE:0","Info: FSF or OSI recognized license: MIT License: LICENCE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 5 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-17T05:53:47.600Z","repository_id":45193313,"created_at":"2025-08-17T05:53:47.600Z","updated_at":"2025-08-17T05:53:47.600Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28846058,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T13:02:32.985Z","status":"ssl_error","status_checked_at":"2026-01-28T13:02:04.945Z","response_time":57,"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":["expression","go","golang","library","parser"],"created_at":"2026-01-28T14:12:33.584Z","updated_at":"2026-01-28T14:12:34.342Z","avatar_url":"https://github.com/bhmj.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Expression parser/evaluator in Go\n\n## What is it?\n\nThis project is a renewed version of expression parser/evaluator used in [jsonslice](https://github.com/bhmj/jsonslice). It allows you to evaluate simple arithmetic expressions with variable support.\n\n## Check it out\n\n```\ngit clone https://github.com/bhmj/xpression.git\n\ncd xpression\n\nmake build\n\n./bin/xpression \"1+2\"\n````\n\nExpression examples:\n\n`1+2`  \n`2**1**2`  \n`3 + 4 * 2 / (1-5) ** 2 ** 3`  \n`5 + -5`  \n`1/(3 \u0026 5)`  \n`'a' \u003e 'b'`  \n`'abc' =~ /a.c/i`  \n`!((false))`\n\n## Usage\n\n```Go\n    // simple expression evaluation (error handling skipped)\n    result, _ := xpression.EvalStr(`5-3*(6-12)`)\n    fmt.Println(result.String())\n\n    // external data in expression (aka variables)\n    foobar := 123\n    varMapper := map[string]*int{\n        `foobar`: \u0026foobar,\n    }\n    varFunc := func(name []byte, result *xpression.Operand) error {\n        ref := varMapper[string(name)]\n        if ref == nil {\n            return errors.New(\"unknown variable\")\n        }\n        result.SetNumber(float64(*ref))\n        return nil\n    }\n    result, _ = xpression.EvalVarStr(`27 / foobar`, varFunc)\n    fmt.Println(result.String())\n```\n[Run in Go Playground](https://play.golang.com/p/YaweDHqUJKa)\n\n## Functions\n\n```Go\nfunc Eval(expression []byte) (*Operand, error)\n```\nEval evaluates expression and returns the result. No external variables used. See EvalVar for more.\nReturns a pointer to Operand or error.\nUse Operand's method `.String()` to get a serializable value or see Operand's `.OperandType` field to determine the result type and get the value from `.Str`, `.Number` or `.Bool` field.\n\n```Go\nfunc EvalVar(expression []byte, varFunc VariableFunc) (*Operand, error)\n```\n`EvalVar` evaluates expression and returns the result. External variables can be used via `varFunc`.\n\n```Go\nfunc EvalStr(expression string) (*Operand, error)\n```\nSame as `Eval` but receives a `string` instead of `[]byte`.\n\n```Go\nfunc EvalVarStr(expression string, varFunc VariableFunc) (*Operand, error)\n```\nSame as `EvalVar` but receives a `string` instead of `[]byte`.\n\n## xpression CLI\n\nYou can find a simple and dumb expression evaluation CLI tool in cmd/xpression.  \nBuild it with `make build` and run with `./bin/xpression`.  \n\nFeel free to make your own, better implementation.  \n\nRemember that this evaluator complies with JavaScript rules, so the following example is legitimate and behaves JavaScript-like:  \n```\n\u003e a = 123\n123\n\u003e (\"0x\" + a) * 2\n582\n```\n\n## Operators and data types supported\n\nOperators | \u0026nbsp;\n--- | ---\nArithmetic | `+` `-` `*` `/` `**` `%`\nBitwise | `\\|` `\u0026` `^` `~` `\u003c\u003c` `\u003e\u003e`\nLogical | `\u0026\u0026` `\\|\\|` `!`\nComparison | `==` `!=` `===` `!==` `\u003e=` `\u003e` `\u003c=` `\u003c`\nRegexp | `=~` `!=~` `!~`\nParentheses | `(` `)`\n\n\u003cb\u003eData types\u003c/b\u003e | \u0026nbsp;\n--- | ---\nString constants | `'string'` or `\"string\"`\nNumeric | 64-bit integers or floats in decimal or hexadecimal form: `123` or `0.123` or `1.2e34` or `0x12a` or `0x12A`\nBoolean | `true` or `false`. Comparison results in boolean value.\nRegexp | `/expression/` with modifiers:\u003cbr\u003e`i` (case-insensitive), `m` (multiline), `s` (single-line), `U` (ungreedy)\nOther | `null`\n\n## Test coverage\n\nTests cover the majority of cases described in ECMAScript Language definition (specifically [ECMAScript Language: Expressions reference](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html) and [Testing and Comparison Operations](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-testing-and-comparison-operations)). \n\n## Benchmarks\n\nEvaluate `(2) + (2) == (4)`\n\n```golang\n$ go test -bench=. -benchmem -benchtime=4s\ngoos: darwin\ngoarch: amd64\npkg: github.com/bhmj/xpression\ncpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz\nBenchmark_ModifiedNumericLiteral_WithParsing-16       2622770    1811 ns/op   1272 B/op   26 allocs/op\nBenchmark_ModifiedNumericLiteral_WithoutParsing-16   77455698   57.55 ns/op      0 B/op    0 allocs/op\nPASS\nok      github.com/bhmj/xpression       11.548s\n```\n\nThe same expression evaluated with [github.com/Knetic/govaluate](https://github.com/Knetic/govaluate) :\n\n```golang\n$ go test -bench='LiteralModifiers' -benchmem -benchtime=4s\ngoos: darwin\ngoarch: amd64\npkg: github.com/Knetic/govaluate\ncpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz\nBenchmarkEvaluationLiteralModifiers_WithParsing-16    1000000    4019 ns/op   2208 B/op   43 allocs/op\nBenchmarkEvaluationLiteralModifiers-16               30173640   147.2 ns/op      8 B/op    1 allocs/op\nPASS\nok      github.com/Knetic/govaluate     9.810s\n```\n\n\n## Changelog\n\n**0.9.4** (2022-11-28) -- Go 1.19 support. `EvalStr` and `EvalVarStr` helper functions added.  \n**0.9.3** (2022-07-06) -- bugfixes: string to hex conversion `\"0x123\"*2`, closing bracket after a variable `(0+a)`.  \n**0.9.2** (2022-02-23) -- Minor code refactoring. One-liner functions added (Eval, EvalVar).  \n**0.9.1** (2022-01-02) -- Variable bounds refined.  \n**0.9.0** (2021-11-19) -- Memory allocation reduced. Speed optimization.  \n**0.8.0** (2021-11-11) -- hex numbers support. Production ready.  \n**0.7.x** (2021-11-11) -- WIP  \n**0.7.0** (2021-11-10) -- project renamed to `xpression`  \n**0.6.0** (2021-11-05) -- a remainder operator `%` added. Benchmarks added. Some optimization done.  \n**0.5.0** (2021-11-04) -- Tests added. Multiple bugs fixed.  \n**0.4.0** (2021-11-02) -- Expression evaluation.  \n**0.3.0** (2021-11-01) -- MVP.\n\n## Roadmap\n\n- [x] arithmetic operators: `+ - * / **` `%`\n- [x] bitwise operators: `| \u0026 ^ ~`\n- [x] logical operators: `|| \u0026\u0026 !`\n- [x] comparison operators: `\u003e \u003c \u003e= \u003c= == === != !==`\n- [x] full support of parentheses\n- [x] regular expressions for strings\n- [x] unary minus supported\n- [x] expression evaluation\n- [x] parser test coverage\n- [x] evaluator test coverage\n- [x] add external reference type aka variable (node reference in jsonslice)\n- [x] optimize memory allocations\n- [ ] Unicode support\n- [ ] add math functions support (?)\n- [ ] add math/big support (?)\n\n## Contributing\n\n1. Fork it!\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. Submit a pull request :)\n\n## Licence\n\n[MIT](http://opensource.org/licenses/MIT)\n\n## Author\n\nMichael Gurov aka BHMJ\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbhmj%2Fxpression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbhmj%2Fxpression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbhmj%2Fxpression/lists"}