www.mooseframework.org
Classes | Public Member Functions | Protected Attributes | List of all members
Syntax Class Reference

Holding syntax for parsing input files. More...

#include <Syntax.h>

Classes

struct  ActionInfo
 

Public Member Functions

 Syntax ()
 
void registerTaskName (std::string task, bool is_required)
 
void registerTaskName (std::string task, std::string moose_object_type, bool is_required)
 
void appendTaskName (std::string task, std::string moose_object_type)
 
void addDependency (std::string task, std::string pre_req)
 
void addDependencySets (const std::string &action_sets)
 
const std::vector< std::string > & getSortedTask ()
 
const std::vector< std::vector< std::string > > & getSortedTaskSet ()
 
bool hasTask (const std::string &task)
 
bool isActionRequired (const std::string &task)
 
void registerActionSyntax (const std::string &action, const std::string &syntax, const std::string &task="", const std::string &file="", int line=-1)
 
void replaceActionSyntax (const std::string &action, const std::string &syntax, const std::string &task, const std::string &file="", int line=-1)
 Registration function that replaces existing Moose Actions with a completely new action Note: This function will remove all actions associated with this piece of syntax NOT just a single match of some kind. More...
 
void registerSyntaxType (const std::string &syntax, const std::string &type)
 Registration a type with a block. More...
 
const std::multimap< std::string, std::string > & getAssociatedTypes () const
 Get a multimap of registered associations of syntax with type. More...
 
void deprecateActionSyntax (const std::string &syntax)
 This method deprecates previously registered syntax. More...
 
bool isDeprecatedSyntax (const std::string &syntax) const
 Returns a Boolean indicating whether the syntax has been deprecated through a call to deprecateActionSyntax. More...
 
std::string getSyntaxByAction (const std::string &action, const std::string &task)
 
std::string isAssociated (const std::string &real_id, bool *is_parent)
 Method for determining whether a piece of syntax is associated with an Action TODO: I need a better name. More...
 
std::pair< std::multimap< std::string, ActionInfo >::iterator, std::multimap< std::string, ActionInfo >::iterator > getActions (const std::string &name)
 
const std::multimap< std::string, ActionInfo > & getAssociatedActions () const
 
bool verifyMooseObjectTask (const std::string &base, const std::string &task) const
 
FileLineInfo getLineInfo (const std::string &syntax, const std::string &action, const std::string &task) const
 Gets the file and line where the syntax/action/task combo was registered. More...
 

Protected Attributes

std::map< std::string, bool > _registered_tasks
 The list of registered tasks and a flag indicating whether or not they are required. More...
 
std::multimap< std::string, std::string > _moose_systems_to_tasks
 The list of Moose system objects to tasks. This map indicates which tasks are allowed to build certain MooseObjects. More...
 
DependencyResolver< std::string > _tasks
 The dependency resolver. More...
 
std::multimap< std::string, ActionInfo_associated_actions
 Actions/Syntax association. More...
 
std::multimap< std::string, std::string > _associated_types
 Syntax/Type association. More...
 
std::set< std::string > _deprecated_syntax
 
FileLineInfoMap _syntax_to_line
 

Detailed Description

Holding syntax for parsing input files.

Definition at line 26 of file Syntax.h.

Constructor & Destructor Documentation

Syntax::Syntax ( )

Definition at line 18 of file Syntax.C.

18 {}

Member Function Documentation

void Syntax::addDependency ( std::string  task,
std::string  pre_req 
)

Definition at line 51 of file Syntax.C.

Referenced by addDependencySets().

52 {
53  if (_registered_tasks.find(task) == _registered_tasks.end())
54  mooseError("A ", task, " is not a registered task name.");
55 
56  _tasks.insertDependency(task, pre_req);
57 }
DependencyResolver< std::string > _tasks
The dependency resolver.
Definition: Syntax.h:134
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::map< std::string, bool > _registered_tasks
The list of registered tasks and a flag indicating whether or not they are required.
Definition: Syntax.h:128
void insertDependency(const T &key, const T &value)
Insert a dependency pair - the first value or the "key" depends on the second value or the "value"...
void Syntax::addDependencySets ( const std::string &  action_sets)

