import "./cljs_env.js";
goog.provide('clojure_eval.node');
var module$node_modules$$lezer$common$dist$index_cjs=shadow.js.require("module$node_modules$$lezer$common$dist$index_cjs", {});
var module$node_modules$$codemirror$language$dist$index_cjs=shadow.js.require("module$node_modules$$codemirror$language$dist$index_cjs", {});
var module$node_modules$$nextjournal$lezer_clojure$dist$index_cjs=shadow.js.require("module$node_modules$$nextjournal$lezer_clojure$dist$index_cjs", {});
clojure_eval.node.coll_prop = module$node_modules$$nextjournal$lezer_clojure$dist$index_cjs.props.coll;
clojure_eval.node.prefix_coll_prop = module$node_modules$$nextjournal$lezer_clojure$dist$index_cjs.props.prefixColl;
clojure_eval.node.prefix_edge_prop = module$node_modules$$nextjournal$lezer_clojure$dist$index_cjs.props.prefixEdge;
clojure_eval.node.prefix_container_prop = module$node_modules$$nextjournal$lezer_clojure$dist$index_cjs.props.prefixContainer;
clojure_eval.node.start_edge_prop = module$node_modules$$lezer$common$dist$index_cjs.NodeProp.closedBy;
clojure_eval.node.end_edge_prop = module$node_modules$$lezer$common$dist$index_cjs.NodeProp.openedBy;
clojure_eval.node.same_edge_prop = module$node_modules$$nextjournal$lezer_clojure$dist$index_cjs.props.sameEdge;
clojure_eval.node.node_prop = (function clojure_eval$node$node_prop(prop_name){
var G__55221 = prop_name;
switch (G__55221) {
case "prefixColl":
return clojure_eval.node.prefix_coll_prop;

break;
case "coll":
return clojure_eval.node.coll_prop;

break;
case "prefixEdge":
return clojure_eval.node.prefix_edge_prop;

break;
case "prefixContainer":
return clojure_eval.node.prefix_container_prop;

break;
case "sameEdge":
return clojure_eval.node.same_edge_prop;

break;
default:
throw (new Error(["No matching clause: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(G__55221)].join('')));

}
});
clojure_eval.node.type = (function clojure_eval$node$type(node){
return node.type;
});
clojure_eval.node.start = (function clojure_eval$node$start(node){
if(cljs.core.truth_(node.from)){
} else {
throw (new Error("Assert failed: (.-from node)"));
}

return node.from;
});
clojure_eval.node.end = (function clojure_eval$node$end(node){
if(cljs.core.truth_(node.to)){
} else {
throw (new Error("Assert failed: (.-to node)"));
}

return node.to;
});
clojure_eval.node.up = (function clojure_eval$node$up(node){
return node.parent;
});
clojure_eval.node.down = (function clojure_eval$node$down(node){
if((!(cljs.core.fn_QMARK_(node.lastChild)))){
} else {
throw (new Error("Assert failed: (not (fn? (.-lastChild node)))"));
}

return node.firstChild;
});
clojure_eval.node.down_last = (function clojure_eval$node$down_last(node){
if((!(cljs.core.fn_QMARK_(node.lastChild)))){
} else {
throw (new Error("Assert failed: (not (fn? (.-lastChild node)))"));
}

return node.lastChild;
});
clojure_eval.node.depth = (function clojure_eval$node$depth(node){
var node__$1 = node;
var i = (0);
while(true){
var temp__5755__auto__ = clojure_eval.node.up(node__$1);
if((temp__5755__auto__ == null)){
return i;
} else {
var parent = temp__5755__auto__;
var G__55334 = parent;
var G__55335 = (i + (1));
node__$1 = G__55334;
i = G__55335;
continue;
}
break;
}
});
clojure_eval.node.left = (function clojure_eval$node$left(node){
return clojure_eval.node.up(node).childBefore(clojure_eval.node.start(node));
});
clojure_eval.node.lefts = (function clojure_eval$node$lefts(node){
return cljs.core.take_while.cljs$core$IFn$_invoke$arity$2(cljs.core.identity,cljs.core.iterate(clojure_eval.node.left,clojure_eval.node.left(node)));
});
clojure_eval.node.right = (function clojure_eval$node$right(node){
return clojure_eval.node.up(node).childAfter(clojure_eval.node.end(node));
});
clojure_eval.node.rights = (function clojure_eval$node$rights(node){
return cljs.core.take_while.cljs$core$IFn$_invoke$arity$2(cljs.core.identity,cljs.core.iterate(clojure_eval.node.right,clojure_eval.node.right(node)));
});
clojure_eval.node.coll_type_QMARK_ = (function clojure_eval$node$coll_type_QMARK_(node_type){
return node_type.prop(clojure_eval.node.coll_prop);
});
clojure_eval.node.prefix_type_QMARK_ = (function clojure_eval$node$prefix_type_QMARK_(node_type){
return node_type.prop(clojure_eval.node.prefix_coll_prop);
});
clojure_eval.node.prefix_edge_type_QMARK_ = (function clojure_eval$node$prefix_edge_type_QMARK_(node_type){
return node_type.prop(clojure_eval.node.prefix_edge_prop);
});
clojure_eval.node.prefix_container_type_QMARK_ = (function clojure_eval$node$prefix_container_type_QMARK_(node_type){
return node_type.prop(clojure_eval.node.prefix_container_prop);
});
clojure_eval.node.same_edge_type_QMARK_ = (function clojure_eval$node$same_edge_type_QMARK_(node_type){
return node_type.prop(clojure_eval.node.same_edge_prop);
});
clojure_eval.node.start_edge_type_QMARK_ = (function clojure_eval$node$start_edge_type_QMARK_(node_type){
return node_type.prop(clojure_eval.node.start_edge_prop);
});
clojure_eval.node.end_edge_type_QMARK_ = (function clojure_eval$node$end_edge_type_QMARK_(node_type){
return node_type.prop(clojure_eval.node.end_edge_prop);
});
clojure_eval.node.top_type_QMARK_ = (function clojure_eval$node$top_type_QMARK_(node_type){
return node_type.isTop;
});
clojure_eval.node.error_type_QMARK_ = (function clojure_eval$node$error_type_QMARK_(node_type){
return node_type.isError;
});
clojure_eval.node.prefix_QMARK_ = (function clojure_eval$node$prefix_QMARK_(n){
return clojure_eval.node.prefix_type_QMARK_(clojure_eval.node.type(n));
});
clojure_eval.node.prefix_edge_QMARK_ = (function clojure_eval$node$prefix_edge_QMARK_(n){
return clojure_eval.node.prefix_edge_type_QMARK_(clojure_eval.node.type(n));
});
clojure_eval.node.prefix_container_QMARK_ = (function clojure_eval$node$prefix_container_QMARK_(n){
return clojure_eval.node.prefix_container_type_QMARK_(clojure_eval.node.type(n));
});
clojure_eval.node.same_edge_QMARK_ = (function clojure_eval$node$same_edge_QMARK_(n){
return clojure_eval.node.same_edge_type_QMARK_(clojure_eval.node.type(n));
});
clojure_eval.node.start_edge_QMARK_ = (function clojure_eval$node$start_edge_QMARK_(n){
return clojure_eval.node.start_edge_type_QMARK_(clojure_eval.node.type(n));
});
clojure_eval.node.end_edge_QMARK_ = (function clojure_eval$node$end_edge_QMARK_(n){
return clojure_eval.node.end_edge_type_QMARK_(clojure_eval.node.type(n));
});
clojure_eval.node.left_edge_type_QMARK_ = (function clojure_eval$node$left_edge_type_QMARK_(t){
return ((clojure_eval.node.start_edge_type_QMARK_(t)) || (((clojure_eval.node.same_edge_type_QMARK_(t)) || (clojure_eval.node.prefix_edge_type_QMARK_(t)))));
});
clojure_eval.node.left_edge_QMARK_ = (function clojure_eval$node$left_edge_QMARK_(n){
return clojure_eval.node.left_edge_type_QMARK_(clojure_eval.node.type(n));
});
clojure_eval.node.right_edge_type_QMARK_ = (function clojure_eval$node$right_edge_type_QMARK_(t){
return ((clojure_eval.node.end_edge_type_QMARK_(t)) || (clojure_eval.node.same_edge_type_QMARK_(t)));
});
clojure_eval.node.right_edge_QMARK_ = (function clojure_eval$node$right_edge_QMARK_(n){
return clojure_eval.node.right_edge_type_QMARK_(clojure_eval.node.type(n));
});
clojure_eval.node.edge_QMARK_ = (function clojure_eval$node$edge_QMARK_(n){
var t = clojure_eval.node.type(n);
return ((clojure_eval.node.start_edge_type_QMARK_(t)) || (((clojure_eval.node.end_edge_type_QMARK_(t)) || (((clojure_eval.node.same_edge_type_QMARK_(t)) || (clojure_eval.node.prefix_type_QMARK_(t)))))));
});
clojure_eval.node.closed_by = (function clojure_eval$node$closed_by(n){
var G__55235 = clojure_eval.node.type(n).prop(module$node_modules$$lezer$common$dist$index_cjs.NodeProp.closedBy);
if((G__55235 == null)){
return null;
} else {
return (G__55235[(0)]);
}
});
clojure_eval.node.opened_by = (function clojure_eval$node$opened_by(n){
var G__55236 = clojure_eval.node.type(n).prop(module$node_modules$$lezer$common$dist$index_cjs.NodeProp.openedBy);
if((G__55236 == null)){
return null;
} else {
return (G__55236[(0)]);
}
});
clojure_eval.node.name = (function clojure_eval$node$name(node){
return node.name;
});
clojure_eval.node.error_QMARK_ = (function clojure_eval$node$error_QMARK_(node){
return clojure_eval.node.error_type_QMARK_(node);
});
clojure_eval.node.top_QMARK_ = (function clojure_eval$node$top_QMARK_(node){
return clojure_eval.node.top_type_QMARK_(clojure_eval.node.type(node));
});
clojure_eval.node.program_QMARK_ = (function clojure_eval$node$program_QMARK_(node){
return ("Program" === clojure_eval.node.name(node));
});
clojure_eval.node.string_QMARK_ = (function clojure_eval$node$string_QMARK_(node){
return ("String" === clojure_eval.node.name(node));
});
clojure_eval.node.regexp_QMARK_ = (function clojure_eval$node$regexp_QMARK_(node){
return ("RegExp" === clojure_eval.node.name(node));
});
clojure_eval.node.line_comment_QMARK_ = (function clojure_eval$node$line_comment_QMARK_(node){
return ("LineComment" === clojure_eval.node.name(node));
});
clojure_eval.node.discard_QMARK_ = (function clojure_eval$node$discard_QMARK_(node){
return ("Discard" === clojure_eval.node.name(node));
});
clojure_eval.node.coll_QMARK_ = (function clojure_eval$node$coll_QMARK_(node){
return clojure_eval.node.coll_type_QMARK_(clojure_eval.node.type(node));
});
clojure_eval.node.terminal_type_QMARK_ = (function clojure_eval$node$terminal_type_QMARK_(node_type){
if(clojure_eval.node.top_type_QMARK_(node_type)){
return false;
} else {
if(cljs.core.truth_(node_type.prop(clojure_eval.node.prefix_coll_prop))){
return false;
} else {
if(cljs.core.truth_(node_type.prop(clojure_eval.node.coll_prop))){
return false;
} else {
if(("Meta" === clojure_eval.node.name(node_type))){
return false;
} else {
if(("TaggedLiteral" === clojure_eval.node.name(node_type))){
return false;
} else {
if(("ConstructorCall" === clojure_eval.node.name(node_type))){
return false;
} else {
return true;

}
}
}
}
}
}
});
clojure_eval.node.balanced_QMARK_ = (function clojure_eval$node$balanced_QMARK_(p__55238){
var map__55239 = p__55238;
var map__55239__$1 = (((((!((map__55239 == null))))?(((((map__55239.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__55239.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.cljs$core$IFn$_invoke$arity$2(cljs.core.hash_map,map__55239):map__55239);
var node = map__55239__$1;
var firstChild = (function (){var obj55241 = map__55239__$1;
var k55242 = "firstChild";
if((function (){var obj55243 = obj55241;
return (((!((obj55243 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k55242,obj55243)));
})()){
return (obj55241[k55242]);
} else {
return undefined;
}
})();
var lastChild = (function (){var obj55244 = map__55239__$1;
var k55245 = "lastChild";
if((function (){var obj55246 = obj55244;
return (((!((obj55246 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k55245,obj55246)));
})()){
return (obj55244[k55245]);
} else {
return undefined;
}
})();
var temp__5751__auto__ = clojure_eval.node.closed_by(firstChild);
if(cljs.core.truth_(temp__5751__auto__)){
var closing = temp__5751__auto__;
return ((cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(closing,clojure_eval.node.name(lastChild))) && (cljs.core.not_EQ_.cljs$core$IFn$_invoke$arity$2(clojure_eval.node.end(firstChild),clojure_eval.node.end(lastChild))));
} else {
return true;
}
});
clojure_eval.node.ancestors = (function clojure_eval$node$ancestors(node){
var temp__5757__auto__ = clojure_eval.node.up(node);
if((temp__5757__auto__ == null)){
return null;
} else {
var parent = temp__5757__auto__;
return cljs.core.cons(parent,(new cljs.core.LazySeq(null,(function (){
return (clojure_eval.node.ancestors.cljs$core$IFn$_invoke$arity$1 ? clojure_eval.node.ancestors.cljs$core$IFn$_invoke$arity$1(parent) : clojure_eval.node.ancestors.call(null,parent));
}),null,null)));
}
});
clojure_eval.node.closest = (function clojure_eval$node$closest(node,pred){
if(cljs.core.truth_((pred.cljs$core$IFn$_invoke$arity$1 ? pred.cljs$core$IFn$_invoke$arity$1(node) : pred.call(null,node)))){
return node;
} else {
return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3((function (_,x){
if(cljs.core.truth_((pred.cljs$core$IFn$_invoke$arity$1 ? pred.cljs$core$IFn$_invoke$arity$1(x) : pred.call(null,x)))){
return cljs.core.reduced(x);
} else {
return null;
}
}),null,clojure_eval.node.ancestors(node));
}
});
clojure_eval.node.highest = (function clojure_eval$node$highest(node,pred){
return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3((function (found,x){
if(cljs.core.truth_((pred.cljs$core$IFn$_invoke$arity$1 ? pred.cljs$core$IFn$_invoke$arity$1(x) : pred.call(null,x)))){
return x;
} else {
return cljs.core.reduced(found);
}
}),null,cljs.core.cons(node,clojure_eval.node.ancestors(node)));
});
clojure_eval.node.children = (function clojure_eval$node$children(var_args){
var G__55248 = arguments.length;
switch (G__55248) {
case 3:
return clojure_eval.node.children.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)]));

break;
case 1:
return clojure_eval.node.children.cljs$core$IFn$_invoke$arity$1((arguments[(0)]));

break;
default:
throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join('')));

}
});

(clojure_eval.node.children.cljs$core$IFn$_invoke$arity$3 = (function (parent,from,dir){
var temp__5757__auto__ = (function (){var G__55249 = dir;
switch (G__55249) {
case (1):
return parent.childAfter(from);

break;
case (-1):
return parent.childBefore(from);

break;
default:
throw (new Error(["No matching clause: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(G__55249)].join('')));

}
})();
if((temp__5757__auto__ == null)){
return null;
} else {
var child = temp__5757__auto__;
return cljs.core.cons(child,(new cljs.core.LazySeq(null,(function (){
return clojure_eval.node.children.cljs$core$IFn$_invoke$arity$3(parent,(function (){var G__55250 = dir;
switch (G__55250) {
case (1):
return clojure_eval.node.end(child);

break;
case (-1):
return clojure_eval.node.start(child);

break;
default:
throw (new Error(["No matching clause: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(G__55250)].join('')));

}
})(),dir);
}),null,null)));
}
}));

(clojure_eval.node.children.cljs$core$IFn$_invoke$arity$1 = (function (subtree){
return clojure_eval.node.children.cljs$core$IFn$_invoke$arity$3(subtree,clojure_eval.node.start(subtree),(1));
}));

(clojure_eval.node.children.cljs$lang$maxFixedArity = 3);

clojure_eval.node.eq_QMARK_ = (function clojure_eval$node$eq_QMARK_(x,y){
return (((clojure_eval.node.start(x) === clojure_eval.node.start(y))) && ((((clojure_eval.node.end(x) === clojure_eval.node.end(y))) && ((clojure_eval.node.depth(x) === clojure_eval.node.depth(y))))));
});
/**
 * Node only contains whitespace
 */
clojure_eval.node.empty_QMARK_ = (function clojure_eval$node$empty_QMARK_(node){
var type_name = clojure_eval.node.name(node);
if(cljs.core.truth_(clojure_eval.node.coll_QMARK_(node))){
return clojure_eval.node.eq_QMARK_(clojure_eval.node.right(clojure_eval.node.down(node)),clojure_eval.node.down_last(node));
} else {
if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2("String",type_name)){
return (clojure_eval.node.end(clojure_eval.node.down(node)) === clojure_eval.node.start(clojure_eval.node.down_last(node)));
} else {
return false;

}
}
});
clojure_eval.node.from_to = (function clojure_eval$node$from_to(var_args){
var G__55252 = arguments.length;
switch (G__55252) {
case 2:
return clojure_eval.node.from_to.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));

break;
case 1:
return clojure_eval.node.from_to.cljs$core$IFn$_invoke$arity$1((arguments[(0)]));

break;
default:
throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join('')));

}
});

(clojure_eval.node.from_to.cljs$core$IFn$_invoke$arity$2 = (function (from,to){
return ({"from": from, "to": to});
}));

(clojure_eval.node.from_to.cljs$core$IFn$_invoke$arity$1 = (function (node){
return clojure_eval.node.from_to.cljs$core$IFn$_invoke$arity$2(clojure_eval.node.start(node),clojure_eval.node.end(node));
}));

(clojure_eval.node.from_to.cljs$lang$maxFixedArity = 2);

clojure_eval.node.range = (function clojure_eval$node$range(node){
return clojure_eval.selections.range.cljs$core$IFn$_invoke$arity$2(clojure_eval.node.start(node),clojure_eval.node.end(node));
});
clojure_eval.node.string = (function clojure_eval$node$string(var_args){
var G__55254 = arguments.length;
switch (G__55254) {
case 2:
return clojure_eval.node.string.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));

break;
case 3:
return clojure_eval.node.string.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)]));

break;
default:
throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join('')));

}
});

(clojure_eval.node.string.cljs$core$IFn$_invoke$arity$2 = (function (state,node){
return clojure_eval.node.string.cljs$core$IFn$_invoke$arity$3(state,clojure_eval.node.start(node),clojure_eval.node.end(node));
}));

(clojure_eval.node.string.cljs$core$IFn$_invoke$arity$3 = (function (state,from,to){
return state.doc.sliceString(from,to,"\n");
}));

(clojure_eval.node.string.cljs$lang$maxFixedArity = 3);

clojure_eval.node.ancestor_QMARK_ = (function clojure_eval$node$ancestor_QMARK_(parent,child){
return cljs.core.boolean$((((clojure_eval.node.start(parent) <= clojure_eval.node.start(child))) && ((((clojure_eval.node.end(parent) >= clojure_eval.node.end(child))) && ((clojure_eval.node.depth(parent) < clojure_eval.node.depth(child)))))));
});
/**
 * Returns next loc moving toward `to-path`, skipping children
 */
clojure_eval.node.move_toward = (function clojure_eval$node$move_toward(node,to_node){
if(clojure_eval.node.eq_QMARK_(node,to_node)){
return null;
} else {
var G__55255 = cljs.core.compare(clojure_eval.node.start(to_node),clojure_eval.node.start(node));
switch (G__55255) {
case (0):
if(clojure_eval.node.ancestor_QMARK_(to_node,node)){
return clojure_eval.node.up(node);
} else {
if(clojure_eval.node.ancestor_QMARK_(node,to_node)){
return clojure_eval.node.down(node);
} else {
return null;
}
}

break;
case (-1):
if(clojure_eval.node.ancestor_QMARK_(node,to_node)){
return clojure_eval.node.down_last(node);
} else {
var or__4223__auto__ = clojure_eval.node.left(node);
if(cljs.core.truth_(or__4223__auto__)){
return or__4223__auto__;
} else {
return clojure_eval.node.up(node);
}
}

break;
case (1):
if(clojure_eval.node.ancestor_QMARK_(node,to_node)){
return clojure_eval.node.down(node);
} else {
var or__4223__auto__ = clojure_eval.node.right(node);
if(cljs.core.truth_(or__4223__auto__)){
return or__4223__auto__;
} else {
return clojure_eval.node.up(node);
}
}

break;
default:
throw (new Error(["No matching clause: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(G__55255)].join('')));

}
}
});
clojure_eval.node.nodes_between = (function clojure_eval$node$nodes_between(node,to_node){
return cljs.core.take_while.cljs$core$IFn$_invoke$arity$2(cljs.core.identity,cljs.core.iterate((function (p1__55256_SHARP_){
return clojure_eval.node.move_toward(p1__55256_SHARP_,to_node);
}),node));
});
clojure_eval.node.require_balance_QMARK_ = (function clojure_eval$node$require_balance_QMARK_(node){
var or__4223__auto__ = clojure_eval.node.coll_QMARK_(node);
if(cljs.core.truth_(or__4223__auto__)){
return or__4223__auto__;
} else {
return ((clojure_eval.node.string_QMARK_(node)) || (clojure_eval.node.regexp_QMARK_(node)));
}
});
/**
 * Returns a (Tree https://lezer.codemirror.net/docs/ref/#common.Tree) for editor state
 *   or the SyntaxNode at pos.
 * 
 *   If pos is given and we're using Clojure language support embedded in other languages (e.g. markdown)
 *   enters overlaid Clojure nodes (https://lezer.codemirror.net/docs/ref/#common.MountedTree).
 */
clojure_eval.node.tree = (function clojure_eval$node$tree(var_args){
var G__55258 = arguments.length;
switch (G__55258) {
case 1:
return clojure_eval.node.tree.cljs$core$IFn$_invoke$arity$1((arguments[(0)]));

break;
case 2:
return clojure_eval.node.tree.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));

break;
case 3:
return clojure_eval.node.tree.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)]));

break;
default:
throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join('')));

}
});

