simple-graph-query 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LANGUAGE.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
This library evaluates a single **expression** (the `parseExpr` grammar entry
|
|
9
9
|
point) against a data instance. The language is the expression fragment of
|
|
10
10
|
[Forge](https://forge-fm.org) (itself a dialect of Alloy), with a few
|
|
11
|
-
extensions (string literals, label access) and deliberate omissions.
|
|
11
|
+
extensions (string literals, label access, string comparison) and deliberate omissions.
|
|
12
12
|
|
|
13
13
|
**Everything is a set of tuples.** A sig name denotes the set of its atoms, a
|
|
14
14
|
relation name the set of its tuples, and a scalar (one atom, one number, one
|
|
@@ -101,12 +101,32 @@ Called with square brackets, e.g. `add[1, 2]`.
|
|
|
101
101
|
| Builtins | Arity | Notes |
|
|
102
102
|
|----------|-------|-------|
|
|
103
103
|
| `add`, `subtract`, `multiply`, `divide`, `remainder` | 2 | Integer/real arithmetic. `divide` is real division. |
|
|
104
|
+
| `lexCompare` | 2 | String comparison (SGQ extension), returning -1, 0, or 1. |
|
|
104
105
|
| `abs`, `sign`, `floor`, `ceil` | 1 | |
|
|
105
106
|
| `min`, `max`, `sum` | set | Aggregate over a set; numeric strings resolve to numbers. `sum` also has a quantifier form `sum x: S \| intExpr`. |
|
|
106
107
|
|
|
107
108
|
Builtin names are **not** reserved words: a data instance that names an
|
|
108
109
|
entity `add` shadows the builtin (see issue #59).
|
|
109
110
|
|
|
111
|
+
### String comparison
|
|
112
|
+
|
|
113
|
+
`lexCompare[a, b]` returns -1 if `a` precedes `b`, 0 if they are equal,
|
|
114
|
+
and 1 if `a` follows `b`. Each argument must be a string or a singleton
|
|
115
|
+
unary string relation; empty relations, multiple values, higher-arity tuples,
|
|
116
|
+
numbers, and booleans are rejected. No implicit conversion or label lookup occurs.
|
|
117
|
+
|
|
118
|
+
Ordering uses JavaScript's `<` and `>`: case-sensitive, locale-independent
|
|
119
|
+
lexicographic comparison of UTF-16 code units, with no Unicode normalization.
|
|
120
|
+
A proper prefix comes first (`""` precedes `"a"`, which precedes `"aa"`);
|
|
121
|
+
numeric-looking strings remain strings (`"10"` precedes `"2"`).
|
|
122
|
+
Use label extraction explicitly when ordering atoms by their displayed labels:
|
|
123
|
+
|
|
124
|
+
`{a, b: Person | lexCompare[@:a, @:b] < 0}`
|
|
125
|
+
|
|
126
|
+
Atom IDs are also represented as strings, so `lexCompare[a, b]` compares IDs
|
|
127
|
+
when given atoms. Distinct atoms with identical labels compare equal after
|
|
128
|
+
label extraction. The infix ordering operators remain numeric.
|
|
129
|
+
|
|
110
130
|
## Grammar
|
|
111
131
|
|
|
112
132
|
The expression grammar, with token literals substituted in. Pattern tokens
|
package/README.md
CHANGED
|
@@ -43,6 +43,23 @@ stands for itself.
|
|
|
43
43
|
There is no implicit conversion: `"12" = 12` and `"true" = true` are both false.
|
|
44
44
|
Use `@num:` / `@bool:` to convert explicitly.
|
|
45
45
|
|
|
46
|
+
### Lexicographic comparison
|
|
47
|
+
|
|
48
|
+
`lexCompare[a, b]` returns `-1`, `0`, or `1` for strings that precede, equal,
|
|
49
|
+
or follow one another, using JavaScript's case-sensitive UTF-16 string ordering
|
|
50
|
+
(`a < b` / `a > b`). It has no locale rules, Unicode normalization, or numeric
|
|
51
|
+
conversion: `"10"` precedes `"2"`, and a proper prefix comes first.
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
lexCompare["apple", "banana"] < 0
|
|
55
|
+
{a, b: Person | lexCompare[@:a, @:b] < 0}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Each argument must be a string or a singleton unary string relation. Empty or
|
|
59
|
+
multi-value relations, higher-arity tuples, numbers, and booleans are rejected.
|
|
60
|
+
Atom IDs are represented as strings too; use `@:` explicitly to compare labels.
|
|
61
|
+
The infix `<`, `>`, `<=`, and `>=` operators continue to require numbers.
|
|
62
|
+
|
|
46
63
|
### Embedding in YAML
|
|
47
64
|
|
|
48
65
|
`@` is a reserved indicator in YAML, so an expression beginning with `@:` cannot
|
|
@@ -5,6 +5,8 @@ import { IDataInstance } from "./types";
|
|
|
5
5
|
export type SingleValue = string | number | boolean;
|
|
6
6
|
export type Tuple = SingleValue[];
|
|
7
7
|
export type EvalResult = SingleValue | Tuple[];
|
|
8
|
+
/** JavaScript's case-sensitive, locale-independent UTF-16 string ordering. */
|
|
9
|
+
export declare function compareStrings(a: string, b: string): -1 | 0 | 1;
|
|
8
10
|
export declare function areTupleArraysEqual(a: Tuple[], b: Tuple[]): boolean;
|
|
9
11
|
export declare const SUPPORTED_BUILTINS: string[];
|
|
10
12
|
/**
|