{"id":21179036,"url":"https://github.com/spaceavocado/goillogical","last_synced_at":"2025-06-19T16:38:10.855Z","repository":{"id":65752708,"uuid":"594587368","full_name":"spaceavocado/goillogical","owner":"spaceavocado","description":"A micro conditional go engine used to parse the raw logical and comparison expressions, evaluate the expression in the given data context, and provide access to a text form of the given expressions.","archived":false,"fork":false,"pushed_at":"2024-08-27T18:20:56.000Z","size":126,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-21T11:45:40.903Z","etag":null,"topics":["expression","expression-evaluator","logical"],"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/spaceavocado.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":"contributing.md","funding":null,"license":"license.txt","code_of_conduct":"code_of_conduct.md","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":"2023-01-29T02:02:32.000Z","updated_at":"2024-08-27T18:21:00.000Z","dependencies_parsed_at":"2024-08-27T16:43:11.141Z","dependency_job_id":"51f1e7a9-31f7-4687-b093-e70864a43c5b","html_url":"https://github.com/spaceavocado/goillogical","commit_stats":{"total_commits":48,"total_committers":1,"mean_commits":48.0,"dds":0.0,"last_synced_commit":"c807db0af7010e3213adc79db5fb85c2676fd91f"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spaceavocado%2Fgoillogical","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spaceavocado%2Fgoillogical/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spaceavocado%2Fgoillogical/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spaceavocado%2Fgoillogical/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spaceavocado","download_url":"https://codeload.github.com/spaceavocado/goillogical/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243629556,"owners_count":20322079,"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":["expression","expression-evaluator","logical"],"created_at":"2024-11-20T17:28:03.259Z","updated_at":"2025-03-14T18:44:28.002Z","avatar_url":"https://github.com/spaceavocado.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# (go)illogical\n\nA micro conditional javascript engine used to parse the raw logical and comparison expressions, evaluate the expression in the given data context, and provide access to a text form of the given expressions.\n\n\u003e Revision: Aug 27, 2024.\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://goreportcard.com/report/github.com/spaceavocado/goillogical\"\u003e\u003cimg class=\"badge\" tag=\"https://github.com/spaceavocado/goillogical\" src=\"https://goreportcard.com/badge/github.com/spaceavocado/goillogical\"\u003e\u003c/a\u003e\n\u003ca href=\"https://codecov.io/gh/spaceavocado/goillogical\" \u003e\n\u003cimg src=\"https://codecov.io/gh/spaceavocado/goillogical/branch/master/graph/badge.svg?token=16C3FQ0IA2\"/\u003e\n\u003c/a\u003e\n\u003ca href=\"https://godoc.org/github.com/spaceavocado/goillogical\"\u003e\u003cimg alt=\"Go Doc\" src=\"https://godoc.org/github.com/spaceavocado/goillogical?status.svg\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nOther implementations:\n- [TS/JS](https://github.com/spaceavocado/illogical)\n- [Python](https://github.com/spaceavocado/pyillogical)\n- [C#](https://github.com/spaceavocado/cillogical)\n- [Java](https://github.com/spaceavocado/jillogical)\n- [Odin](https://github.com/spaceavocado/oillogical)\n\n## About\n\nThis project has been developed to provide Go(lang) implementation of [spaceavocado/illogical](https://github.com/spaceavocado/illogical).\n\n\n## Getting Started\n\n```sh\ngo get -u github.com/spaceavocado/goillogical@latest\n```\n\n**Table of Content**\n\n---\n\n- [(go)illogical](#goillogical)\n  - [About](#about)\n  - [Getting Started](#getting-started)\n  - [Basic Usage](#basic-usage)\n    - [Evaluate](#evaluate)\n    - [Statement](#statement)\n    - [Parse](#parse)\n    - [Evaluable](#evaluable)\n      - [Simplify](#simplify)\n      - [Serialize](#serialize)\n  - [Working with Expressions](#working-with-expressions)\n    - [Evaluation Data Context](#evaluation-data-context)\n      - [Accessing Array Element:](#accessing-array-element)\n      - [Accessing Array Element via Reference:](#accessing-array-element-via-reference)\n      - [Nested Referencing](#nested-referencing)\n      - [Composite Reference Key](#composite-reference-key)\n      - [Data Type Casting](#data-type-casting)\n    - [Operand Types](#operand-types)\n      - [Value](#value)\n      - [Reference](#reference)\n      - [Collection](#collection)\n    - [Comparison Expressions](#comparison-expressions)\n      - [Equal](#equal)\n      - [Not Equal](#not-equal)\n      - [Greater Than](#greater-than)\n      - [Greater Than or Equal](#greater-than-or-equal)\n      - [Less Than](#less-than)\n      - [Less Than or Equal](#less-than-or-equal)\n      - [In](#in)\n      - [Not In](#not-in)\n      - [Prefix](#prefix)\n      - [Suffix](#suffix)\n      - [Overlap](#overlap)\n      - [Nil](#nil)\n      - [Present](#present)\n    - [Logical Expressions](#logical-expressions)\n      - [And](#and)\n      - [Or](#or)\n      - [Nor](#nor)\n      - [Xor](#xor)\n      - [Not](#not)\n  - [Engine Options](#engine-options)\n    - [Reference Serialize Options](#reference-serialize-options)\n      - [From](#from)\n      - [To](#to)\n    - [Collection Serialize Options](#collection-serialize-options)\n      - [Escape Character](#escape-character)\n    - [Simplify Options](#simplify-options)\n      - [Ignored Paths](#ignored-paths)\n      - [Ignored Paths RegEx](#ignored-paths-regex)\n    - [Operator Mapping](#operator-mapping)\n    - [Multiple Options](#multiple-options)\n  - [Contributing](#contributing)\n  - [License](#license)\n\n---\n\n\n## Basic Usage\n\n```go\nimport (\n\tillogical \"github.com/spaceavocado/goillogical\n)\n\n// Create a new instance of the engine\ni := illogical.New()\n\n// Evaluate the raw expression\nres, err := i.Evaluate([]any{\"==\", 1, 1}, map[string]any{})\n```\n\n\u003e For advanced usage, please [Engine Options](#engine-options).\n\n### Evaluate\n\nEvaluate comparison or logical expression:\n\n`i.evaluate(`[Comparison Expression](#comparison-expressions) or [Logical Expression](#logical-expressions), [Evaluation Data Context](#evaluation-data-context)`)` =\u003e `boolean`\n\n\u003e Data context is optional.\n\n**Example**\n\n```go\nctx := map[string]any{\n  \"name\": \"peter\",\n}\n\n// Comparison expression\ni.Evaluate([]any{\"==\", 5, 5}, ctx)\ni.Evaluate([]any{\"==\", \"circle\", \"circle\"}, ctx)\ni.Evaluate([]any{\"==\", true, true}, ctx)\ni.Evaluate([]any{\"==\", \"$name\", \"peter\"}, ctx)\ni.Evaluate([]any{\"NONE\", \"$RefA\"}, ctx)\n\n// Logical expression\ni.Evaluate([]any{\"AND\", []any{\"==\", 5, 5}, []any{\"==\", 10, 10}}, ctx)\ni.Evaluate([]any{\"AND\", []any{\"==\", \"circle\", \"circle\"}, []any{\"==\", 10, 10}}, ctx)\ni.Evaluate([]any{\"OR\", []any{\"==\", \"$name\", \"peter\"}, []any{\"==\", 5, 10}}, ctx)\n```\n\n### Statement\n\nGet expression string representation:\n\n`i.Statement(`[Comparison Expression](#comparison-expressions) or [Logical Expression](#logical-expressions)`)` =\u003e `string`\n\n**Example**\n\n```go\n// Comparison expression\n\ni.Statement([]any{\"==\", 5, 5}) // (5 == 5)\ni.Statement([]any{\"==\", \"circle\", \"circle\"}) // (\"circle\" == \"circle\")\ni.Statement([]any{\"==\", true, true}) // (true == true)\ni.Statement([]any{\"==\", \"$name\", \"peter\"}) // ({name} == \"peter\")\ni.Statement([]any{\"NONE\", \"$RefA\"}) // ({RefA} \u003cis nil\u003e)\n\n// Logical expression\n\ni.Statement([]any{\"AND\", []any{\"==\", 5, 5}, []any{\"==\", 10, 10}}) // ((5 == 5) AND (10 == 10))\ni.Statement([]any{\"AND\", []any{\"==\", \"circle\", \"circle\"}, []any{\"==\", 10, 10}}) // ((\"circle\" == \"circle\") AND (10 == 10))\ni.Statement([]any{\"OR\", []any{\"==\", \"$name\", \"peter\"}, []any{\"==\", 5, 10}}) // (({name} == \"peter\") OR (5 == 10))\n```\n\n### Parse\n\nParse the expression into a **Evaluable** object, i.e. it returns the parsed self-evaluable condition expression.\n\n`i.Parse(`[Comparison Expression](#comparison-expressions) or [Logical Expression](#logical-expressions)`)` =\u003e `Evaluable`\n\n### Evaluable\n\n- `evaluable.Evaluate(context)` please see [Evaluation Data Context](#evaluation-data-context).\n- `evaluable.String()` please see [Statement](#statement).\n- `evaluable.Simplify(context)` please see [Simplify](#simplify).\n\n**Example**\n\n```go\ne, err := i.Parse([]any{\"==\", \"$name\", \"peter\"})\n\ne.Evaluate(map[string]any{\"name\": \"peter\"}) // true\ne.String() // ({name} == \"peter\")\n```\n\n#### Simplify\n\nSimplifies an expression with a given context. This is useful when you already have some of\nthe properties of context and wants to try to evaluate the expression.\n\n**Example**\n\n```go\ne, err := i.Parse([]any{\"AND\", []any{\"==\", \"$a\", 10}, []any{\"==\", \"$b\", 20}})\n\ne.Simplify(map[string]any{\"a\": 10}) // ({b} == 20)\ne.simplify(map[string]any{\"a\": 20}) // false\n```\n\nValues not found in the context will cause the parent operand not to be evaluated and returned\nas part of the simplified expression.\n\nIn some situations we might want to evaluate the expression even if referred value is not\npresent. You can provide a list of keys that will be strictly evaluated even if they are not\npresent in the context.\n\n**Example**\n\n```go\nsimplifyOptions := illogical.WithReferenceSimplifyOptions(illogical.SimplifyOptions{\n  IgnoredPaths: []string{\"ignored\"},\n  IgnoredPathsRx: []regexp.Regexp{*regexp.MustCompile(\"^ignored\")},\n})\ni := illogical.New(simplifyOptions)\n\ne, err := i.Parse([]any{\"AND\", []any{\"==\", \"$a\", 10}, []any{\"==\", \"$ignored\", 20}})\ne.Simplify(map[string]any{\"a\": 10})\n\n// false\n// $ignored\" will be evaluated to nil.\n```\n\nAlternatively we might want to do the opposite and strictly evaluate the expression for all referred\nvalues not present in the context except for a specified list of optional keys.\n\n**Example**\n\n```go\nsimplifyOptions := illogical.WithReferenceSimplifyOptions(illogical.SimplifyOptions{\n  IgnoredPaths: []string{\"b\"},\n  IgnoredPathsRx: []regexp.Regexp{},\n})\ni := illogical.New(simplifyOptions)\n\ne, err := i.Parse([]any{\"OR\", []any{\"==\", \"$a\", 10}, []any{\"==\", \"$b\", 20}, []any{\"==\", \"$c\", 20}})\ne.Simplify(map[string]any{\"c\": 10})\n\n// ({a} == 10)\n// except for \"$b\" everything not in context will be evaluated to nil.\n```\n\n#### Serialize\n\nSerializes an expression into the raw data form, reverse parse operation.\n\n**Example**\n\n```go\ne, err := i.Parse([]any{\"AND\", []any{\"==\", \"$a\", 10}, []any{\"==\", 10, 20}})\ne.Serialize() // [AND [== $a 10] [== 10 20]]\n```\n\n## Working with Expressions\n\n### Evaluation Data Context\n\nThe evaluation data context is used to provide the expression with variable references, i.e. this allows for the dynamic expressions. The data context is object with properties used as the references keys, and its values as reference values.\n\n\u003e Valid reference values: object, string, number, [] boolean | string | number.\n\nTo reference the nested reference, please use \".\" delimiter, e.g.:\n`$address.city`\n\n#### Accessing Array Element:\n\n`$options[1]`\n\n#### Accessing Array Element via Reference:\n\n`$options[{index}]`\n\n- The **index** reference is resolved within the data context as an array index.\n\n#### Nested Referencing\n\n`$address.{segment}`\n\n- The **segment** reference is resolved within the data context as a property key.\n\n#### Composite Reference Key\n\n`$shape{shapeType}`\n\n- The **shapeType** reference is resolved within the data context, and inserted into the outer reference key.\n- E.g. **shapeType** is resolved as \"**B**\" and would compose the **$shapeB** outer reference.\n- This resolution could be n-nested.\n\n#### Data Type Casting\n\n`$payment.amount.(Type)`\n\nCast the given data context into the desired data type before being used as an operand in the evaluation.\n\n\u003e Note: If the conversion is invalid, then a warning message is being logged.\n\nSupported data type conversions:\n\n- .(String): cast a given reference to String.\n- .(Number): cast a given reference to Number.\n- .(Integer): cast a given reference to Integer.\n- .(Float): cast a given reference to Float.\n- .(Boolean): cast a given reference to Boolean.\n\n**Example**\n\n```go\n// Data context\nctx := map[string]any{\n  \"name\":    \"peter\",\n  \"country\": \"canada\",\n  \"age\":     21,\n  \"options\": []int{1, 2, 3},\n  \"address\": struct {\n    city    string\n    country string\n  }{\n    city:    \"Toronto\",\n    country: \"Canada\",\n  },\n  \"index\":     2,\n  \"segment\":   \"city\",\n  \"shapeA\":    \"box\",\n  \"shapeB\":    \"circle\",\n  \"shapeType\": \"B\",\n}\n\n// Evaluate an expression in the given data context\ni.Evaluate([]any{\"\u003e\", \"$age\", 20}, ctx) // true\n\n// Evaluate an expression in the given data context\ni.Evaluate([]any{\"==\", \"$address.city\", \"Toronto\"}, ctx) // true\n\n// Accessing Array Element\ni.Evaluate([]any{\"==\", \"$options[1]\", 2}, ctx) // true\n\n// Accessing Array Element via Reference\ni.Evaluate([]any{\"==\", \"$options[{index}]\", 3}, ctx) // true\n\n// Nested Referencing\ni.Evaluate([]any{\"==\", \"$address.{segment}\", \"Toronto\"}, ctx) // true\n\n// Composite Reference Key\ni.Evaluate([]any{\"==\", \"$shape{shapeType}\", \"circle\"}, ctx) // true\n\n// Data Type Casting\ni.Evaluate([]any{\"==\", \"$age.(String)\", \"21\"}, ctx) // true\n```\n\n### Operand Types\n\nThe [Comparison Expression](#comparison-expression) expect operands to be one of the below:\n\n#### Value\n\nSimple value types: string, number, boolean.\n\n**Example**\n\n```go\nval1 := 5\nvar2 := \"cirle\"\nvar3 := true\n\ni.Parse([]any{\"AND\", []any{\"==\", val1, var2}, []any{\"==\", var3, var3}})\n```\n\n#### Reference\n\nThe reference operand value is resolved from the [Evaluation Data Context](#evaluation-data-context), where the the operands name is used as key in the context.\n\nThe reference operand must be prefixed with `$` symbol, e.g.: `$name`. This might be customized via [Reference Predicate Parser Option](#reference-predicate).\n\n**Example**\n\n| Expression                    | Data Context      |\n| ----------------------------- | ----------------- |\n| `[\"==\", \"$age\", 21]`          | `{age: 21}`       |\n| `[\"==\", \"circle\", \"$shape\"] ` | `{shape: \"circle\"}` |\n| `[\"==\", \"$visible\", true]`    | `{visible: true}` |\n\n#### Collection\n\nThe operand could be an array mixed from [Value](#value) and [Reference](#reference).\n\n**Example**\n\n| Expression                               | Data Context                        |\n| ---------------------------------------- | ----------------------------------- |\n| `[\"IN\", [1, 2], 1]`                      | `{}`                                |\n| `[\"IN\", \"circle\", [\"$shapeA\", \"$shapeB\"] ` | `{shapeA: \"circle\", shapeB: \"box\"}` |\n| `[\"IN\", [\"$number\", 5], 5]`                | `{number: 3}`                       |\n\n### Comparison Expressions\n\n#### Equal\n\nExpression format: `[\"==\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: string, number, boolean.\n\n```json\n[\"==\", 5, 5]\n```\n\n```go\ni.Evaluate([]any{\"==\", 5, 5}, ctx) // true\n```\n\n#### Not Equal\n\nExpression format: `[\"!=\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: string, number, boolean.\n\n```json\n[\"!=\", \"circle\", \"square\"]\n```\n\n```go\ni.Evaluate([]any{\"!=\", \"circle\", \"square\"}, ctx) // true\n```\n\n#### Greater Than\n\nExpression format: `[\"\u003e\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: number.\n\n```json\n[\"\u003e\", 10, 5]\n```\n\n```go\ni.Evaluate([]any{\"\u003e\", 10, 5}, ctx) // true\n```\n\n#### Greater Than or Equal\n\nExpression format: `[\"\u003e=\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: number.\n\n```json\n[\"\u003e=\", 5, 5]\n```\n\n```go\ni.Evaluate([]any{\"\u003e=\", 5, 5}, ctx) // true\n```\n\n#### Less Than\n\nExpression format: `[\"\u003c\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: number.\n\n```json\n[\"\u003c\", 5, 10]\n```\n\n```go\ni.Evaluate([]any{\"\u003c\", 5, 10}, ctx) // true\n```\n\n#### Less Than or Equal\n\nExpression format: `[\"\u003c=\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: number.\n\n```json\n[\"\u003c=\", 5, 5]\n```\n\n```go\ni.Evaluate([]any{\"\u003c=\", 5, 5}, ctx) // true\n```\n\n#### In\n\nExpression format: `[\"IN\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: number and number[] or string and string[].\n\n```json\n[\"IN\", 5, [1, 2, 3, 4, 5]]\n[\"IN\", [\"circle\", \"square\", \"triangle\"], \"square\"]\n```\n\n```go\ni.Evaluate([]any{\"IN\", 5, []int{1, 2, 3, 4, 5}}, ctx) // true\ni.Evaluate([]any{\"IN\", []string{\"circle\", \"square\", \"triangle\"}, \"square\"}, ctx) // true\n```\n\n#### Not In\n\nExpression format: `[\"NOT IN\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: number and number[] or string and string[].\n\n```json\n[\"IN\", 10, [1, 2, 3, 4, 5]]\n[\"IN\", [\"circle\", \"square\", \"triangle\"], \"oval\"]\n```\n\n```go\ni.Evaluate([]any{\"NOT IN\", 10, []int{1, 2, 3, 4, 5}}, ctx) // true\ni.Evaluate([]any{\"NOT IN\", []string{\"circle\", \"square\", \"triangle\"}, \"oval\"}, ctx) // true\n```\n\n#### Prefix\n\nExpression format: `[\"PREFIX\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: string.\n\n- Left operand is the PREFIX term.\n- Right operand is the tested word.\n\n```json\n[\"PREFIX\", \"hemi\", \"hemisphere\"]\n```\n\n```go\ni.Evaluate([]any{\"PREFIX\", \"hemi\", \"hemisphere\"}, ctx) // true\ni.Evaluate([]any{\"PREFIX\", \"hemi\", \"sphere\"}, ctx) // false\n```\n\n#### Suffix\n\nExpression format: `[\"SUFFIX\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: string.\n\n- Left operand is the tested word.\n- Right operand is the SUFFIX term.\n\n```json\n[\"SUFFIX\", \"establishment\", \"ment\"]\n```\n\n```go\ni.Evaluate([]any{\"SUFFIX\", \"establishment\", \"ment\"}, ctx) // true\ni.Evaluate([]any{\"SUFFIX\", \"establish\", \"ment\"}, ctx) // false\n```\n\n#### Overlap\n\nExpression format: `[\"OVERLAP\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types number[] or string[].\n\n```json\n[\"OVERLAP\", [1, 2], [1, 2, 3, 4, 5]]\n[\"OVERLAP\", [\"circle\", \"square\", \"triangle\"], [\"square\"]]\n```\n\n```go\ni.Evaluate([]any{\"OVERLAP\", []int{1, 2, 6}, []int{1, 2, 3, 4, 5}}, ctx) // true\ni.Evaluate([]any{\"OVERLAP\", []string{\"circle\", \"square\", \"triangle\"}, []string{\"square\", \"oval\"}}, ctx) // true\n```\n\n#### Nil\n\nExpression format: `[\"NONE\", `[Reference Operand](#reference)`]`.\n\n```json\n[\"NONE\", \"$RefA\"]\n```\n\n```go\ni.Evaluate([]any{\"NONE\", \"RefA\"}, map[string]any{}) // true\ni.Evaluate([]any{\"NONE\", \"RefA\"}, map[string]any{\"RefA\": 10}) // false\n```\n\n#### Present\n\nEvaluates as FALSE when the operand is UNDEFINED or NULL.\n\nExpression format: `[\"PRESENT\", `[Reference Operand](#reference)`]`.\n\n```json\n[\"PRESENT\", \"$RefA\"]\n```\n\n```go\ni.Evaluate([]any{\"PRESENT\", \"RefA\"}, map[string]any{}) // false\ni.Evaluate([]any{\"PRESENT\", \"RefA\"}, map[string]any{\"RefA\": 10}) // true\ni.Evaluate([]any{\"PRESENT\", \"RefA\"}, map[string]any{\"RefA\": false}) // true\ni.Evaluate([]any{\"PRESENT\", \"RefA\"}, map[string]any{\"RefA\": \"val\"}) // true\n```\n\n### Logical Expressions\n\n#### And\n\nThe logical AND operator (\u0026\u0026) returns the boolean value TRUE if both operands are TRUE and returns FALSE otherwise.\n\nExpression format: `[\"AND\", Left Operand 1, Right Operand 2, ... , Right Operand N]`.\n\n\u003e Valid operand types: [Comparison Expression](#comparison-expressions) or [Nested Logical Expression](#logical-expressions).\n\n```json\n[\"AND\", [\"==\", 5, 5], [\"==\", 10, 10]]\n```\n\n```go\ni.Evaluate([]any{\"AND\", []any{\"==\", 5, 5}, []any{\"==\", 10, 10}}, ctx) // true\n```\n\n#### Or\n\nThe logical OR operator (||) returns the boolean value TRUE if either or both operands is TRUE and returns FALSE otherwise.\n\nExpression format: `[\"OR\", Left Operand 1, Right Operand 2, ... , Right Operand N]`.\n\n\u003e Valid operand types: [Comparison Expression](#comparison-expressions) or [Nested Logical Expression](#logical-expressions).\n\n```json\n[\"OR\", [\"==\", 5, 5], [\"==\", 10, 5]]\n```\n\n```go\ni.Evaluate([]any{\"OR\", []any{\"==\", 5, 5}, []any{\"==\", 10, 5}}, ctx) // true\n```\n\n#### Nor\n\nThe logical NOR operator returns the boolean value TRUE if both operands are FALSE and returns FALSE otherwise.\n\nExpression format: `[\"NOR\", Left Operand 1, Right Operand 2, ... , Right Operand N]`\n\n\u003e Valid operand types: [Comparison Expression](#comparison-expressions) or [Nested Logical Expression](#logical-expressions).\n\n```json\n[\"NOR\", [\"==\", 5, 1], [\"==\", 10, 5]]\n```\n\n```go\ni.Evaluate([]any{\"NOR\", []any{\"==\", 5, 1}, []any{\"==\", 10, 5}}, ctx) // true\n```\n\n#### Xor\n\nThe logical NOR operator returns the boolean value TRUE if both operands are FALSE and returns FALSE otherwise.\n\nExpression format: `[\"XOR\", Left Operand 1, Right Operand 2, ... , Right Operand N]`\n\n\u003e Valid operand types: [Comparison Expression](#comparison-expressions) or [Nested Logical Expression](#logical-expressions).\n\n```json\n[\"XOR\", [\"==\", 5, 5], [\"==\", 10, 5]]\n```\n\n```go\ni.Evaluate([]any{\"XOR\", []any{\"==\", 5, 5}, []any{\"==\", 10, 5}}, ctx) // true\n```\n\n```json\n[\"XOR\", [\"==\", 5, 5], [\"==\", 10, 10]]\n```\n\n```go\ni.Evaluate([]any{\"XOR\", []any{\"==\", 5, 5}, []any{\"==\", 10, 10}}, ctx) // false\n```\n\n#### Not\n\nThe logical NOT operator returns the boolean value TRUE if the operand is FALSE, TRUE otherwise.\n\nExpression format: `[\"NOT\", Operand]`\n\n\u003e Valid operand types: [Comparison Expression](#comparison-expressions) or [Nested Logical Expression](#logical-expressions).\n\n```json\n[\"NOT\", [\"==\", 5, 5]]\n```\n\n```go\ni.Evaluate([]any{\"NOT\", []any{\"==\", 5, 5}}, ctx) // true\n```\n\n## Engine Options\n\n### Reference Serialize Options\n\n**Usage**\n\n```go\nreferenceSerializeOptions := illogical.WithReferenceSerializeOptions(illogical.ReferenceSerializeOptions{\n  From: func(string) (string, error)\n\tTo:   func(string) string\n})\n\ni := illogical.New(referenceSerializeOptions)\n```\n\n#### From\n\nA function used to determine if the operand is a reference type, otherwise evaluated as a static value.\n\n```go\nfunc(string) (string, error)\n```\n\n**Return value:**\n\n- `true` = reference type\n- `false` = value type\n\n**Default reference predicate:**\n\n\u003e The `$` symbol at the begging of the operand is used to predicate the reference type., E.g. `$State`, `$Country`.\n\n#### To\n\nA function used to transform the operand into the reference annotation stripped form. I.e. remove any annotation used to detect the reference type. E.g. \"$Reference\" =\u003e \"Reference\".\n\n```go\nfunc(string) string\n```\n\n\u003e **Default reference transform:**\n\u003e It removes the `$` symbol at the begging of the operand name.\n\n### Collection Serialize Options\n\n**Usage**\n\n```go\ncollectionSerializeOptions := illogical.WithCollectionSerializeOptions(illogical.CollectionSerializeOptions{\n\tEscapeCharacter  string\n})\n\ni := illogical.New(collectionSerializeOptions)\n```\n\n#### Escape Character\n\nCharter used to escape fist value within a collection, if the value contains operator value.\n\n**Example**\n- `[\"==\", 1, 1]` // interpreted as EQ expression\n- `[\"\\==\", 1, 1]` // interpreted as a collection\n\n```go\nEscapeCharacter  string\n```\n\n\u003e **Default escape character:**\n\u003e `\\`\n\n### Simplify Options\n\nOptions applied while an expression is being simplified.\n\n**Usage**\n\n```go\nreferenceSimplifyOptions := illogical.WithReferenceSimplifyOptions(illogical.SimplifyOptions{\n\tIgnoredPaths   []string\n\tIgnoredPathsRx []regexp.Regexp\n})\n\ni := illogical.New(referenceSimplifyOptions)\n```\n\n#### Ignored Paths\n\nReference paths which should be ignored while simplification is applied. Must be an exact match.\n\n```go\nIgnoredPaths   []string\n```\n\n#### Ignored Paths RegEx\n\nReference paths which should be ignored while simplification is applied. Matching regular expression patterns.\n\n```go\nIgnoredPathsRx []regexp.Regexp\n```\n\n### Operator Mapping\n\nMapping of the operators. The key is unique operator key, and the value is the key used to represent the given operator in the raw expression.\n\n**Usage**\n\n```go\nimport (\n\te \"github.com/spaceavocado/goillogical/evaluable\"\n)\n\noperatorMapping := illogical.WithOperatorMappingOptions(map[e.Kind]string{})\n\ni := illogical.New(operatorMapping)\n```\n\n**Default operator mapping:**\n\n```go\noperatorMapping := e.OperatorMapping{\n  // Comparison\n  e.Eq: \"==\",\n  e.Ne: \"!=\",\n  e.Gt: \"\u003e\",\n  e.Ge: \"\u003e=\",\n  e.Lt: \"\u003c\",\n  e.Le: \"\u003c=\",\n  e.In: \"IN\",\n  e.Nin: \"NOT IN\",\n  e.Prefix: \"PREFIX\",\n  e.Suffix: \"SUFFIX\",\n  e.Overlap:, \"OVERLAP\",\n  e.Nil: \"NONE\",\n  e.Present: \"PRESENT\",\n  // Logical\n  e.And: \"AND\",\n  e.Or: \"OR\",\n  e.Nor: \"NOR\",\n  e.Xor: \"XOR\",\n  e.Not: \"NOT\",\n}\n```\n\n### Multiple Options\nAll options could be used simultaneously.\n\n```go\noperatorMapping := illogical.WithOperatorMappingOptions(map[e.Kind]string{})\n\nreferenceSimplifyOptions := illogical.WithReferenceSimplifyOptions(illogical.SimplifyOptions{\n  IgnoredPaths:   []string{},\n  IgnoredPathsRx: []regexp.Regexp{},\n})\n\ni := illogical.New(operatorMapping, referenceSimplifyOptions)\n```\n\n---\n\n## Contributing\n\nSee [contributing.md](contributing.md).\n\n## License\n\nIllogical is released under the MIT license. See [license.txt](license.txt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspaceavocado%2Fgoillogical","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspaceavocado%2Fgoillogical","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspaceavocado%2Fgoillogical/lists"}