(clojure_eval.node.tree.cljs$core$IFn$_invoke$arity$1 = (function (state){
return module$node_modules$$codemirror$language$dist$index_cjs.syntaxTree(state);
}));

(clojure_eval.node.tree.cljs$core$IFn$_invoke$arity$2 = (function (state,pos){
return module$node_modules$$codemirror$language$dist$index_cjs.syntaxTree(state).resolveInner(pos);
}));

(clojure_eval.node.tree.cljs$core$IFn$_invoke$arity$3 = (function (state,pos,dir){
return module$node_modules$$codemirror$language$dist$index_cjs.syntaxTree(state).resolveInner(pos,dir);
}));

(clojure_eval.node.tree.cljs$lang$maxFixedArity = 3);

clojure_eval.node.cursor = (function clojure_eval$node$cursor(var_args){
var G__55260 = arguments.length;
switch (G__55260) {
case 1:
return clojure_eval.node.cursor.cljs$core$IFn$_invoke$arity$1((arguments[(0)]));

break;
case 2:
return clojure_eval.node.cursor.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));

break;
case 3:
return clojure_eval.node.cursor.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)]));

break;
default:
throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join('')));

}
});

(clojure_eval.node.cursor.cljs$core$IFn$_invoke$arity$1 = (function (tree){
return tree.cursor();
}));

