11 #include <CLI/CLI.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;
90 else if (
token_type == get_token_type(Token::STRING)) {
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;
112 int main(
int argc,
const char* argv[]) {
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");
122 CLI11_PARSE(app, argc, argv);
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) {