diff --git a/data/test.mod b/data/test.mod index 0f95e7179e48240b43d407a8c654e530672e6c86..bbb8ce41cf9ba422e9513a4387819ef957d1ba4c 100644 --- a/data/test.mod +++ b/data/test.mod @@ -10,8 +10,8 @@ NEURON { } STATE { - h (mA) - m (mV) r (S) + h (nA) + m r } UNITS { diff --git a/modcc/module.cpp b/modcc/module.cpp index c9f749e9ea7a89b1c0dabfa205d03062a3a55111..509d775515ba8ebeb7f1e8dc9918ca772d102d14 100644 --- a/modcc/module.cpp +++ b/modcc/module.cpp @@ -40,6 +40,15 @@ Module::Module(std::vector<char> const& buffer) buffer_.push_back(0); } +Module::Module(const char* buffer, size_t count) +{ + for (auto i = 0; i < count-1 && *buffer != '\0'; ++buffer) { + buffer_.push_back(*buffer); + } + + buffer_.push_back(0); +} + std::vector<Module::symbol_ptr>& Module::procedures() { return procedures_; diff --git a/modcc/module.hpp b/modcc/module.hpp index f427d870ebc1cb770e8e424349d4d140892b3f45..1cd1cfe89b4e31d1bb18e3e3cedb6e173d049ee2 100644 --- a/modcc/module.hpp +++ b/modcc/module.hpp @@ -15,6 +15,7 @@ public : Module(std::string const& fname); Module(std::vector<char> const& buffer); + Module(const char* buffer, size_t count); std::vector<char> const& buffer() const { return buffer_; diff --git a/modcc/parser.hpp b/modcc/parser.hpp index 6768749df46e51181ade05d0d6acb1d4dddbe7c6..b55bede17e698aa9d790211ddbee5a54f90ba56a 100644 --- a/modcc/parser.hpp +++ b/modcc/parser.hpp @@ -39,9 +39,6 @@ public: return error_string_; } -private: - Module *module_; - // functions for parsing descriptive blocks // these are called in the first pass, and do not // construct any AST information @@ -52,6 +49,9 @@ private: void parse_assigned_block(); void parse_title(); +private: + Module *module_; + std::vector<Token> comma_separated_identifiers(); std::vector<Token> unit_description(); @@ -69,4 +69,3 @@ private: bool expect(tok, const char *str=""); bool expect(tok, std::string const& str); }; - diff --git a/tests/modcc/test_parser.cpp b/tests/modcc/test_parser.cpp index 2d09e5703fd2d2344c7f7ddc1da22560d146e3d3..1edfe1a9ad61a0e3837dbddba2877037fb30aee2 100644 --- a/tests/modcc/test_parser.cpp +++ b/tests/modcc/test_parser.cpp @@ -15,7 +15,7 @@ TEST(Parser, full_file) { } TEST(Parser, procedure) { - std::vector< const char*> calls = + std::vector<const char*> calls = { "PROCEDURE foo(x, y) {" " LOCAL a\n" @@ -562,3 +562,39 @@ TEST(Parser, parse_binop) { std::cout << red("error") << p.error_message() << std::endl; } } + +TEST(Parser, parse_state_block) { + std::vector<const char*> state_blocks = { + "STATE {\n" + " h\n" + " m r\n" + "}", + "STATE {\n" + " h (nA)\n" + " m r\n" + "}", + "STATE {\n" + " h (nA)\n" + " m (nA) r\n" + "}", + "STATE {\n" + " h (nA)\n" + " m r (uA)\n" + "}", + "STATE {\n" + " h (nA)\n" + " m (nA) r (uA)\n" + "}" + }; + + for (auto const& str: state_blocks) { + Module m(str, sizeof(str)); + Parser p(m, false); + p.parse_state_block(); + EXPECT_EQ(lexerStatus::happy, p.status()); + if (p.status() == lexerStatus::error) { + std::cout << str << "\n" + << red("error") << p.error_message() << "\n"; + } + } +}