User Guide
nmodl::parser::NmodlDriver Class Reference

Class that binds all pieces together for parsing nmodl file. More...

Detailed Description

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.

Todo:
Lexer, parser and ast member variables are used inside lexer/ parser instances. The local instaces are created inside parse_stream and hence the pointers are no longer valid except ast. Need better way to handle this.
Todo:
Stream name is not used as it will need better support as location object used in scanner takes string pointer which could be invalid when we copy location object.

Definition at line 67 of file nmodl_driver.hpp.

#include <nmodl_driver.hpp>

Inheritance diagram for nmodl::parser::NmodlDriver:
nmodl::PyNmodlDriver

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::Programparse_stream (std::istream &in)
 parse nmodl file provided as istream More...
 
std::shared_ptr< ast::Programparse_string (const std::string &input)
 parser nmodl provided as string (used for testing) More...
 
std::shared_ptr< ast::Programparse_file (const std::filesystem::path &filename, const location *loc=nullptr)
 parse NMODL file More...
 
std::shared_ptr< ast::Includeparse_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::ProgramastRoot = 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...
 

Constructor & Destructor Documentation

◆ NmodlDriver() [1/2]

nmodl::parser::NmodlDriver::NmodlDriver ( )
default

◆ NmodlDriver() [2/2]

nmodl::parser::NmodlDriver::NmodlDriver ( bool  strace,
bool  ptrace 
)

Definition at line 21 of file nmodl_driver.cpp.

Member Function Documentation

◆ add_defined_var()

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.

◆ check_include_argument()

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:

  • between double-quotes
  • not empty ""
Returns
unquoted string

Definition at line 168 of file nmodl_driver.cpp.

◆ get_ast()

const std::shared_ptr<ast::Program>& nmodl::parser::NmodlDriver::get_ast ( ) const
inlinenoexcept

return previously parsed AST otherwise nullptr

Definition at line 136 of file nmodl_driver.hpp.

◆ get_defined_var_value()

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.

◆ is_defined_var()

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.

◆ is_verbose()

bool nmodl::parser::NmodlDriver::is_verbose ( ) const
inlinenoexcept

Definition at line 131 of file nmodl_driver.hpp.

◆ parse_error() [1/2]

void nmodl::parser::NmodlDriver::parse_error ( const location &  location,
const std::string &  message 
)

Emit a parsing error.

Exceptions
std::runtime_error

Definition at line 149 of file nmodl_driver.cpp.

◆ parse_error() [2/2]

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

Exceptions
std::runtime_error

Definition at line 155 of file nmodl_driver.cpp.

◆ parse_file()

std::shared_ptr< ast::Program > nmodl::parser::NmodlDriver::parse_file ( const std::filesystem::path &  filename,
const location *  loc = nullptr 
)

parse NMODL file

Parameters
filenamepath to the file to parse
locoptional location when filename is dictated by an INCLUDE NMODL directive.

Definition at line 43 of file nmodl_driver.cpp.

◆ parse_include()

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.

◆ parse_stream()

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.

◆ parse_string()

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.

◆ set_ast()

void nmodl::parser::NmodlDriver::set_ast ( ast::Program node)
inlinenoexcept

set new ast root

Definition at line 141 of file nmodl_driver.hpp.

◆ set_verbose()

void nmodl::parser::NmodlDriver::set_verbose ( bool  b)
inline

Definition at line 127 of file nmodl_driver.hpp.

Member Data Documentation

◆ astRoot

std::shared_ptr<ast::Program> nmodl::parser::NmodlDriver::astRoot = nullptr
private

root of the ast

Definition at line 82 of file nmodl_driver.hpp.

◆ defined_var

std::unordered_map<std::string, int> nmodl::parser::NmodlDriver::defined_var
private

all macro defined in the mod file

Definition at line 70 of file nmodl_driver.hpp.

◆ library

FileLibrary nmodl::parser::NmodlDriver::library {FileLibrary::default_instance()}
private

The file library for IMPORT directives.

Definition at line 85 of file nmodl_driver.hpp.

◆ open_files

std::unordered_map<std::string, const location*> nmodl::parser::NmodlDriver::open_files
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.

◆ parser_stream

std::ostringstream nmodl::parser::NmodlDriver::parser_stream
private

The stream where Bison will dump its logs.

Definition at line 92 of file nmodl_driver.hpp.

◆ stream_name

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.

◆ trace_parser

bool nmodl::parser::NmodlDriver::trace_parser = true
private

enable debug output in the bison parser

Definition at line 76 of file nmodl_driver.hpp.

◆ trace_scanner

bool nmodl::parser::NmodlDriver::trace_scanner = false
private

enable debug output in the flex scanner

Definition at line 73 of file nmodl_driver.hpp.

◆ verbose

bool nmodl::parser::NmodlDriver::verbose = false
private

print messages from lexer/parser

Definition at line 79 of file nmodl_driver.hpp.


The documentation for this class was generated from the following files: