{"id":17434714,"url":"https://github.com/ganigeorgiev/fexpr","last_synced_at":"2025-04-09T05:08:22.536Z","repository":{"id":43817012,"uuid":"450887542","full_name":"ganigeorgiev/fexpr","owner":"ganigeorgiev","description":"Simple filter query language parser so that you can build SQL, Elasticsearch, etc. queries safely from user input.","archived":false,"fork":false,"pushed_at":"2025-03-27T11:57:29.000Z","size":52,"stargazers_count":119,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T03:58:31.312Z","etag":null,"topics":["dsl","filter-parser","parser","query"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ganigeorgiev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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-01-22T17:29:26.000Z","updated_at":"2025-04-01T06:15:16.000Z","dependencies_parsed_at":"2024-06-18T16:58:17.106Z","dependency_job_id":null,"html_url":"https://github.com/ganigeorgiev/fexpr","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ganigeorgiev%2Ffexpr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ganigeorgiev%2Ffexpr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ganigeorgiev%2Ffexpr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ganigeorgiev%2Ffexpr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ganigeorgiev","download_url":"https://codeload.github.com/ganigeorgiev/fexpr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247980837,"owners_count":21027808,"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":["dsl","filter-parser","parser","query"],"created_at":"2024-10-17T09:08:32.740Z","updated_at":"2025-04-09T05:08:22.514Z","avatar_url":"https://github.com/ganigeorgiev.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"fexpr\n[![Go Report Card](https://goreportcard.com/badge/github.com/ganigeorgiev/fexpr)](https://goreportcard.com/report/github.com/ganigeorgiev/fexpr)\n[![GoDoc](https://godoc.org/github.com/ganigeorgiev/fexpr?status.svg)](https://pkg.go.dev/github.com/ganigeorgiev/fexpr)\n================================================================================\n\n**fexpr** is a filter query language parser that generates easy to work with AST structure so that you can create safely SQL, Elasticsearch, etc. queries from user input.\n\nOr in other words, transform the string `\"id \u003e 1\"` into the struct `[{\u0026\u0026 {{identifier id} \u003e {number 1}}}]`.\n\nSupports parenthesis and various conditional expression operators (see [Grammar](https://github.com/ganigeorgiev/fexpr#grammar)).\n\n\n## Example usage\n\n```\ngo get github.com/ganigeorgiev/fexpr\n```\n\n```go\npackage main\n\nimport github.com/ganigeorgiev/fexpr\n\nfunc main() {\n    // [{\u0026\u0026 {{identifier id} = {number 123}}} {\u0026\u0026 {{identifier status} = {text active}}}]\n    result, err := fexpr.Parse(\"id=123 \u0026\u0026 status='active'\")\n}\n```\n\n\u003e Note that each parsed expression statement contains a join/union operator (`\u0026\u0026` or `||`) so that the result can be consumed on small chunks without having to rely on the group/nesting context.\n\n\u003e See the [package documentation](https://pkg.go.dev/github.com/ganigeorgiev/fexpr) for more details and examples.\n\n\n## Grammar\n\n**fexpr** grammar resembles the SQL `WHERE` expression syntax. It recognizes several token types (identifiers, numbers, quoted text, expression operators, whitespaces, etc.).\n\n\u003e You could find all supported tokens in [`scanner.go`](https://github.com/ganigeorgiev/fexpr/blob/master/scanner.go).\n\n#### Operators\n\n- **`=`**  Equal operator (eg. `a=b`)\n- **`!=`** NOT Equal operator (eg. `a!=b`)\n- **`\u003e`**  Greater than operator (eg. `a\u003eb`)\n- **`\u003e=`** Greater than or equal operator (eg. `a\u003e=b`)\n- **`\u003c`**  Less than or equal operator (eg. `a\u003cb`)\n- **`\u003c=`** Less than or equal operator (eg. `a\u003c=b`)\n- **`~`**  Like/Contains operator (eg. `a~b`)\n- **`!~`** NOT Like/Contains operator (eg. `a!~b`)\n- **`?=`**  Array/Any equal operator (eg. `a?=b`)\n- **`?!=`** Array/Any NOT Equal operator (eg. `a?!=b`)\n- **`?\u003e`**  Array/Any Greater than operator (eg. `a?\u003eb`)\n- **`?\u003e=`** Array/Any Greater than or equal operator (eg. `a?\u003e=b`)\n- **`?\u003c`**  Array/Any Less than or equal operator (eg. `a?\u003cb`)\n- **`?\u003c=`** Array/Any Less than or equal operator (eg. `a?\u003c=b`)\n- **`?~`**  Array/Any Like/Contains operator (eg. `a?~b`)\n- **`?!~`** Array/Any NOT Like/Contains operator (eg. `a?!~b`)\n- **`\u0026\u0026`** AND join operator (eg. `a=b \u0026\u0026 c=d`)\n- **`||`** OR join operator (eg. `a=b || c=d`)\n- **`()`** Parenthesis (eg. `(a=1 \u0026\u0026 b=2) || (a=3 \u0026\u0026 b=4)`)\n\n#### Numbers\nNumber tokens are any integer or decimal numbers.\n\n_Example_: `123`, `10.50`, `-14`.\n\n#### Quoted text\n\nText tokens are any literals that are wrapped by `'` or `\"` quotes.\n\n_Example_: `'Lorem ipsum dolor 123!'`, `\"escaped \\\"word\\\"\"`, `\"mixed 'quotes' are fine\"`.\n\n#### Identifiers\n\nIdentifier tokens are literals that start with a letter, `_`, `@` or `#` and could contain further any number of letters, digits, `.` (usually used as a separator) or `:` (usually used as modifier) characters.\n\n_Example_: `id`, `a.b.c`, `field123`, `@request.method`, `author.name:length`.\n\n#### Functions\n\nFunction tokens are similar to the identifiers but in addition accept a list of arguments enclosed in parenthesis `()`.\nThe function arguments must be separated by comma (_a single trailing comma is also allowed_) and each argument can be an identifier, quoted text, number or another nested function (_up to 2 nested_).\n\n_Example_: `test()`, `test(a.b, 123, \"abc\")`, `@a.b.c:test(true)`, `a(b(c(1, 2)))`.\n\n#### Comments\n\nComment tokens are any single line text literals starting with `//`.\nSimilar to whitespaces, comments are ignored by `fexpr.Parse()`.\n\n_Example_: `// test`.\n\n\n## Using only the scanner\n\nThe tokenizer (aka. `fexpr.Scanner`) could be used without the parser's state machine so that you can write your own custom tokens processing:\n\n```go\ns := fexpr.NewScanner([]byte(\"id \u003e 123\"))\n\n// scan single token at a time until EOF or error is reached\nfor {\n    t, err := s.Scan()\n    if t.Type == fexpr.TokenEOF || err != nil {\n        break\n    }\n\n    fmt.Println(t)\n}\n\n// Output:\n// {\u003cnil\u003e identifier id}\n// {\u003cnil\u003e whitespace  }\n// {\u003cnil\u003e sign \u003e}\n// {\u003cnil\u003e whitespace  }\n// {\u003cnil\u003e number 123}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fganigeorgiev%2Ffexpr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fganigeorgiev%2Ffexpr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fganigeorgiev%2Ffexpr/lists"}