User Guide
main_units.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Blue Brain Project, EPFL.
3  * See the top-level LICENSE file for details.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #include <fstream>
9 
10 #include <CLI/CLI.hpp>
11 
12 #include "config/config.h"
13 #include "parser/unit_driver.hpp"
14 #include "utils/logger.hpp"
15 
16 /**
17  * Standalone parser program for Units. This demonstrate basic
18  * usage of parser and driver class to parse the `nrnunits.lib`
19  * file.
20  *
21  */
22 
23 using namespace nmodl;
24 
25 
26 int main(int argc, const char* argv[]) {
27  CLI::App app{
28  fmt::format("Unit-Parser : Standalone Parser for Units({})", Version::to_string())};
29 
30  std::vector<std::string> units_files;
31  units_files.push_back(NrnUnitsLib::get_path());
32  app.add_option("units_files", units_files, "One or more Units files to process");
33 
34  CLI11_PARSE(app, argc, argv);
35 
36  for (const auto& f: units_files) {
37  logger->info("Processing {}", f);
38  std::ifstream file(f);
39 
40  // driver object creates lexer and parser
42  driver.set_verbose(true);
43 
44  // just call parser method
45  driver.parse_stream(file);
46  driver.table->print_units_sorted(std::cout);
47  }
48 
49  return 0;
50 }
nmodl::parser::UnitDriver::table
std::shared_ptr< nmodl::units::UnitTable > table
shared pointer to the UnitTable that stores all the unit definitions
Definition: unit_driver.hpp:52
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
unit_driver.hpp
nmodl::logger
logger_type logger
Definition: logger.cpp:34
nmodl::parser::UnitDriver::set_verbose
void set_verbose(bool b)
Definition: unit_driver.hpp:69
driver
nmodl::parser::UnitDriver driver
Definition: parser.cpp:28
main
int main(int argc, const char *argv[])
Definition: main_units.cpp:26
nmodl::Version::to_string
static std::string to_string()
return version string (version + git id) as a string
Definition: config.h:39
logger.hpp
Implement logger based on spdlog library.
config.h
Version information and units file path.
nmodl::parser::UnitDriver
Class that binds all pieces together for parsing C units.
Definition: unit_driver.hpp:39
nmodl::NrnUnitsLib::get_path
static std::string get_path()
Return path of units database file.
Definition: config.h:54
nmodl::parser::UnitDriver::parse_stream
bool parse_stream(std::istream &in)
parse Units file provided as istream
Definition: unit_driver.cpp:18