11 #include <CLI/CLI.hpp>
14 #include "config/config.h"
17 #include "utils/logger.hpp"
31 using parser::NmodlDriver;
32 using parser::NmodlLexer;
34 using Token = parser::NmodlParser::token;
39 std::istringstream in(mod_text);
47 auto get_token_type = [](
TokenType token) {
48 return parser::NmodlParser::by_type(token).type_get();
56 if (
token_type == get_token_type(Token::END)) {
66 if (
token_type == get_token_type(Token::NAME) ||
69 token_type == get_token_type(Token::VALENCE) ||
72 std::cout << *(
value.get_token()) << std::endl;
75 else if (
token_type == get_token_type(Token::PRIME)) {
77 std::cout << *(
value.get_token()) << std::endl;
80 else if (
token_type == get_token_type(Token::INTEGER)) {
82 std::cout << *(
value.get_token()) << std::endl;
85 else if (
token_type == get_token_type(Token::REAL)) {
87 std::cout << *(
value.get_token()) << std::endl;
92 std::cout << *(
value.get_token()) << std::endl;
95 else if (
token_type == get_token_type(Token::VERBATIM) ||
96 token_type == get_token_type(Token::BLOCK_COMMENT) ||
97 token_type == get_token_type(Token::LINE_PART)) {
98 auto str = sym.
value.as<std::string>();
99 std::cout << str << std::endl;
103 auto token = sym.value.as<
ModToken>();
104 std::cout << token << std::endl;
113 CLI::App app{fmt::format(
"NMODL-Lexer : Standalone Lexer for NMODL Code({})",
116 std::vector<std::string> mod_files;
117 std::vector<std::string> mod_texts;
119 app.add_option(
"file", mod_files,
"One or more NMODL files")->check(CLI::ExistingFile);
120 app.add_option(
"--text", mod_texts,
"One or more NMODL constructs as text");
124 for (
const auto& file: mod_files) {
126 std::ifstream f(file);
127 std::string mod{std::istreambuf_iterator<char>{f}, {}};
131 for (
const auto&
text: mod_texts) {
Auto generated AST classes declaration.
Represent token returned by scanner.
Represents a double variable.
Represents an integer variable.
Represents a prime variable (for ODE)
std::string value
Value of string.
Class that binds all pieces together for parsing nmodl file.
Represent Lexer/Scanner class for NMODL language parsing.
virtual NmodlParser::symbol_type next_token()
Function for lexer to scan token (replacement for yylex())
void symbol_type(const std::string &name, T &value)
int main(int argc, const char *argv[])
encapsulates code generation backend implementations
void tokenize(const std::string &mod_text)
parser::NmodlParser::symbol_type SymbolType
TokenType token_type(const std::string &name)
Return token type for given token name.
parser::NmodlParser::token Token
parser::NmodlParser::token_type TokenType
static std::string to_string()
return version string (version + git id) as a string
nmodl::parser::UnitDriver driver