User Guide
main_nmodl.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 <CLI/CLI.hpp>
9 
10 #include "ast/program.hpp"
11 #include "config/config.h"
12 #include "parser/nmodl_driver.hpp"
13 #include "utils/logger.hpp"
14 
15 /**
16  * Standalone parser program for NMODL. This demonstrate
17  * basic usage of parser and driver classes.
18  */
19 
20 using namespace nmodl;
21 
22 int main(int argc, const char* argv[]) {
23  CLI::App app{
24  fmt::format("NMODL-Parser : Standalone Parser for NMODL({})", Version::to_string())};
25 
26  std::vector<std::string> mod_files;
27  std::vector<std::string> mod_texts;
28 
29  app.add_option("file", mod_files, "One or more NMODL files")->check(CLI::ExistingFile);
30  app.add_option("--text", mod_texts, "One or more NMODL constructs as text");
31 
32  CLI11_PARSE(app, argc, argv);
33 
35  driver.set_verbose(true);
36 
37  for (const auto& f: mod_files) {
38  logger->info("Processing file : {}", f);
39  driver.parse_file(f);
40  }
41 
42  for (const auto& text: mod_texts) {
43  logger->info("Processing text : {}", text);
44  driver.parse_string(text);
45  }
46 
47  return 0;
48 }
nmodl::parser::NmodlDriver
Class that binds all pieces together for parsing nmodl file.
Definition: nmodl_driver.hpp:67
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
nmodl::logger
logger_type logger
Definition: logger.cpp:34
nmodl::parser::UnitDriver::set_verbose
void set_verbose(bool b)
Definition: unit_driver.hpp:69
program.hpp
Auto generated AST classes declaration.
driver
nmodl::parser::UnitDriver driver
Definition: parser.cpp:28
nmodl::parser::UnitDriver::parse_string
bool parse_string(const std::string &input)
parser Units provided as string (used for testing)
Definition: unit_driver.cpp:40
nmodl::Version::to_string
static std::string to_string()
return version string (version + git id) as a string
Definition: config.h:39
main
int main(int argc, const char *argv[])
Definition: main_nmodl.cpp:112
logger.hpp
Implement logger based on spdlog library.
nmodl_driver.hpp
config.h
Version information and units file path.
nmodl::parser::UnitDriver::parse_file
bool parse_file(const std::string &filename)
parse Units file
Definition: unit_driver.cpp:29