From 3ffbe622543864fbefe9910c7536f8f7657d6e49 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 16 Jan 2026 12:06:26 +0000 Subject: [PATCH 1/4] Initial plan From c16d46f005f5561e9d1092c27340821c5c807104 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 16 Jan 2026 12:09:57 +0000 Subject: [PATCH 2/4] docs: document usage of the concat operator | Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com> --- docs/syntax.md | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/docs/syntax.md b/docs/syntax.md index f3c113b..09099b5 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -12,7 +12,7 @@ The parser accepts a pretty basic grammar. It's similar to normal JavaScript exp | ^ | Right | Exponentiation | | +, -, not, sqrt, etc. | Right | Unary prefix operators (see below for the full list) | | \*, /, % | Left | Multiplication, division, remainder | -| +, -, \|\| | Left | Addition, subtraction, array/list concatenation | +| +, -, \| | Left | Addition, subtraction, array/string concatenation | | ==, !=, >=, <=, >, <, in | Left | Equals, not equals, etc. "in" means "is the left operand included in the right array operand?" | | and | Left | Logical AND | | or | Left | Logical OR | @@ -30,6 +30,35 @@ const parser = new Parser({ // Now parser supports 'x in array' and 'y = 2*x' expressions ``` +## Concatenation Operator + +The `|` (pipe) operator concatenates arrays or strings. + +| Operator | Description | +|:-------- |:----------- | +| a \| b | Concatenates arrays or strings. Both operands must be of the same type. | + +### Array Concatenation + +```js +const parser = new Parser(); + +parser.evaluate('[1, 2] | [3, 4]'); // [1, 2, 3, 4] +parser.evaluate('[1] | [2] | [3]'); // [1, 2, 3] +parser.evaluate('["a", "b"] | ["c", "d"]'); // ["a", "b", "c", "d"] +``` + +### String Concatenation + +```js +const parser = new Parser(); + +parser.evaluate('"hello" | " " | "world"'); // "hello world" +parser.evaluate('"a" | "b" | "c"'); // "abc" +``` + +> **Note:** Both operands must be of the same type (both arrays or both strings). Mixing types will return `undefined`. + ## Unary Operators The parser has several built-in "functions" that are actually unary operators. The primary difference between these and functions are that they can only accept exactly one argument, and parentheses are optional. With parentheses, they have the same precedence as function calls, but without parentheses, they keep their normal precedence (just below `^`). For example, `sin(x)^2` is equivalent to `(sin x)^2`, and `sin x^2` is equivalent to `sin(x^2)`. From 39b302a6bb0ee3eb249ea8664f70ab18629e4ebc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 16 Jan 2026 12:29:50 +0000 Subject: [PATCH 3/4] docs: clarify concat operator behavior for arrays and strings Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com> --- docs/syntax.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/syntax.md b/docs/syntax.md index 09099b5..567fab6 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -32,14 +32,19 @@ const parser = new Parser({ ## Concatenation Operator -The `|` (pipe) operator concatenates arrays or strings. +The `|` (pipe) operator concatenates arrays or strings: +- If both operands are arrays, they are concatenated as arrays +- If both operands are strings, they are concatenated as strings +- If operands are of different types, the result is `undefined` | Operator | Description | |:-------- |:----------- | -| a \| b | Concatenates arrays or strings. Both operands must be of the same type. | +| a \| b | Concatenates `a` and `b`. Both operands must be arrays or both must be strings. | ### Array Concatenation +When both operands are arrays, the `|` operator returns a new array containing all elements from both arrays: + ```js const parser = new Parser(); @@ -50,6 +55,8 @@ parser.evaluate('["a", "b"] | ["c", "d"]'); // ["a", "b", "c", "d"] ### String Concatenation +When both operands are strings, the `|` operator returns a new string combining both: + ```js const parser = new Parser(); @@ -57,7 +64,7 @@ parser.evaluate('"hello" | " " | "world"'); // "hello world" parser.evaluate('"a" | "b" | "c"'); // "abc" ``` -> **Note:** Both operands must be of the same type (both arrays or both strings). Mixing types will return `undefined`. +> **Note:** Mixing types (e.g., array with string, or number with string) will return `undefined`. ## Unary Operators From f416209fd2a1efa84dd40bba3562256887a54e9e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 16 Jan 2026 12:30:36 +0000 Subject: [PATCH 4/4] docs: improve table description and note consistency Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com> --- docs/syntax.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/syntax.md b/docs/syntax.md index 567fab6..cb00ae7 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -39,7 +39,7 @@ The `|` (pipe) operator concatenates arrays or strings: | Operator | Description | |:-------- |:----------- | -| a \| b | Concatenates `a` and `b`. Both operands must be arrays or both must be strings. | +| a \| b | Concatenates `a` and `b` if both are arrays or both are strings; otherwise returns `undefined`. | ### Array Concatenation @@ -64,7 +64,7 @@ parser.evaluate('"hello" | " " | "world"'); // "hello world" parser.evaluate('"a" | "b" | "c"'); // "abc" ``` -> **Note:** Mixing types (e.g., array with string, or number with string) will return `undefined`. +> **Note:** Mixing types (e.g., an array with a string) will return `undefined`. ## Unary Operators