https://mooseframework.inl.gov
Parser.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 // MOOSE includes
13 #include "ConsoleStreamInterface.h"
14 #include "MooseTypes.h"
15 #include "Syntax.h"
16 
17 #include "hit/hit.h"
18 
19 #include <vector>
20 #include <string>
21 #include <iomanip>
22 #include <optional>
23 #include <filesystem>
24 
25 // Forward declarations
26 class ActionWarehouse;
27 class SyntaxTree;
28 class MooseApp;
29 class Factory;
30 class ActionFactory;
31 class GlobalParamsAction;
32 class JsonSyntaxTree;
33 
34 class FuncParseEvaler : public hit::Evaler
35 {
36 public:
37  virtual std::string
38  eval(hit::Field * n, const std::list<std::string> & args, hit::BraceExpander & exp);
39 };
40 
41 class UnitsConversionEvaler : public hit::Evaler
42 {
43 public:
44  virtual std::string
45  eval(hit::Field * n, const std::list<std::string> & args, hit::BraceExpander & exp);
46 };
47 
48 class DupParamWalker : public hit::Walker
49 {
50 public:
51  virtual void
52  walk(const std::string & fullpath, const std::string & /*nodepath*/, hit::Node * n) override;
53 
54  std::vector<std::string> errors;
55 
56 private:
57  std::set<std::string> _duplicates;
58  std::map<std::string, hit::Node *> _have;
59 };
60 
61 class BadActiveWalker : public hit::Walker
62 {
63 public:
64  virtual void walk(const std::string & /*fullpath*/,
65  const std::string & /*nodepath*/,
66  hit::Node * section) override;
67  std::vector<std::string> errors;
68 };
69 
70 class CompileParamWalker : public hit::Walker
71 {
72 public:
73  typedef std::map<std::string, hit::Node *> ParamMap;
74  CompileParamWalker(ParamMap & map) : _map(map){};
75 
76  virtual void
77  walk(const std::string & fullpath, const std::string & /*nodepath*/, hit::Node * n) override;
78 
79 private:
81 };
82 
83 class OverrideParamWalker : public hit::Walker
84 {
85 public:
87 
88  void walk(const std::string & fullpath, const std::string & /*nodepath*/, hit::Node * n) override;
89  std::vector<std::string> warnings;
90 
91 private:
93 };
94 
100 class Parser
101 {
102 public:
108  Parser(const std::vector<std::string> & input_filenames,
109  const std::optional<std::vector<std::string>> & input_text = {});
115  Parser(const std::string & input_filename, const std::optional<std::string> & input_text = {});
116 
120  void parse();
121 
127  void extractParams(const std::string & prefix, InputParameters & p);
128 
134  hit::Node * root() { return _root.get(); }
135 
139  const std::vector<std::string> & getInputFileNames() const { return _input_filenames; }
140 
141  /*
142  * Get extracted application type from parser
143  */
144  const std::string & getAppType() const { return _app_type; }
145 
146  /*
147  * Set the application type in parser
148  */
149  void setAppType(const std::string & app_type) { _app_type = app_type; }
150 
154  const std::string & getLastInputFileName() const;
155 
159  std::filesystem::path getLastInputFilePath() const { return getLastInputFileName(); }
160 
161 private:
163  std::unique_ptr<hit::Node> _root;
164 
166  const std::vector<std::string> _input_filenames;
167 
169  const std::optional<std::vector<std::string>> _input_text;
170 
172  std::string _app_type;
173 };
const std::vector< std::string > _input_filenames
The input file names.
Definition: Parser.h:166
void setAppType(const std::string &app_type)
Definition: Parser.h:149
void parse()
Parses the inputs.
Definition: Parser.C:299
const std::optional< std::vector< std::string > > _input_text
The optional input text contents (to support not reading by file)
Definition: Parser.h:169
std::vector< std::string > errors
Definition: Parser.h:67
CompileParamWalker(ParamMap &map)
Definition: Parser.h:74
auto exp(const T &)
Generic factory class for build all sorts of objects.
Definition: Factory.h:28
ParamMap & _map
Definition: Parser.h:80
virtual std::string eval(hit::Field *n, const std::list< std::string > &args, hit::BraceExpander &exp)
Definition: Parser.C:89
const std::string & getLastInputFileName() const
Definition: Parser.C:291
Base class for MOOSE-based applications.
Definition: MooseApp.h:85
Storage for action instances.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const std::vector< std::string > & getInputFileNames() const
Definition: Parser.h:139
void extractParams(const std::string &prefix, InputParameters &p)
This function attempts to extract values from the input file based on the contents of the passed para...
std::vector< std::string > warnings
Definition: Parser.h:89
std::set< std::string > _duplicates
Definition: Parser.h:57
Holds the syntax in a Json::Value tree.
std::string _app_type
The application types extracted from [Application] block.
Definition: Parser.h:172
const std::string & getAppType() const
Definition: Parser.h:144
virtual void walk(const std::string &fullpath, const std::string &, hit::Node *n) override
Definition: Parser.C:191
Parser(const std::vector< std::string > &input_filenames, const std::optional< std::vector< std::string >> &input_text={})
Constructor given a list of input files, given in input_filenames.
Definition: Parser.C:155
std::map< std::string, hit::Node * > _have
Definition: Parser.h:58
Specialized factory for generic Action System objects.
Definition: ActionFactory.h:50
std::map< std::string, hit::Node * > ParamMap
Definition: Parser.h:73
hit::Node * root()
Definition: Parser.h:134
virtual void walk(const std::string &fullpath, const std::string &, hit::Node *n) override
Definition: Parser.C:172
std::unique_ptr< hit::Node > _root
The root node, which owns the whole tree.
Definition: Parser.h:163
void walk(const std::string &fullpath, const std::string &, hit::Node *n) override
Definition: Parser.C:200
std::filesystem::path getLastInputFilePath() const
Definition: Parser.h:159
virtual std::string eval(hit::Field *n, const std::list< std::string > &args, hit::BraceExpander &exp)
Definition: Parser.C:37
OverrideParamWalker(const CompileParamWalker::ParamMap &map)
Definition: Parser.h:86
Class for parsing input files.
Definition: Parser.h:100
std::vector< std::string > errors
Definition: Parser.h:54
virtual void walk(const std::string &, const std::string &, hit::Node *section) override
Definition: Parser.C:216
const CompileParamWalker::ParamMap & _map
Definition: Parser.h:92