1
1
mirror of https://github.com/github/semantic.git synced 2024-12-28 09:21:35 +03:00
semantic/prototype/UI/syntax.js
2015-10-27 11:10:38 -04:00

40 lines
823 B
JavaScript

function Syntax(json, continuation) {
if (json.indexed != null) {
this.indexed = json.indexed.map(continuation);
}
if (json.fixed != null) {
this.fixed = json.fixed.map(continuation);
}
if (json.keyed != null) {
this.keyed = (new Dictionary(json.keyed)).map(continuation);
}
if (json.leaf != null) {
this.leaf = json.leaf;
}
return this;
}
// forall a b. Syntax a -> (a -> b) -> Syntax b
Syntax.prototype.map = function(transform) {
if (this.leaf != null) {
return new Syntax({
leaf: this.leaf
}, transform);
}
if (this.indexed != null) {
return new Syntax({
indexed: this.indexed
}, transform);
}
if (this.fixed != null) {
return new Syntax({
fixed: this.fixed
}, transform);
}
if (this.keyed != null) {
return new Syntax({
keyed: this.keyed.values
}, transform);
}
}