Branch data Line data Source code
1 : : // ***************************************************************************** 2 : : /*! 3 : : \file src/Control/Inciter/InputDeck/Parser.cpp 4 : : \copyright 2012-2015 J. Bakosi, 5 : : 2016-2018 Los Alamos National Security, LLC., 6 : : 2019-2021 Triad National Security, LLC. 7 : : All rights reserved. See the LICENSE file for details. 8 : : \brief Inciter's input deck file parser 9 : : \details This file defines the input deck, i.e., control file, parser for 10 : : the computational shock hydrodynamics tool, Inciter. 11 : : */ 12 : : // ***************************************************************************** 13 : : 14 : : #include <ostream> 15 : : #include <type_traits> 16 : : 17 : : #include "QuinoaConfig.hpp" 18 : : 19 : : #include "NoWarning/pegtl.hpp" 20 : : 21 : : #ifdef HAS_LUA 22 : : #include "NoWarning/sol.hpp" 23 : : #endif 24 : : 25 : : #include "Print.hpp" 26 : : #include "Tags.hpp" 27 : : #include "Inciter/Types.hpp" 28 : : #include "Inciter/InputDeck/InputDeck.hpp" 29 : : #include "Inciter/InputDeck/Parser.hpp" 30 : : #include "Inciter/InputDeck/Grammar.hpp" 31 : : 32 : : #ifdef HAS_LUA 33 : : #include "Inciter/InputDeck/LuaGrammar.hpp" 34 : : #endif 35 : : 36 : : namespace tk { 37 : : namespace grm { 38 : : 39 : : extern tk::Print g_print; 40 : : 41 : : } // grm:: 42 : : } // tk:: 43 : : 44 : : using inciter::InputDeckParser; 45 : : 46 : 233 : InputDeckParser::InputDeckParser( const tk::Print& print, 47 : : const ctr::CmdLine& cmdline, 48 : 233 : ctr::InputDeck& inputdeck ) : 49 : 233 : FileParser( cmdline.get< tag::io, tag::control >() ) 50 : : // ***************************************************************************** 51 : : // Constructor 52 : : //! \param[in] print Pretty printer 53 : : //! \param[in] cmdline Command line stack 54 : : //! \param[in,out] inputdeck Input deck stack where data is stored during 55 : : //! parsing 56 : : // ***************************************************************************** 57 : : { 58 : : // Create InputDeck (a tagged tuple) to store parsed input 59 [ + - ]: 466 : ctr::InputDeck id( cmdline ); 60 : : 61 : : // Reset parser's output stream to that of print's. This is so that mild 62 : : // warnings emitted during parsing can be output using the pretty printer. 63 : : // Usually, errors and warnings are simply accumulated during parsing and 64 : : // printed during diagnostics after the parser has finished. Howver, in some 65 : : // special cases we can provide a more user-friendly message right during 66 : : // parsing since there is more information available to construct a more 67 : : // sensible message. This is done in e.g., tk::grm::store_option. Resetting 68 : : // the global g_print, to that of passed in as the constructor argument allows 69 : : // not to have to create a new pretty printer, but use the existing one. 70 [ + - ][ + - ]: 233 : tk::grm::g_print.reset( print.save() ); 71 : : 72 : : // Parse input file and populate the underlying tagged tuple 73 [ + - ]: 466 : tao::pegtl::file_input<> in( m_filename ); 74 [ + - ]: 233 : tao::pegtl::parse< deck::read_file, tk::grm::action >( in, id ); 75 : : 76 : : #ifdef HAS_LUA 77 : : // Parse multiple lua ... end blocks as Lua code using Sol2 78 : : std::size_t cnt = 0; 79 : : for (const auto& l : id.get< tag::param, tag::compflow, tag::lua >()) { 80 : : sol::state lua; 81 : : lua.script( l ); 82 : : // Interpret ic ... end block within lua block 83 : : lua::ic< tag::compflow >( lua, cnt, id ); 84 : : ++cnt; 85 : : } 86 : : #endif 87 : : 88 : : // Echo errors and warnings accumulated during parsing 89 [ + - ]: 233 : diagnostics( print, id.get< tag::error >() ); 90 : : 91 : : // Strip input deck (and its underlying tagged tuple) from PEGTL instruments 92 : : // and transfer it out 93 : 233 : inputdeck = std::move( id ); 94 : 233 : }