www.mooseframework.org
Public Member Functions | Public Attributes | Private Attributes | List of all members
ExpandWalker Class Reference

#include <Parser.h>

Inheritance diagram for ExpandWalker:
[legend]

Public Member Functions

 ExpandWalker (std::string fname)
 
virtual void walk (const std::string &, const std::string &, hit::Node *n) override
 

Public Attributes

std::vector< std::string > used
 
std::vector< std::string > errors
 

Private Attributes

std::string _fname
 

Detailed Description

Definition at line 54 of file Parser.h.

Constructor & Destructor Documentation

◆ ExpandWalker()

ExpandWalker::ExpandWalker ( std::string  fname)
inline

Definition at line 57 of file Parser.h.

57 : _fname(fname) {}
std::string _fname
Definition: Parser.h:107

Member Function Documentation

◆ walk()

virtual void ExpandWalker::walk ( const std::string &  ,
const std::string &  ,
hit::Node *  n 
)
inlineoverridevirtual

Definition at line 59 of file Parser.h.

60  {
61  auto f = dynamic_cast<hit::Field *>(n);
62  auto s = f->val();
63 
64  auto start = s.find("${");
65  while (start < s.size())
66  {
67  auto end = s.find("}", start);
68  if (end != std::string::npos)
69  {
70  auto var = s.substr(start + 2, end - (start + 2));
71  auto curr = n;
72  while ((curr = curr->parent()))
73  {
74  auto src = curr->find(var);
75  if (src && src != n && src->type() == hit::NodeType::Field)
76  {
77  used.push_back(hit::pathJoin({curr->fullpath(), var}));
78  s = s.substr(0, start) + curr->param<std::string>(var) +
79  s.substr(end + 1, s.size() - (end + 1));
80 
81  if (end + 1 - start == f->val().size())
82  f->setVal(s, dynamic_cast<hit::Field *>(curr->find(var))->kind());
83  else
84  f->setVal(s);
85 
86  // move end back to the position of the end of the replacement text - not the replaced
87  // text since the former is the one relevant to the string for remaining replacements.
88  end = start + curr->param<std::string>(var).size();
89  break;
90  }
91  }
92 
93  if (curr == nullptr)
94  errors.push_back(
95  errormsg(_fname, n, "no variable '", var, "' found for substitution expression"));
96  }
97  else
98  errors.push_back(errormsg(_fname, n, "missing substitution expression terminator '}'"));
99  start = s.find("${", end);
100  }
101  }
std::vector< std::string > errors
Definition: Parser.h:104
std::vector< std::string > used
Definition: Parser.h:103
PetscInt n
std::string errormsg(std::string, hit::Node *)
Definition: Parser.h:34
std::string _fname
Definition: Parser.h:107

Member Data Documentation

◆ _fname

std::string ExpandWalker::_fname
private

Definition at line 107 of file Parser.h.

Referenced by walk().

◆ errors

std::vector<std::string> ExpandWalker::errors

Definition at line 104 of file Parser.h.

Referenced by Parser::parse(), and walk().

◆ used

std::vector<std::string> ExpandWalker::used

Definition at line 103 of file Parser.h.

Referenced by Parser::parse(), and walk().


The documentation for this class was generated from the following file: