# Logical Parser (/placeholders/parsers/logical)



The Logical Parser allows you to create conditional logic within placeholders by evaluating multiple boolean expressions. It supports two modes: **OR logic** (returns true if any expression matches) and **AND logic** (returns true only if all expressions match).

## Syntax [#syntax]

```
{parser(expression|expression|...):true_message|false_message}
```

## Structure [#structure]

* **Expressions**: Multiple boolean conditions separated by pipes (`|`)
* **Payload**: A message split by a pipe (`|`) containing the true/false responses
* The text before the first pipe in the payload is returned when conditions are met
* The text after the first pipe is returned when conditions are not met

## Modes [#modes]

### OR Mode (Any Match) [#or-mode-any-match]

Returns the true message if **any** of the expressions evaluate to `true`.

**Aliases:**

* `any` (primary)
* `or`
* `union`

**Syntax:**

```
{any(expression|expression|...):true_message|false_message}
```

**How it works:**

1. Evaluates each expression separated by `|`
2. If **any** expression is `true`, returns the text before the first pipe in the payload
3. If **all** expressions are `false`, returns the text after the first pipe in the payload

**Examples:**

```
{any({args}==hi|{args}==hello|{args}==hey):Hello {user}!|How rude.}
```

* If `{args}` is `hi`, `hello`, or `hey` → Returns: `Hello Mr. Priyansh#2063!`
* If `{args}` is anything else → Returns: `How rude.`

```
{any({a}==1|{b}==2):One or two matched.|No match.}
```

* If `{a}==1` is true OR `{b}==2` is true → Returns: `One or two matched.`
* If both are false → Returns: `No match.`

### AND Mode (All Match) [#and-mode-all-match]

Returns the true message only if **all** of the expressions evaluate to `true`.

**Aliases:**

* `all` (primary)
* `and`
* `intersection`

**Syntax:**

```
{all(expression|expression|...):true_message|false_message}
```

**How it works:**

1. Evaluates each expression separated by `|`
2. If **all** expressions are `true`, returns the text before the first pipe in the payload
3. If **any** expression is `false`, returns the text after the first pipe in the payload

**Examples:**

```
{all({args}>=100|{args}<=1000):You picked {args}.|You must provide a number between 100 and 1000.}
```

* If `{args}` is `52` → Returns: `You must provide a number between 100 and 1000.` (fails first condition)
* If `{args}` is `282` → Returns: `You picked 282.` (both conditions pass)
* If `{args}` is `1500` → Returns: `You must provide a number between 100 and 1000.` (fails second condition)

```
{all({x}==a|{y}==b):Both matched.|One or more did not match.}
```

* If `{x}==a` is true AND `{y}==b` is true → Returns: `Both matched.`
* If either condition is false → Returns: `One or more did not match.`

## Notes [#notes]

* The payload must contain a pipe (`|`) to separate true/false messages
* In OR mode, expressions are evaluated left to right; evaluation may stop once any expression is true (short-circuit behavior)
* In AND mode, all expressions are evaluated; every expression must be true for the parser to return the first message

## When to Use Which Mode [#when-to-use-which-mode]

| Scenario                       | Use This Mode   | Example Use Case                                |
| ------------------------------ | --------------- | ----------------------------------------------- |
| Match any of multiple values   | **OR** (`any`)  | Greeting detection: `hi`, `hello`, or `hey`     |
| Require all conditions to pass | **AND** (`all`) | Validation: number must be between 100 and 1000 |
| Optional conditions            | **OR** (`any`)  | Check if user has any of several roles          |
| Mandatory requirements         | **AND** (`all`) | Verify user has all required permissions        |

**Quick Reference:**

* **OR mode** (`any`): "If **any** of these are true, do this"
* **AND mode** (`all`): "If **all** of these are true, do this"