(clojure_eval.node.cursor.cljs$core$IFn$_invoke$arity$2 = (function (tree,pos){
return tree.cursorAt(pos);
}));

(clojure_eval.node.cursor.cljs$core$IFn$_invoke$arity$3 = (function (tree,pos,dir){
return tree.cursorAt(pos,dir);
}));

(clojure_eval.node.cursor.cljs$lang$maxFixedArity = 3);

clojure_eval.node.terminal_cursor = (function clojure_eval$node$terminal_cursor(tree,pos,dir){
var i = pos;
while(true){
var c = clojure_eval.node.cursor.cljs$core$IFn$_invoke$arity$3(tree,i,dir);
var type = c.type;
if(clojure_eval.node.top_type_QMARK_(type)){
return null;
} else {
if(clojure_eval.node.terminal_type_QMARK_(c.type)){
return c;
} else {
var G__55384 = (dir + i);
i = G__55384;
continue;

}
}
break;
}
});
/**
 * Returns topmost node at same starting position
 */
clojure_eval.node.up_here = (function clojure_eval$node$up_here(node){
var from = clojure_eval.node.start(node);
var or__4223__auto__ = clojure_eval.node.highest(node,(function (p1__55261_SHARP_){
return cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(from,clojure_eval.node.start(p1__55261_SHARP_));
}));
if(cljs.core.truth_(or__4223__auto__)){
return or__4223__auto__;
} else {
return node;
}
});
clojure_eval.node.topmost_cursor = (function clojure_eval$node$topmost_cursor(state,from){
return clojure_eval.node.up_here(clojure_eval.node.tree.cljs$core$IFn$_invoke$arity$3(state,from,(1)).node).cursor();
});
clojure_eval.node.terminal_nodes = (function clojure_eval$node$terminal_nodes(state,from,to){
var cursor = clojure_eval.node.topmost_cursor(state,from);
var found = cljs.core.PersistentVector.EMPTY;
while(true){
var node_type = clojure_eval.node.type(cursor);
if((clojure_eval.node.start(cursor) > to)){
return found;
} else {
if(((clojure_eval.node.terminal_type_QMARK_(node_type)) || (clojure_eval.node.error_QMARK_(node_type)))){
var found__$1 = cljs.core.conj.cljs$core$IFn$_invoke$arity$2(found,({"type": node_type, "from": clojure_eval.node.start(cursor), "to": clojure_eval.node.end(cursor)}));
cursor.lastChild();

if(cljs.core.truth_(cursor.next())){
var G__55389 = found__$1;
found = G__55389;
continue;
} else {
return found__$1;
}
} else {
if(cljs.core.truth_(cursor.next())){
var G__55392 = found;
found = G__55392;
continue;
} else {
return found;
}

}
}
break;
}
});
clojure_eval.node.balanced_range = (function clojure_eval$node$balanced_range(var_args){
var G__55264 = arguments.length;
switch (G__55264) {
case 2:
return clojure_eval.node.balanced_range.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));

break;
case 3:
return clojure_eval.node.balanced_range.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)]));

