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 59 of file Parser.h.

Constructor & Destructor Documentation

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

Definition at line 62 of file Parser.h.

62 : _fname(fname) {}
std::string _fname
Definition: Parser.h:112

Member Function Documentation

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

Definition at line 64 of file Parser.h.

Referenced by Parser::getSyntaxByAction().

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

Member Data Documentation

std::string ExpandWalker::_fname
private

Definition at line 112 of file Parser.h.

Referenced by walk().

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

Definition at line 109 of file Parser.h.

Referenced by walk().

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

Definition at line 108 of file Parser.h.

Referenced by walk().


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