diff --git a/data/test.mod b/data/test.mod index 9ab7868500498e2232327d7ec17fbda32ae3dc21..d7403c791f390dacf899fe6a32429ad4b5f4096d 100644 --- a/data/test.mod +++ b/data/test.mod @@ -1,4 +1,5 @@ : sample file +? another style of comments NEURON { THREADSAFE @@ -26,7 +27,7 @@ PARAMETER { gkbar = 0.1 (mho/cm2) celsius ek = -100 (mV) : must be explicitly def. in hoc - v (mV) + v (mV) ? another style of comment vhalfm =-43 (mV) km =8 vhalfh =-67 (mV) diff --git a/modcc/lexer.cpp b/modcc/lexer.cpp index b4b8ccf936b7d028f79353afbbb4c05864c4478b..ea371d104ea9c283a3dd47ca73636da18b2a7b65 100644 --- a/modcc/lexer.cpp +++ b/modcc/lexer.cpp @@ -78,8 +78,9 @@ Token Lexer::parse() { location_.line++; continue; // skip to next line - // comment (everything after : on a line is a comment) - case ':' : + // comment (everything after : or ? on a line is a comment) + case ':' : + case '?' : // strip characters until either end of file or end of line while( !is_eof(*current_) && *current_ != '\n') { ++current_; diff --git a/modcc/lexer.hpp b/modcc/lexer.hpp index a998287fabcf2edddc7c96b43675a1509ff41dbb..52917e94477a09173d7e580ea067f9e7b691f2ed 100644 --- a/modcc/lexer.hpp +++ b/modcc/lexer.hpp @@ -31,7 +31,7 @@ bool is_keyword(Token const& t); // takes a range of characters as input parameters class Lexer { public: - Lexer(const char * begin, const char* end) + Lexer(const char* begin, const char* end) : begin_(begin), end_(end), current_(begin), @@ -114,4 +114,3 @@ protected: Token token_; }; - diff --git a/tests/modcc/test_lexer.cpp b/tests/modcc/test_lexer.cpp index dacfe8c6e910f6beea2d44e0eb715a4c6fb1b672..091a752b4ee0f25ea929bed86129ba7efc41e573 100644 --- a/tests/modcc/test_lexer.cpp +++ b/tests/modcc/test_lexer.cpp @@ -205,7 +205,9 @@ TEST(Lexer, braces) { // test comments TEST(Lexer, comments) { - char string[] = "foo:this is one line\nbar : another comment\n"; + char string[] = "foo:this is one line\n" + "bar : another comment\n" + "foobar ? another comment\n"; PRINT_LEX_STRING Lexer lexer(string, string+sizeof(string)); @@ -218,7 +220,12 @@ TEST(Lexer, comments) { EXPECT_EQ(t2.location.line, 2); auto t3 = lexer.parse(); - EXPECT_EQ(t3.type, tok::eof); + EXPECT_EQ(t3.type, tok::identifier); + EXPECT_EQ(t3.spelling, "foobar"); + EXPECT_EQ(t3.location.line, 3); + + auto t4 = lexer.parse(); + EXPECT_EQ(t4.type, tok::eof); } // test numbers