break;
default:
throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join('')));

}
});

(clojure_eval.node.balanced_range.cljs$core$IFn$_invoke$arity$2 = (function (state,node){
return clojure_eval.node.balanced_range.cljs$core$IFn$_invoke$arity$3(state,clojure_eval.node.start(node),clojure_eval.node.end(node));
}));

(clojure_eval.node.balanced_range.cljs$core$IFn$_invoke$arity$3 = (function (state,from,to){
var vec__55265 = cljs.core.sort.cljs$core$IFn$_invoke$arity$1(new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [from,to], null));
var from__$1 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__55265,(0),null);
var to__$1 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__55265,(1),null);
var from_node = clojure_eval.node.tree.cljs$core$IFn$_invoke$arity$3(state,from__$1,(1));
var to_node = clojure_eval.node.tree.cljs$core$IFn$_invoke$arity$3(state,to__$1,(-1));
var from__$2 = (cljs.core.truth_(clojure_eval.node.require_balance_QMARK_(from_node))?clojure_eval.node.start(from_node):from__$1);
var to__$2 = (cljs.core.truth_(clojure_eval.node.require_balance_QMARK_(to_node))?clojure_eval.node.end(to_node):to__$1);
var vec__55268 = cljs.core.reduce.cljs$core$IFn$_invoke$arity$3((function (p__55271,node_between){
var vec__55272 = p__55271;
var left = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__55272,(0),null);
var right = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__55272,(1),null);
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [((clojure_eval.node.ancestor_QMARK_(node_between,from_node))?clojure_eval.node.start(node_between):left),((clojure_eval.node.ancestor_QMARK_(node_between,to_node))?clojure_eval.node.end(node_between):right)], null);
}),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [from__$2,to__$2], null),cljs.core.map.cljs$core$IFn$_invoke$arity$2((function (p1__55262_SHARP_){
var G__55275 = p1__55262_SHARP_;
if(clojure_eval.node.edge_QMARK_(p1__55262_SHARP_)){
return clojure_eval.node.up(G__55275);
} else {
return G__55275;
}
}),clojure_eval.node.nodes_between(from_node,to_node)));
var left = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__55268,(0),null);
var right = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__55268,(1),null);
return clojure_eval.selections.range.cljs$core$IFn$_invoke$arity$2(left,right);
}));

