Skip to content

Commit

Permalink
Clean up obsolete code
Browse files Browse the repository at this point in the history
  • Loading branch information
sungshik committed Oct 9, 2024
1 parent 0b35f6d commit 562dc55
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ bool tryParse(Grammar g, Symbol s, str input, bool allowAmbiguity = false) {
Checks if symbol `s` is recursive in grammar `g`
}

// TODO: Compute a map and memoize the results
bool isRecursive(Grammar g, Symbol s, set[Symbol] checking = {})
= s in checking
? true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Grammar;
import ParseTree;
import Relation;
import Set;
import util::Maybe;

import lang::rascal::grammar::Util;

Expand Down Expand Up @@ -50,7 +49,7 @@ Dependencies deps(Graph[Production] g) {
= deps(removeNodes(g, getNodes(g, p, getAncestors = removeAncestors)));
list[Production] getProds()
= toList(g.nodes);

return deps(retainProds, removeProds, getProds);
}

Expand Down Expand Up @@ -82,10 +81,14 @@ alias Graph[&Node] = tuple[
rel[&Node, &Node] edges];
@synopsis {
Representation of predicates to select nodes in a graph
Representation of predicates to select nodes in a graph based on their own
properties, their ancestors, and their descendants
}
alias Predicate[&Node] = bool(&Node n);
alias Predicate[&Node] = bool(
&Node n,
set[&Node] ancestors /* of `n` in the graph */,
set[&Node] descendants /* of `n` in the graph */);
@synopsis{
Gets the nodes of graph `g` that satisfy predicate `p`, optionally including
Expand All @@ -94,13 +97,13 @@ alias Predicate[&Node] = bool(&Node n);
set[&Node] getNodes(Graph[&Node] g, Predicate[&Node] p,
bool getAncestors = false, bool getDescendants = false) {
// Compute ancestors/descendants of nodes
rel[&Node, &Node] descendants = g.edges+;
rel[&Node, &Node] ancestors = invert(descendants);
// Select nodes
nodes = {n | n <- g.nodes, p(n)};
nodes = {n | n <- g.nodes, p(n, ancestors[n] ? {}, descendants[n] ? {})};
nodes += ({} | it + (ancestors[n] ? {}) | getAncestors, n <- nodes);
nodes += ({} | it + (descendants[n] ? {}) | getDescendants, n <- nodes);
return nodes;
Expand All @@ -118,27 +121,4 @@ Graph[&Node] retainNodes(Graph[&Node] g, set[&Node] nodes)
}
Graph[&Node] removeNodes(Graph[&Node] g, set[&Node] nodes)
= <g.nodes - nodes, carrierX(g.edges, nodes)>;
@synopsis{
Gets the closest ancestors that satisfy predicate `p` in each branch upward
from node `n` in graph `g`, optionally including `\default` when none of the
ancestors in a branch satisfy `p`
}
set[&Node] getClosestAncestors(
Graph[&Node] g, Predicate[&Node] p, &Node n,
set[&Node] getting = {}, Maybe[&Node] \default = nothing()) {
if (n in getting) {
return {};
} else {
set[&Node] parents = invert(g.edges)[n];
if ({} == parents && just(_) := \default) {
return {\default.val};
} else {
set[&Node] recur(&Node parent) = getClosestAncestors(g, p, parent, getting = getting + n, \default = \default);
return {*(p(parent) ? {parent} : recur(parent)) | parent <- parents};
}
}
}
= <g.nodes - nodes, carrierX(g.edges, nodes)>;

0 comments on commit 562dc55

Please sign in to comment.