Skip to content
Snippets Groups Projects
Commit eb74bd20 authored by Ben Cumming's avatar Ben Cumming Committed by GitHub
Browse files

Merge pull request #21 from vkarak/feature/modcc/qmark-comments

modcc: support for comments starting with '?'
parents 822d8cae 6736546f
No related branches found
No related tags found
No related merge requests found
: sample file : sample file
? another style of comments
NEURON { NEURON {
THREADSAFE THREADSAFE
...@@ -26,7 +27,7 @@ PARAMETER { ...@@ -26,7 +27,7 @@ PARAMETER {
gkbar = 0.1 (mho/cm2) gkbar = 0.1 (mho/cm2)
celsius celsius
ek = -100 (mV) : must be explicitly def. in hoc ek = -100 (mV) : must be explicitly def. in hoc
v (mV) v (mV) ? another style of comment
vhalfm =-43 (mV) vhalfm =-43 (mV)
km =8 km =8
vhalfh =-67 (mV) vhalfh =-67 (mV)
......
...@@ -78,8 +78,9 @@ Token Lexer::parse() { ...@@ -78,8 +78,9 @@ Token Lexer::parse() {
location_.line++; location_.line++;
continue; // skip to next line continue; // skip to next line
// comment (everything after : on a line is a comment) // comment (everything after : or ? on a line is a comment)
case ':' : case ':' :
case '?' :
// strip characters until either end of file or end of line // strip characters until either end of file or end of line
while( !is_eof(*current_) && *current_ != '\n') { while( !is_eof(*current_) && *current_ != '\n') {
++current_; ++current_;
......
...@@ -31,7 +31,7 @@ bool is_keyword(Token const& t); ...@@ -31,7 +31,7 @@ bool is_keyword(Token const& t);
// takes a range of characters as input parameters // takes a range of characters as input parameters
class Lexer { class Lexer {
public: public:
Lexer(const char * begin, const char* end) Lexer(const char* begin, const char* end)
: begin_(begin), : begin_(begin),
end_(end), end_(end),
current_(begin), current_(begin),
...@@ -114,4 +114,3 @@ protected: ...@@ -114,4 +114,3 @@ protected:
Token token_; Token token_;
}; };
...@@ -205,7 +205,9 @@ TEST(Lexer, braces) { ...@@ -205,7 +205,9 @@ TEST(Lexer, braces) {
// test comments // test comments
TEST(Lexer, 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 PRINT_LEX_STRING
Lexer lexer(string, string+sizeof(string)); Lexer lexer(string, string+sizeof(string));
...@@ -218,7 +220,12 @@ TEST(Lexer, comments) { ...@@ -218,7 +220,12 @@ TEST(Lexer, comments) {
EXPECT_EQ(t2.location.line, 2); EXPECT_EQ(t2.location.line, 2);
auto t3 = lexer.parse(); 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 // test numbers
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment