Line data Source code
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 62248 : 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: 80 : ParamMap & _map; 81 : }; 82 : 83 : class OverrideParamWalker : public hit::Walker 84 : { 85 : public: 86 62248 : OverrideParamWalker(const CompileParamWalker::ParamMap & map) : _map(map) {} 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: 92 : const CompileParamWalker::ParamMap & _map; 93 : }; 94 : 95 : /** 96 : * Class for parsing input files. This class utilizes the GetPot library for actually tokenizing and 97 : * parsing files. It is not currently designed for extensibility. If you wish to build your own 98 : * parser, please contact the MOOSE team for guidance. 99 : */ 100 : class Parser 101 : { 102 : public: 103 : /** 104 : * Constructor given a list of input files, given in \p input_filenames. 105 : * 106 : * Optionally, the file contents can be provided via text in \p input_text. 107 : */ 108 : Parser(const std::vector<std::string> & input_filenames, 109 : const std::optional<std::vector<std::string>> & input_text = {}); 110 : /** 111 : * Constructor, given a file in \p input_filename. 112 : * 113 : * Optionally, the file contents can be provided via text in \p input_text. 114 : */ 115 : Parser(const std::string & input_filename, const std::optional<std::string> & input_text = {}); 116 : 117 : /** 118 : * Parses the inputs 119 : */ 120 : void parse(); 121 : 122 : /** 123 : * This function attempts to extract values from the input file based on the contents of 124 : * the passed parameters objects. It handles a number of various types with dynamic casting 125 : * including vector types 126 : */ 127 : void extractParams(const std::string & prefix, InputParameters & p); 128 : 129 : /** 130 : * @return The root HIT node, if any 131 : * 132 : * If this is null, it means that we haven't parsed yet 133 : */ 134 62738303 : hit::Node * root() { return _root.get(); } 135 : 136 : /** 137 : * @return The names of the inputs 138 : */ 139 331671 : const std::vector<std::string> & getInputFileNames() const { return _input_filenames; } 140 : 141 : /* 142 : * Get extracted application type from parser 143 : */ 144 176860 : const std::string & getAppType() const { return _app_type; } 145 : 146 : /* 147 : * Set the application type in parser 148 : */ 149 62808 : void setAppType(const std::string & app_type) { _app_type = app_type; } 150 : 151 : /** 152 : * @return The file name of the last input 153 : */ 154 : const std::string & getLastInputFileName() const; 155 : 156 : /** 157 : * @return The path of the last input 158 : */ 159 2218 : std::filesystem::path getLastInputFilePath() const { return getLastInputFileName(); } 160 : 161 : private: 162 : /// The root node, which owns the whole tree 163 : std::unique_ptr<hit::Node> _root; 164 : 165 : /// The input file names 166 : const std::vector<std::string> _input_filenames; 167 : 168 : /// The optional input text contents (to support not reading by file) 169 : const std::optional<std::vector<std::string>> _input_text; 170 : 171 : /// The application types extracted from [Application] block 172 : std::string _app_type; 173 : };