Open chharvey opened 4 years ago
Update: Only punning will be implemented for records, with a slight change in syntax. Punning for mappings and augmentation for all literals will not be developed.
let c: int = 42;
let rec: [c: int] = [
c$,
% equivalent to:
% c= c,
];
[a$ b= 42]; % sugar for `[a= a, b= 42]`
This completely supercedes the previous.
Property ::=
| Word "=" Expression
+ | IDENTIFIER "$"
;
Decorate(Property ::= Word "=" Expression) -> SemanticProperty
:= (SemanticProperty
Decorate(Word)
Decorate(Expression)
);
+Decorate(Property ::= IDENTIFIER "$") -> SemanticProperty
+ := (SemanticProperty
+ (SemanticKey[id=TokenWorth(IDENTIFIER)])
+ (SemanticVariable[id=TokenWorth(IDENTIFIER)])
+ );
In record literals, allow key punning with augment and update operators. In mapping literals, allow antecedent punning. Dependent on #15 and #21.
Descripiton
Record Augment Assignment
In record literals, augmented assignment operators may be used as the delimiter of a key-value pair.
This sets
rec.a
to42 / 3
, but does not modify the unbound variablea
, which still points to42
. Whitespace may be inserted before the operator symbol to improve readability.In record literals, update operators may be used.
This sets
rec.b
to42 + 1
, but does not modify the unbound variableb
, which still points to42
.Record Punning
In a record literal, using the symbol
$
as a property value is equivalent to repeating the key. This is only valid when there exists an unbound variable or parameter whose identifier is exactly the same as the property key.This sets
rec.c
to42
.Augment operators may also be used with punning:
This sets
rec.d
to42 * 42
, but does not modify the unbound variabled
, which still points to42
.The complete list of operators:
Mapping Punning
In a mapping literal, using the symbol
$
as the consequent of a case is equivalent to repeating the antecedent.If a case has multiple antecedents, it deconstructs each of them.
The complete list of operators:
(where
‹x›
and‹y›
are metavariables representing expressions)Specification
Syntactic Grammar
Decorate