1
1
mirror of https://github.com/github/semantic.git synced 2024-12-01 09:15:01 +03:00
semantic/prototype/UI/syntax.js

40 lines
823 B
JavaScript
Raw Normal View History

2015-10-27 18:10:38 +03:00
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);
}
}