1 #include <fridh/lexer.hpp>
5 void lexer::parse_comment()
8 multi_line_comment
= ";;",
9 nested_comment_start
= ";.",
10 nested_comment_end
= ".;",
12 multiline_comment_prefix
= "In multi-line comment: ",
13 nested_comment_prefix
= "In nested comment: ";
15 uword start_of_comment
= line
;
17 if(string_match(multi_line_comment
))
20 for(i
+= multi_line_comment
.size(); !got_end
&& i
< end
;)
30 if(string_match(multi_line_comment
))
40 lexer_error("Unable to find the end of a multi-line comment", start_of_comment
);
42 else if(string_match(nested_comment_start
))
44 uword comment_depth
= 1;
45 for(i
+= nested_comment_start
.size(); comment_depth
> 0 && i
< end
;)
53 else if(string_match(nested_comment_start
))
56 i
+= nested_comment_start
.size();
59 else if(string_match(nested_comment_end
))
62 i
+= nested_comment_end
.size();
68 if(comment_depth
!= 0)
69 lexer_error("Unable to find the end of a nested comment", start_of_comment
);
73 std::size_t offset
= input
.find('\n', i
);
74 if(offset
== std::string::npos
)
75 lexer_error("Unable to find the end of a multi-line comment", start_of_comment
);