www.mooseframework.org
Classes | Functions
Parser.C File Reference

Go to the source code of this file.

Classes

class  DupParamWalker
 
class  UnusedWalker
 
class  BadActiveWalker
 

Functions

bool isSectionActive (std::string path, hit::Node *root)
 
std::vector< std::string > findSimilar (std::string param, std::vector< std::string > options)
 

Function Documentation

std::vector<std::string> findSimilar ( std::string  param,
std::vector< std::string >  options 
)

Definition at line 139 of file Parser.C.

Referenced by UnusedWalker::walk().

140 {
141  std::vector<std::string> candidates;
142  if (options.size() == 0)
143  return candidates;
144 
145  int mindist = MooseUtils::levenshteinDist(options[0], param);
146  for (auto & opt : options)
147  {
148  int dist = MooseUtils::levenshteinDist(opt, param);
149  // magic number heuristics to get similarity distance cutoff
150  int dist_cutoff = 1 + param.size() / 5;
151  if (dist > dist_cutoff || dist > mindist)
152  continue;
153 
154  if (dist < mindist)
155  {
156  mindist = dist;
157  candidates.clear();
158  }
159  candidates.push_back(opt);
160  }
161  return candidates;
162 }
int levenshteinDist(const std::string &s1, const std::string &s2)
Computes and returns the Levenshtein distance between strings s1 and s2.
Definition: MooseUtils.C:46
bool isSectionActive ( std::string  path,
hit::Node *  root 
)

Definition at line 72 of file Parser.C.

Referenced by UnusedWalker::walk(), and Parser::walkRaw().

73 {
74  hit::Node * n = root->find(path);
75  while (n)
76  {
77  hit::Node * section = n->parent();
78  if (section)
79  {
80  auto actives = section->find("active");
81  auto inactives = section->find("inactive");
82 
83  // only check current level, not nested ones
84  if (actives && actives->type() == hit::NodeType::Field && actives->parent() == section)
85  {
86  auto vars = section->param<std::vector<std::string>>("active");
87  bool have_var = false;
88  for (auto & var : vars)
89  if (n->path() == hit::pathNorm(var))
90  have_var = true;
91  if (!have_var)
92  return false;
93  }
94  // only check current level, not nested ones
95  if (inactives && inactives->type() == hit::NodeType::Field && inactives->parent() == section)
96  {
97  auto vars = section->param<std::vector<std::string>>("inactive");
98  for (auto & var : vars)
99  if (n->path() == hit::pathNorm(var))
100  return false;
101  }
102  }
103  n = section;
104  }
105  return true;
106 }
PetscInt n