(clojure_eval.node.balanced_range.cljs$lang$maxFixedArity = 3);

/**
 * Span of collection not including edges
 */
clojure_eval.node.inner_span = (function clojure_eval$node$inner_span(p__55276){
var map__55277 = p__55276;
var map__55277__$1 = (((((!((map__55277 == null))))?(((((map__55277.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__55277.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.cljs$core$IFn$_invoke$arity$2(cljs.core.hash_map,map__55277):map__55277);
var node = map__55277__$1;
var firstChild = (function (){var obj55279 = map__55277__$1;
var k55280 = "firstChild";
if((function (){var obj55281 = obj55279;
return (((!((obj55281 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k55280,obj55281)));
})()){
return (obj55279[k55280]);
} else {
return undefined;
}
})();
var lastChild = (function (){var obj55282 = map__55277__$1;
var k55283 = "lastChild";
if((function (){var obj55284 = obj55282;
return (((!((obj55284 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k55283,obj55284)));
})()){
return (obj55282[k55283]);
} else {
return undefined;
}
})();
return ({"from": ((clojure_eval.node.left_edge_QMARK_(firstChild))?clojure_eval.node.end(firstChild):clojure_eval.node.start(node)), "to": ((clojure_eval.node.right_edge_QMARK_(lastChild))?clojure_eval.node.start(lastChild):clojure_eval.node.end(node))});
});
/**
 * within (exclusive of edges)
 */
clojure_eval.node.within_QMARK__LT_ = (function clojure_eval$node$within_QMARK__LT_(parent,child){
var c1 = cljs.core.compare(clojure_eval.node.start(parent),clojure_eval.node.start(child));
var c2 = cljs.core.compare(clojure_eval.node.end(parent),clojure_eval.node.end(child));
return (((((c1 > (0))) || ((c2 < (0))))) && ((((!((c1 < (0))))) && ((!((c2 > (0))))))));
});
/**
 * within (inclusive of edges)
 */
clojure_eval.node.within_QMARK_ = (function clojure_eval$node$within_QMARK_(parent,child){
return (((!((cljs.core.compare(clojure_eval.node.start(parent),clojure_eval.node.start(child)) < (0))))) && ((!((cljs.core.compare(clojure_eval.node.end(parent),clojure_eval.node.end(child)) > (0))))));
});
clojure_eval.node.follow_edges = (function clojure_eval$node$follow_edges(node){
if(clojure_eval.node.edge_QMARK_(node)){
return clojure_eval.node.up(node);
} else {
return node;
}
});
clojure_eval.node.prefix = (function clojure_eval$node$prefix(node){
var temp__5757__auto__ = clojure_eval.node.up(node);
if((temp__5757__auto__ == null)){
return null;
} else {
var parent = temp__5757__auto__;
var or__4223__auto__ = clojure_eval.util.guard(parent,clojure_eval.node.prefix_container_QMARK_);
if(cljs.core.truth_(or__4223__auto__)){
return or__4223__auto__;
} else {
return clojure_eval.util.guard(clojure_eval.node.down(parent),clojure_eval.node.prefix_edge_QMARK_);
}
}
});
clojure_eval.node.left_edge_with_prefix = (function clojure_eval$node$left_edge_with_prefix(state,node){
return [cljs.core.str.cljs$core$IFn$_invoke$arity$1((function (){var G__55286 = clojure_eval.node.prefix(node);
if((G__55286 == null)){
return null;
} else {
return clojure_eval.node.string.cljs$core$IFn$_invoke$arity$2(state,G__55286);
}
})()),clojure_eval.node.name(clojure_eval.node.down(node))].join('');
});
clojure_eval.node.with_prefix = (function clojure_eval$node$with_prefix(node){
var G__55287 = node;
if(cljs.core.truth_(clojure_eval.node.prefix(node))){
return clojure_eval.node.up(G__55287);
} else {
return G__55287;
}
});
/**
 * Node ending immediately to the left of pos
 */
clojure_eval.node.node_BAR_ = (function clojure_eval$node$node_BAR_(state,pos){
var G__55289 = clojure_eval.node.tree.cljs$core$IFn$_invoke$arity$3(state,pos,(-1));
if((G__55289 == null)){
return null;
} else {
return clojure_eval.util.guard(G__55289,(function (p1__55288_SHARP_){
return cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(pos,clojure_eval.node.end(p1__55288_SHARP_));
}));
}
});
/**
 * Node starting immediately to the right of pos
 */
clojure_eval.node._BAR_node = (function clojure_eval$node$_BAR_node(state,pos){
var G__55291 = clojure_eval.node.tree.cljs$core$IFn$_invoke$arity$3(state,pos,(1));
if((G__55291 == null)){
return null;
} else {
return clojure_eval.util.guard(G__55291,(function (p1__55290_SHARP_){
return cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(pos,clojure_eval.node.start(p1__55290_SHARP_));
}));
}
});
clojure_eval.node.nearest_touching = (function clojure_eval$node$nearest_touching(state,pos,dir){
var L = (function (){var G__55294 = clojure_eval.node.tree.cljs$core$IFn$_invoke$arity$3(state,pos,(-1));
if((G__55294 == null)){
return null;
} else {
return clojure_eval.util.guard(G__55294,(function (p__55295){
var map__55296 = p__55295;
var map__55296__$1 = (((((!((map__55296 == null))))?(((((map__55296.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__55296.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.cljs$core$IFn$_invoke$arity$2(cljs.core.hash_map,map__55296):map__55296);
var to = (function (){var obj55298 = map__55296__$1;
var k55299 = "to";
if((function (){var obj55300 = obj55298;
return (((!((obj55300 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k55299,obj55300)));
})()){
return (obj55298[k55299]);
} else {
return undefined;
}
})();
return cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(pos,to);
}));
}
})();
var R = (function (){var G__55301 = clojure_eval.node.tree.cljs$core$IFn$_invoke$arity$3(state,pos,(1));
if((G__55301 == null)){
return null;
} else {
return clojure_eval.util.guard(G__55301,(function (p__55302){
var map__55303 = p__55302;
var map__55303__$1 = (((((!((map__55303 == null))))?(((((map__55303.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__55303.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.cljs$core$IFn$_invoke$arity$2(cljs.core.hash_map,map__55303):map__55303);
var from = (function (){var obj55305 = map__55303__$1;
var k55306 = "from";
if((function (){var obj55307 = obj55305;
return (((!((obj55307 == null)))) && (applied_science.js_interop.impl.in_QMARK__STAR_(k55306,obj55307)));
})()){
return (obj55305[k55306]);
} else {
return undefined;
}
})();
return cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(pos,from);
}));
}
})();
var mid = clojure_eval.node.tree.cljs$core$IFn$_invoke$arity$2(state,pos);
var G__55308 = dir;
switch (G__55308) {
case (1):
var or__4223__auto__ = clojure_eval.util.guard(R,cljs.core.every_pred.cljs$core$IFn$_invoke$arity$2(cljs.core.some_QMARK_,(function (p1__55292_SHARP_){
return ((clojure_eval.node.same_edge_QMARK_(p1__55292_SHARP_)) || ((!(clojure_eval.node.right_edge_QMARK_(p1__55292_SHARP_)))));
})));
if(cljs.core.truth_(or__4223__auto__)){
return or__4223__auto__;
} else {
var or__4223__auto____$1 = L;
if(cljs.core.truth_(or__4223__auto____$1)){
return or__4223__auto____$1;
} else {
var or__4223__auto____$2 = R;
if(cljs.core.truth_(or__4223__auto____$2)){
return or__4223__auto____$2;
} else {
return mid;
}
}
}

break;
case (-1):
var or__4223__auto__ = clojure_eval.util.guard(L,cljs.core.every_pred.cljs$core$IFn$_invoke$arity$2(cljs.core.some_QMARK_,(function (p1__55293_SHARP_){
return ((clojure_eval.node.same_edge_QMARK_(p1__55293_SHARP_)) || ((!(clojure_eval.node.left_edge_QMARK_(p1__55293_SHARP_)))));
})));
if(cljs.core.truth_(or__4223__auto__)){
return or__4223__auto__;
} else {
var or__4223__auto____$1 = R;
if(cljs.core.truth_(or__4223__auto____$1)){
return or__4223__auto____$1;
} else {
var or__4223__auto____$2 = L;
if(cljs.core.truth_(or__4223__auto____$2)){
return or__4223__auto____$2;
} else {
return mid;
}
}
}

break;
default:
throw (new Error(["No matching clause: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(G__55308)].join('')));

}
});
/**
 * Returns true when position (or current cursor) is inside some Clojure node.
 * 
 *   This is useful for limiting certain actions when clojure is nested into another language (e.g. Markdown)
 */
clojure_eval.node.within_program_QMARK_ = (function clojure_eval$node$within_program_QMARK_(var_args){
var G__55310 = arguments.length;
switch (G__55310) {
case 1:
return clojure_eval.node.within_program_QMARK_.cljs$core$IFn$_invoke$arity$1((arguments[(0)]));

break;
case 2:
return clojure_eval.node.within_program_QMARK_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)]));

break;
default:
throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join('')));

}
});

(clojure_eval.node.within_program_QMARK_.cljs$core$IFn$_invoke$arity$1 = (function (state){
return clojure_eval.node.within_program_QMARK_.cljs$core$IFn$_invoke$arity$2(state,state.selection.main.head);
}));

(clojure_eval.node.within_program_QMARK_.cljs$core$IFn$_invoke$arity$2 = (function (state,pos){
var n = clojure_eval.node.tree.cljs$core$IFn$_invoke$arity$2(state,pos);
var or__4223__auto__ = clojure_eval.node.program_QMARK_(n);
if(or__4223__auto__){
return or__4223__auto__;
} else {
return cljs.core.some(clojure_eval.node.program_QMARK_,clojure_eval.node.ancestors(n));
}
}));

(clojure_eval.node.within_program_QMARK_.cljs$lang$maxFixedArity = 2);


//# sourceMappingURL=clojure_eval.node.js.map
