1 #include <fridh/lexer.hpp>
5 bool lexer::parse_comment(std::string
& error_message
)
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
))
41 error_message
= lexer_error("Unable to find the end of a multi-line comment", start_of_comment
);
45 else if(string_match(nested_comment_start
))
47 uword comment_depth
= 1;
48 for(i
+= nested_comment_start
.size(); comment_depth
> 0 && i
< end
;)
56 else if(string_match(nested_comment_start
))
59 i
+= nested_comment_start
.size();
62 else if(string_match(nested_comment_end
))
65 i
+= nested_comment_end
.size();
71 if(comment_depth
!= 0)
73 error_message
= lexer_error("Unable to find the end of a nested comment", start_of_comment
);
79 std::size_t offset
= input
.find('\n', i
);
80 if(offset
== std::string::npos
)
82 error_message
= lexer_error("Unable to find the end of a multi-line comment", start_of_comment
);