Branch data Line data Source code
1 : : // ***************************************************************************** 2 : : /*! 3 : : \file src/Control/RNGTest/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 Random number generator test suite input deck parser 9 : : \details This file defines the input deck, i.e., control file, parser for 10 : : the random number generator test suite, RNGTest. 11 : : */ 12 : : // ***************************************************************************** 13 : : 14 : : #include <ostream> 15 : : #include <type_traits> 16 : : 17 : : #include "NoWarning/pegtl.hpp" 18 : : 19 : : #include "Print.hpp" 20 : : #include "Tags.hpp" 21 : : #include "RNGTest/Types.hpp" 22 : : #include "RNGTest/InputDeck/InputDeck.hpp" 23 : : #include "RNGTest/InputDeck/Parser.hpp" 24 : : #include "RNGTest/InputDeck/Grammar.hpp" 25 : : 26 : : namespace tk { 27 : : namespace grm { 28 : : 29 : : extern tk::Print g_print; 30 : : 31 : : } // grm:: 32 : : } // tk:: 33 : : 34 : : using rngtest::InputDeckParser; 35 : : 36 : 4 : InputDeckParser::InputDeckParser( const tk::Print& print, 37 : : const ctr::CmdLine& cmdline, 38 : 4 : ctr::InputDeck& inputdeck ) : 39 : 4 : FileParser( cmdline.get< tag::io, tag::control >() ) 40 : : // ***************************************************************************** 41 : : // Constructor 42 : : //! \param[in] print Pretty printer 43 : : //! \param[in] cmdline Command line stack 44 : : //! \param[in,out] inputdeck Input deck stack where data is stored during 45 : : //! parsing 46 : : // ***************************************************************************** 47 : : { 48 : : // Create InputDeck (a tagged tuple) to store parsed input 49 [ + - ]: 4 : 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 [ + - ]: 4 : tk::grm::g_print.reset( print.save() ); 61 : : 62 : : // Parse input file and populate the underlying tagged tuple 63 [ + - ]: 4 : tao::pegtl::file_input<> in( m_filename ); 64 : : tao::pegtl::parse< deck::read_file, tk::grm::action >( in, id ); 65 : : 66 : : // Echo errors and warnings accumulated during parsing 67 [ + - ]: 4 : 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 : : inputdeck = std::move( id ); 72 : 4 : }