![]() |
User Guide
|
Class that binds all pieces together for parsing nmodl file. More...
Class that binds all pieces together for parsing nmodl file.
Driver class bind components required for lexing, parsing and ast generation from nmodl file. We create an instance of lexer, parser and provides different methods to parse from file, stream or string. The scanner also gets reference to driver object for two purposes : scanner store/query the macro definitions into/from driver class and erros can be propogated back to driver (not implemented yet). Parser class also gets a reference to driver class as a parameter. Parsing actions generate ast and it's pointer is stored in driver class.
Definition at line 67 of file nmodl_driver.hpp.
#include <nmodl_driver.hpp>
Public Member Functions | |
NmodlDriver ()=default | |
NmodlDriver (bool strace, bool ptrace) | |
void | add_defined_var (const std::string &name, int value) |
add macro definition and it's value (DEFINE keyword of nmodl) More... | |
bool | is_defined_var (const std::string &name) const |
check if particular text is defined as macro More... | |
int | get_defined_var_value (const std::string &name) const |
return variable's value defined as macro (always an integer) More... | |
std::shared_ptr< ast::Program > | parse_stream (std::istream &in) |
parse nmodl file provided as istream More... | |
std::shared_ptr< ast::Program > | parse_string (const std::string &input) |
parser nmodl provided as string (used for testing) More... | |
std::shared_ptr< ast::Program > | parse_file (const std::filesystem::path &filename, const location *loc=nullptr) |
parse NMODL file More... | |
std::shared_ptr< ast::Include > | parse_include (const std::filesystem::path &filename, const location &loc) |
void | set_verbose (bool b) |
bool | is_verbose () const noexcept |
const std::shared_ptr< ast::Program > & | get_ast () const noexcept |
return previously parsed AST otherwise nullptr More... | |
void | set_ast (ast::Program *node) noexcept |
set new ast root More... | |
void | parse_error (const location &location, const std::string &message) |
Emit a parsing error. More... | |
void | parse_error (const NmodlLexer &scanner, const location &location, const std::string &message) |
Emit a parsing error. More... | |
std::string | check_include_argument (const location &location, const std::string &filename) |
Ensure file argument given to the INCLUDE directive is valid: More... | |
Public Attributes | |
std::string | stream_name |
file or input stream name (used by scanner for position), see todo More... | |
Private Attributes | |
std::unordered_map< std::string, int > | defined_var |
all macro defined in the mod file More... | |
bool | trace_scanner = false |
enable debug output in the flex scanner More... | |
bool | trace_parser = true |
enable debug output in the bison parser More... | |
bool | verbose = false |
print messages from lexer/parser More... | |
std::shared_ptr< ast::Program > | astRoot = nullptr |
root of the ast More... | |
FileLibrary | library {FileLibrary::default_instance()} |
The file library for IMPORT directives. More... | |
std::unordered_map< std::string, const location * > | open_files |
The list of open files, and the location of the request. More... | |
std::ostringstream | parser_stream |
The stream where Bison will dump its logs. More... | |
|
default |
nmodl::parser::NmodlDriver::NmodlDriver | ( | bool | strace, |
bool | ptrace | ||
) |
Definition at line 21 of file nmodl_driver.cpp.
void nmodl::parser::NmodlDriver::add_defined_var | ( | const std::string & | name, |
int | value | ||
) |
add macro definition and it's value (DEFINE keyword of nmodl)
Definition at line 133 of file nmodl_driver.cpp.
std::string nmodl::parser::NmodlDriver::check_include_argument | ( | const location & | location, |
const std::string & | filename | ||
) |
Ensure file argument given to the INCLUDE directive is valid:
Definition at line 168 of file nmodl_driver.cpp.
|
inlinenoexcept |
return previously parsed AST otherwise nullptr
Definition at line 136 of file nmodl_driver.hpp.
int nmodl::parser::NmodlDriver::get_defined_var_value | ( | const std::string & | name | ) | const |
return variable's value defined as macro (always an integer)
Definition at line 141 of file nmodl_driver.cpp.
bool nmodl::parser::NmodlDriver::is_defined_var | ( | const std::string & | name | ) | const |
check if particular text is defined as macro
Definition at line 137 of file nmodl_driver.cpp.
|
inlinenoexcept |
Definition at line 131 of file nmodl_driver.hpp.
void nmodl::parser::NmodlDriver::parse_error | ( | const location & | location, |
const std::string & | message | ||
) |
Emit a parsing error.
std::runtime_error |
Definition at line 149 of file nmodl_driver.cpp.
void nmodl::parser::NmodlDriver::parse_error | ( | const NmodlLexer & | scanner, |
const location & | location, | ||
const std::string & | message | ||
) |
Emit a parsing error.
Takes additionally a Lexer instance to print code context
std::runtime_error |
Definition at line 155 of file nmodl_driver.cpp.
std::shared_ptr< ast::Program > nmodl::parser::NmodlDriver::parse_file | ( | const std::filesystem::path & | filename, |
const location * | loc = nullptr |
||
) |
parse NMODL file
filename | path to the file to parse |
loc | optional location when filename is dictated by an INCLUDE NMODL directive. |
Definition at line 43 of file nmodl_driver.cpp.
std::shared_ptr< ast::Include > nmodl::parser::NmodlDriver::parse_include | ( | const std::filesystem::path & | filename, |
const location & | loc | ||
) |
Definition at line 95 of file nmodl_driver.cpp.
std::shared_ptr< ast::Program > nmodl::parser::NmodlDriver::parse_stream | ( | std::istream & | in | ) |
parse nmodl file provided as istream
Definition at line 26 of file nmodl_driver.cpp.
std::shared_ptr< ast::Program > nmodl::parser::NmodlDriver::parse_string | ( | const std::string & | input | ) |
parser nmodl provided as string (used for testing)
Definition at line 89 of file nmodl_driver.cpp.
|
inlinenoexcept |
set new ast root
Definition at line 141 of file nmodl_driver.hpp.
|
inline |
Definition at line 127 of file nmodl_driver.hpp.
|
private |
root of the ast
Definition at line 82 of file nmodl_driver.hpp.
|
private |
all macro defined in the mod file
Definition at line 70 of file nmodl_driver.hpp.
|
private |
The file library for IMPORT directives.
Definition at line 85 of file nmodl_driver.hpp.
|
private |
The list of open files, and the location of the request.
nullptr is pushed as location for the top NMODL file
Definition at line 89 of file nmodl_driver.hpp.
|
private |
The stream where Bison will dump its logs.
Definition at line 92 of file nmodl_driver.hpp.
std::string nmodl::parser::NmodlDriver::stream_name |
file or input stream name (used by scanner for position), see todo
Definition at line 96 of file nmodl_driver.hpp.
|
private |
enable debug output in the bison parser
Definition at line 76 of file nmodl_driver.hpp.
|
private |
enable debug output in the flex scanner
Definition at line 73 of file nmodl_driver.hpp.
|
private |
print messages from lexer/parser
Definition at line 79 of file nmodl_driver.hpp.