User Guide
unit_driver.hpp
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 #pragma once
9 
10 #include "units/units.hpp"
11 #include <algorithm>
12 #include <map>
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
17 namespace nmodl {
18 namespace parser {
19 
20 /// flex generated scanner class (extends base lexer class of flex)
21 class UnitLexer;
22 
23 /// parser class generated by bison
24 class UnitParser;
25 
26 /// represent location of the token
27 class location;
28 
29 /**
30  * @addtogroup parser
31  * @addtogroup units
32  * @{
33  */
34 
35 /**
36  * \class UnitDriver
37  * \brief Class that binds all pieces together for parsing C units
38  */
39 class UnitDriver {
40  private:
41  /// pointer to the lexer instance being used
42  UnitLexer* lexer = nullptr;
43 
44  /// pointer to the parser instance being used
45  UnitParser* parser = nullptr;
46 
47  /// print messages from lexer/parser
48  bool verbose = false;
49 
50  public:
51  /// shared pointer to the UnitTable that stores all the unit definitions
52  std::shared_ptr<nmodl::units::UnitTable> table = std::make_shared<nmodl::units::UnitTable>();
53 
54  /// file or input stream name (used by scanner for position), see todo
55  std::string stream_name;
56 
57  /// \name Ctor & dtor
58  /// \{
59 
60  UnitDriver() = default;
61  UnitDriver(bool strace, bool ptrace);
62 
63  /// \}
64 
65  bool parse_stream(std::istream& in);
66  bool parse_string(const std::string& input);
67  bool parse_file(const std::string& filename);
68 
69  void set_verbose(bool b) {
70  verbose = b;
71  }
72 
73  bool is_verbose() const {
74  return verbose;
75  }
76 };
77 
78 } // namespace parser
79 } // namespace nmodl
nmodl::parser::UnitDriver::table
std::shared_ptr< nmodl::units::UnitTable > table
shared pointer to the UnitTable that stores all the unit definitions
Definition: unit_driver.hpp:52
nmodl::parser::UnitDriver::is_verbose
bool is_verbose() const
Definition: unit_driver.hpp:73
nmodl::parser::UnitDriver::lexer
UnitLexer * lexer
pointer to the lexer instance being used
Definition: unit_driver.hpp:42
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
nmodl::parser::UnitDriver::set_verbose
void set_verbose(bool b)
Definition: unit_driver.hpp:69
nmodl::parser::UnitDriver::stream_name
std::string stream_name
file or input stream name (used by scanner for position), see todo
Definition: unit_driver.hpp:55
units.hpp
Classes for storing different units specification.
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::parser::UnitDriver::UnitDriver
UnitDriver()=default
nmodl::parser::UnitDriver::verbose
bool verbose
print messages from lexer/parser
Definition: unit_driver.hpp:48
nmodl::parser::UnitLexer
Represent Lexer/Scanner class for Units parsing.
Definition: unit_lexer.hpp:49
nmodl::parser::UnitDriver
Class that binds all pieces together for parsing C units.
Definition: unit_driver.hpp:39
nmodl::parser::UnitDriver::parser
UnitParser * parser
pointer to the parser instance being used
Definition: unit_driver.hpp:45
nmodl::parser::UnitDriver::parse_file
bool parse_file(const std::string &filename)
parse Units file
Definition: unit_driver.cpp:29
nmodl::parser::UnitDriver::parse_stream
bool parse_stream(std::istream &in)
parse Units file provided as istream
Definition: unit_driver.cpp:18