Branch data Line data Source code
1 : : // ***************************************************************************** 2 : : /*! 3 : : \file src/Control/Walker/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 Walker's input deck file parser 9 : : \details Walker's input deck file parser 10 : : */ 11 : : // ***************************************************************************** 12 : : 13 : : #include <ostream> 14 : : #include <vector> 15 : : #include <type_traits> 16 : : 17 : : #include "NoWarning/pegtl.hpp" 18 : : 19 : : #include "Print.hpp" 20 : : #include "Tags.hpp" 21 : : #include "ContainerUtil.hpp" 22 : : #include "Walker/Types.hpp" 23 : : #include "Walker/InputDeck/InputDeck.hpp" 24 : : #include "Walker/InputDeck/Parser.hpp" 25 : : #include "Walker/InputDeck/Grammar.hpp" 26 : : 27 : : namespace tk { 28 : : namespace grm { 29 : : 30 : : extern tk::Print g_print; 31 : : 32 : : } // grm:: 33 : : } // tk:: 34 : : 35 : : using walker::InputDeckParser; 36 : : 37 : 74 : InputDeckParser::InputDeckParser( const tk::Print& print, 38 : : const ctr::CmdLine& cmdline, 39 : 74 : ctr::InputDeck& inputdeck ) : 40 : 74 : FileParser( cmdline.get< tag::io, tag::control >() ) 41 : : // ***************************************************************************** 42 : : // Constructor 43 : : //! \param[in] print Pretty printer 44 : : //! \param[in] cmdline Command line stack 45 : : //! \param[inout] inputdeck Input deck stack where data is stored during parsing 46 : : // ***************************************************************************** 47 : : { 48 : : // Create InputDeck (a tagged tuple) to store parsed input 49 [ + - ]: 148 : ctr::InputDeck id( cmdline ); 50 : : 51 : : // Reset parser's output stream to that of print's. This is so that mild 52 : : // warnings emitted during parsing can be output using the pretty printer. 53 : : // Usually, errors and warnings are simply accumulated during parsing and 54 : : // printed during diagnostics after the parser has finished. Howver, in some 55 : : // special cases we can provide a more user-friendly message right during 56 : : // parsing since there is more information available to construct a more 57 : : // sensible message. This is done in e.g., tk::grm::store_option. Resetting 58 : : // the global g_print, to that of passed in as the constructor argument allows 59 : : // not to have to create a new pretty printer, but use the existing one. 60 [ + - ][ + - ]: 74 : tk::grm::g_print.reset( print.save() ); 61 : : 62 : : // Parse input file and populate the underlying tagged tuple 63 [ + - ]: 148 : tao::pegtl::file_input<> in( m_filename ); 64 [ + - ]: 74 : tao::pegtl::parse< deck::read_file, tk::grm::action >( in, id ); 65 : : 66 : : // Echo errors and warnings accumulated during parsing 67 [ + - ]: 74 : diagnostics( print, id.get< tag::error >() ); 68 : : 69 : : // Strip input deck (and its underlying tagged tuple) from PEGTL instruments 70 : : // and transfer it out 71 : 74 : inputdeck = std::move( id ); 72 : : 73 : : // Filter out repeated statistics 74 [ + - ]: 74 : tk::unique( inputdeck.get< tag::stat >() ); 75 : 74 : }