Definition at line 60 of file Syntax.C.

Referenced by Moose::addActionTypes().

61 {
62  std::vector<std::string> sets, prev_names, tasks;
63  MooseUtils::tokenize(action_sets, sets, 1, "()");
64 
65  for (unsigned int i = 0; i < sets.size(); ++i)
66  {
67  tasks.clear();
68  MooseUtils::tokenize(sets[i], tasks, 0, ", ");
69  for (unsigned int j = 0; j < tasks.size(); ++j)
70  {
71  // Each line should depend on each item in the previous line
72  for (unsigned int k = 0; k < prev_names.size(); ++k)
73  addDependency(tasks[j], prev_names[k]);
74  }
75  // Copy the the current items to the previous items for the next iteration
76  std::swap(tasks, prev_names);
77  }
78 }
void tokenize(const std::string &str, std::vector< T > &elements, unsigned int min_len=1, const std::string &delims="/")
This function will split the passed in string on a set of delimiters appending the substrings to the ...
Definition: MooseUtils.h:350
void addDependency(std::string task, std::string pre_req)
Definition: Syntax.C:51
X_global swap(X_sys)
void Syntax::appendTaskName ( std::string  task,
std::string  moose_object_type 
)

Definition at line 42 of file Syntax.C.

43 {
44  if (_registered_tasks.find(task) == _registered_tasks.end())
45  mooseError("A ", task, " is not a registered task name.");
46 
47  _moose_systems_to_tasks.insert(std::make_pair(moose_object_type, task));
48 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::map< std::string, bool > _registered_tasks
The list of registered tasks and a flag indicating whether or not they are required.
Definition: Syntax.h:128
std::multimap< std::string, std::string > _moose_systems_to_tasks
The list of Moose system objects to tasks. This map indicates which tasks are allowed to build certai...
Definition: Syntax.h:131
void Syntax::deprecateActionSyntax ( const std::string &  syntax)

This method deprecates previously registered syntax.

You should use the exact form that you want deprecated in the passed in parameter.

Definition at line 131 of file Syntax.C.

Referenced by getAssociatedTypes().

132 {
133  _deprecated_syntax.insert(syntax);
134 }
std::set< std::string > _deprecated_syntax
Definition: Syntax.h:142
std::pair< std::multimap< std::string, Syntax::ActionInfo >::iterator, std::multimap< std::string, Syntax::ActionInfo >::iterator > Syntax::getActions ( const std::string &  name)

Definition at line 225 of file Syntax.C.

Referenced by getAssociatedTypes(), Parser::listValidParams(), and Parser::walkRaw().

226 {
227  return _associated_actions.equal_range(name);
228 }
std::multimap< std::string, ActionInfo > _associated_actions
Actions/Syntax association.
Definition: Syntax.h:137
const std::multimap<std::string, ActionInfo>& Syntax::getAssociatedActions ( ) const
inline

Definition at line 108 of file Syntax.h.

Referenced by Parser::buildFullTree(), Parser::buildJsonSyntaxTree(), and MooseApp::setupOptions().

109  {
110  return _associated_actions;
111  }
std::multimap< std::string, ActionInfo > _associated_actions
Actions/Syntax association.
Definition: Syntax.h:137
const std::multimap<std::string, std::string>& Syntax::getAssociatedTypes ( ) const
inline

Get a multimap of registered associations of syntax with type.

Definition at line 80 of file Syntax.h.

Referenced by Parser::buildJsonSyntaxTree().

81  {
82  return _associated_types;
83  }
std::multimap< std::string, std::string > _associated_types
Syntax/Type association.
Definition: Syntax.h:140
FileLineInfo Syntax::getLineInfo ( const std::string &  syntax,
const std::string &  action,
const std::string &  task 
) const

Gets the file and line where the syntax/action/task combo was registered.

Parameters
syntaxSyntax name
actionAction name
taskTask name
Returns
A FileLineInfo associated with the syntax/action/task triplet

Definition at line 252 of file Syntax.C.

Referenced by Parser::buildJsonSyntaxTree(), and getAssociatedActions().

255 {
256  return _syntax_to_line.getInfo(syntax, action, task);
257 }
FileLineInfoMap _syntax_to_line
Definition: Syntax.h:143
FileLineInfo getInfo(const std::string &key0) const
Get file/line info for a key.
Definition: FileLineInfo.C:81
const std::vector< std::string > & Syntax::getSortedTask ( )

Definition at line 81 of file Syntax.C.

Referenced by ActionWarehouse::build().

82 {
83  return _tasks.getSortedValues();
84 }
DependencyResolver< std::string > _tasks
The dependency resolver.
Definition: Syntax.h:134
const std::vector< T > & getSortedValues()
This function also returns dependency resolved values but with a simpler single vector interface...
const std::vector< std::vector< std::string > > & Syntax::getSortedTaskSet ( )

Definition at line 87 of file Syntax.C.

Referenced by ActionWarehouse::printActionDependencySets().

88 {
89  return _tasks.getSortedValuesSets();
90 }
const std::vector< std::vector< T > > & getSortedValuesSets()
Returns a vector of sets that represent dependency resolved values.
DependencyResolver< std::string > _tasks
The dependency resolver.
Definition: Syntax.h:134
std::string Syntax::getSyntaxByAction ( const std::string &  action,
const std::string &  task 
)

For now we don't have a data structure that maps Actions to Syntax but this routine is only used by the build full tree routine so it doesn't need to be fast. We will do a linear search for each call to this routine

Definition at line 143 of file Syntax.C.

Referenced by Parser::extractParams(), getAssociatedTypes(), and Parser::parse().

144 {
145  std::string syntax;
151  for (const auto & iter : _associated_actions)
152  if (iter.second._action == action && (iter.second._task == task || iter.second._task == ""))
153  syntax = iter.first;
154 
155  return syntax;
156 }
std::multimap< std::string, ActionInfo > _associated_actions
Actions/Syntax association.
Definition: Syntax.h:137
bool Syntax::hasTask ( const std::string &  task)

Definition at line 93 of file Syntax.C.

Referenced by ActionWarehouse::addActionBlock().

94 {
95  return (_registered_tasks.find(task) != _registered_tasks.end());
96 }
std::map< std::string, bool > _registered_tasks
The list of registered tasks and a flag indicating whether or not they are required.
Definition: Syntax.h:128
bool Syntax::isActionRequired ( const std::string &  task)

Definition at line 99 of file Syntax.C.

Referenced by ActionWarehouse::buildBuildableActions().

100 {
101  return _registered_tasks[task];
102 }
std::map< std::string, bool > _registered_tasks
The list of registered tasks and a flag indicating whether or not they are required.
Definition: Syntax.h:128
std::string Syntax::isAssociated ( const std::string &  real_id,
bool *  is_parent 
)

Method for determining whether a piece of syntax is associated with an Action TODO: I need a better name.

This implementation assumes that wildcards can occur in the place of an entire token but not as part of a token (i.e. 'Variables/ * /InitialConditions' is valid but not 'Variables/Partial* /InitialConditions'. Since maps are ordered, a reverse traversal through the registered list will always select a more specific match before a wildcard match ('*' == char(42))

Definition at line 159 of file Syntax.C.

Referenced by getAssociatedTypes(), Parser::listValidParams(), ActionWarehouse::printInputFile(), and Parser::walkRaw().

160 {
170  bool local_is_parent;
171  if (is_parent == NULL)
172  is_parent = &local_is_parent; // Just so we don't have to keep checking below when we want to
173  // set the value
174  std::multimap<std::string, ActionInfo>::reverse_iterator it;
175  std::vector<std::string> real_elements, reg_elements;
176  std::string return_value;
177 
178  MooseUtils::tokenize(real_id, real_elements);
179 
180  *is_parent = false;
181  for (it = _associated_actions.rbegin(); it != _associated_actions.rend(); ++it)
182  {
183  std::string reg_id = it->first;
184  if (reg_id == real_id)
185  {
186  *is_parent = false;
187  return reg_id;
188  }
189  reg_elements.clear();
190  MooseUtils::tokenize(reg_id, reg_elements);
191  if (real_elements.size() <= reg_elements.size())
192  {
193  bool keep_going = true;
194  for (unsigned int j = 0; keep_going && j < real_elements.size(); ++j)
195  {
196  if (real_elements[j] != reg_elements[j] && reg_elements[j] != std::string("*"))
197  keep_going = false;
198  }
199  if (keep_going)
200  {
201  if (real_elements.size() < reg_elements.size() && !*is_parent)
202  {
203  // We found a parent, the longest parent in fact but we need to keep
204  // looking to make sure that the real thing isn't registered
205  *is_parent = true;
206  return_value = reg_id;
207  }
208  else if (real_elements.size() == reg_elements.size())
209  {
210  *is_parent = false;
211  return reg_id;
212  }
213  }
214  }
215  }
216 
217  if (*is_parent)
218  return return_value;
219  else
220  return std::string("");
221 }
void tokenize(const std::string &str, std::vector< T > &elements, unsigned int min_len=1, const std::string &delims="/")
This function will split the passed in string on a set of delimiters appending the substrings to the ...
Definition: MooseUtils.h:350
std::multimap< std::string, ActionInfo > _associated_actions
Actions/Syntax association.
Definition: Syntax.h:137
bool Syntax::isDeprecatedSyntax ( const std::string &  syntax) const

Returns a Boolean indicating whether the syntax has been deprecated through a call to deprecateActionSyntax.

Definition at line 137 of file Syntax.C.

Referenced by getAssociatedTypes(), and Parser::walkRaw().

138 {
139  return _deprecated_syntax.find(syntax) != _deprecated_syntax.end();
140 }
std::set< std::string > _deprecated_syntax
Definition: Syntax.h:142
void Syntax::registerActionSyntax ( const std::string &  action,
const std::string &  syntax,
const std::string &  task = "",
const std::string &  file = "",
int  line = -1 
)

Definition at line 105 of file Syntax.C.

Referenced by replaceActionSyntax().

110 {
111  ActionInfo action_info;
112  action_info._action = action;
113  action_info._task = task;
114 
115  _associated_actions.insert(std::make_pair(syntax, action_info));
116  _syntax_to_line.addInfo(syntax, action, task, file, line);
117 }
FileLineInfoMap _syntax_to_line
Definition: Syntax.h:143
void addInfo(const std::string &key0, const std::string &file, int line)
Associate a key with file/line info.
Definition: FileLineInfo.C:40
std::multimap< std::string, ActionInfo > _associated_actions
Actions/Syntax association.
Definition: Syntax.h:137
void Syntax::registerSyntaxType ( const std::string &  syntax,
const std::string &  type 
)

Registration a type with a block.

For example, associate FunctionName with the Functions block

Parameters
syntaxThe target syntax to associate the type with
typeThe name of the type to associate with the syntax

Definition at line 246 of file Syntax.C.

Referenced by Moose::associateSyntax().

247 {
248  _associated_types.insert(std::make_pair(syntax, type));
249 }
MatType type
std::multimap< std::string, std::string > _associated_types
Syntax/Type association.
Definition: Syntax.h:140
void Syntax::registerTaskName ( std::string  task,
bool  is_required 
)

Definition at line 21 of file Syntax.C.

22 {
23  if (_registered_tasks.find(task) != _registered_tasks.end())
24  mooseError("A ", task, " is already registered. Do you need to use appendTaskName instead?");
25 
26  _tasks.addItem(task);
27  _registered_tasks[task] = is_required;
28 }
DependencyResolver< std::string > _tasks
The dependency resolver.
Definition: Syntax.h:134
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::map< std::string, bool > _registered_tasks
The list of registered tasks and a flag indicating whether or not they are required.
Definition: Syntax.h:128
void addItem(const T &value)
Add an independent item to the set.
void Syntax::registerTaskName ( std::string  task,
std::string  moose_object_type,
bool  is_required 
)

Definition at line 31 of file Syntax.C.

32 {
33  if (_registered_tasks.find(task) != _registered_tasks.end())
34  mooseError("A ", task, " is already registered. Do you need to use appendTaskName instead?");
35 
36  _tasks.addItem(task);
37  _registered_tasks[task] = is_required;
38  _moose_systems_to_tasks.insert(std::make_pair(moose_object_type, task));
39 }
DependencyResolver< std::string > _tasks
The dependency resolver.
Definition: Syntax.h:134
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::map< std::string, bool > _registered_tasks
The list of registered tasks and a flag indicating whether or not they are required.
Definition: Syntax.h:128
std::multimap< std::string, std::string > _moose_systems_to_tasks
The list of Moose system objects to tasks. This map indicates which tasks are allowed to build certai...
Definition: Syntax.h:131
void addItem(const T &value)
Add an independent item to the set.
void Syntax::replaceActionSyntax ( const std::string &  action,
const std::string &  syntax,
const std::string &  task,
const std::string &  file = "",
int  line = -1 
)

Registration function that replaces existing Moose Actions with a completely new action Note: This function will remove all actions associated with this piece of syntax NOT just a single match of some kind.

Definition at line 120 of file Syntax.C.

125 {
126  _associated_actions.erase(syntax);
127  registerActionSyntax(action, syntax, task, file, line);
128 }
void registerActionSyntax(const std::string &action, const std::string &syntax, const std::string &task="", const std::string &file="", int line=-1)
Definition: Syntax.C:105
std::multimap< std::string, ActionInfo > _associated_actions
Actions/Syntax association.
Definition: Syntax.h:137
bool Syntax::verifyMooseObjectTask ( const std::string &  base,
const std::string &  task 
) const

Definition at line 231 of file Syntax.C.

Referenced by ActionWarehouse::addActionBlock(), Parser::buildFullTree(), Parser::buildJsonSyntaxTree(), and getAssociatedActions().

232 {
233  std::pair<std::multimap<std::string, std::string>::const_iterator,
234  std::multimap<std::string, std::string>::const_iterator>
235  iters = _moose_systems_to_tasks.equal_range(base);
236 
237  for (std::multimap<std::string, std::string>::const_iterator it = iters.first; it != iters.second;
238  ++it)
239  if (task == it->second)
240  return true;
241 
242  return false;
243 }
std::multimap< std::string, std::string > _moose_systems_to_tasks
The list of Moose system objects to tasks. This map indicates which tasks are allowed to build certai...
Definition: Syntax.h:131

Member Data Documentation

std::multimap<std::string, ActionInfo> Syntax::_associated_actions
protected

Actions/Syntax association.

Definition at line 137 of file Syntax.h.

Referenced by getActions(), getAssociatedActions(), getSyntaxByAction(), isAssociated(), registerActionSyntax(), and replaceActionSyntax().

std::multimap<std::string, std::string> Syntax::_associated_types
protected

Syntax/Type association.

Definition at line 140 of file Syntax.h.

Referenced by getAssociatedTypes(), and registerSyntaxType().

std::set<std::string> Syntax::_deprecated_syntax
protected

Definition at line 142 of file Syntax.h.

Referenced by deprecateActionSyntax(), and isDeprecatedSyntax().

std::multimap<std::string, std::string> Syntax::_moose_systems_to_tasks
protected

The list of Moose system objects to tasks. This map indicates which tasks are allowed to build certain MooseObjects.

Definition at line 131 of file Syntax.h.

Referenced by appendTaskName(), registerTaskName(), and verifyMooseObjectTask().

std::map<std::string, bool> Syntax::_registered_tasks
protected

The list of registered tasks and a flag indicating whether or not they are required.

Definition at line 128 of file Syntax.h.

Referenced by addDependency(), appendTaskName(), hasTask(), isActionRequired(), and registerTaskName().

FileLineInfoMap Syntax::_syntax_to_line
protected

Definition at line 143 of file Syntax.h.

Referenced by getLineInfo(), and registerActionSyntax().

DependencyResolver<std::string> Syntax::_tasks
protected

The dependency resolver.

Definition at line 134 of file Syntax.h.

Referenced by addDependency(), getSortedTask(), getSortedTaskSet(), and registerTaskName().


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