Starts with all of JSON, so needs "
, {
, [
, number literals, true
, false
, null
(and :
, ,
in context).
Metadata looks like data @ metadata
, and the "extended" types are all encoded with it. E.g. "<z85-encoded string>" @ { "ejson.type": "ejson.binary" }
.
MapFunc is all functions of zero, one, two, or three arguments. So probably you can write it with parens as in:
Add(Negate(1), Multiply(2, 3))
For QScript, we have SrcHole
, LeftSide
, and RightSide
which can probably be shortened to src
, left
, and right
(or perhaps ◯
, Ⓛ
, and Ⓡ
.
Probably this is left pretty flexible in the parser so you could have variables with arbitrary names, as long as they can be parsed as identifiers (possibly with backticks).
To improve readability, we probably want "infix" syntax for much of MapFunc, with the usual implications.
Questions:
- Stick to ASCII, all in on Unicode, or accept/produce either? As long as this is mainly for output and not so much for input, I lean towards prettier/more Unicode.
- Aim for some consistency with SQL²? I vote no! Instead make a strong statement that this is different.
- Aim for consistency with Scala? Haskell? Other PL? Mathematica?
Perhaps:
Normal | Infix | Precedence | Comment |
---|---|---|---|
Constant(x) |
x |
wraps embedded EJson | |
Now() |
now |
||
Negate(x) |
-x |
prefix | |
Not(x) |
not x , !x , ¬x |
prefix | |
MakeArray(x) |
[x] |
Is this syntactically distinct from an EJson array constant? | |
ConcatArrays(x, y) |
x ++ y |
? | |
ConcatArrays(MakeArray(x), MakeArray(y)) |
[x, y] |
See MakeArray |
|
Add(x, y) |
x + y |
? | |
Subtract(x, y) |
x - y |
? | |
Multiply(x, y) |
x * y |
? | |
Divide(x, y) |
x / y |
? | |
Modulo(x, y) |
x % y |
? | |
Power(x, y) |
x ^ y |
? | NB: we don't have Xor or bitwise ops |
Eq(x, y) |
x = y |
? | |
Neq(x, y) |
x ≠ y |
? | |
Lt(x, y) |
x < y |
? | |
Lte(x, y) |
x ≤ y |
? | Hard to read? |
Gt(x, y) |
x > y |
? | |
Gte(x, y) |
x ≥ y |
? | Hard to read? |
IfUndefined(x, y) |
x ?? y |
? | Better operator/symbol? |
And(x, y) |
x and y , x ∧ y |
? | |
Or(x, y) |
x or y , x ∨ y |
? | Reads as "v"? |
Within(x, y) |
x in y , x ∈ y |
? | |
MakeMap(x, y) |
{x: y} |
Is this syntactically distinct from an EJson object constant? | |
ConcatMaps(x, y) |
? | ||
ConcatMaps(MakeMap(x, y), MakeMap(z, t)) |
{x: y, z: t} |
See MakeMaps |
|
ProjectIndex(x, y) |
x[y] |
||
ProjectField(x, y) |
x{y} |
Ugly. | |
ProjectField(x, Constant(Str(<identifier>))) |
x.y |
? | |
Range(x, y) |
x..y |
? | |
Cond(x, y, z) |
if ... ? |
||
Guard(x, t, y, z) |
? |
That's about 50% of the constructors, but probably 80% or more of the usage.