Лмао, Адель, харе carriage return ставить в конце каждой строки(((
This commit is contained in:
		
							parent
							
								
									2e0dbf8bfe
								
							
						
					
					
						commit
						177a64bdb8
					
				| @ -43,7 +43,7 @@ namespace nytl { | ||||
|     } | ||||
| 
 | ||||
|     bool isSPACE(char ch) { | ||||
|         return ch == ' ' || ch == '\r' || ch == '\t' || ch == '\r'; | ||||
|         return ch == ' ' || ch == '\r' || ch == '\t' || ch == '\n'; | ||||
|     } | ||||
| 
 | ||||
|     bool isUname(const std::string &str) { | ||||
|  | ||||
| @ -26,7 +26,8 @@ namespace nytl { | ||||
| 
 | ||||
|     std::vector<std::string> splitIntoLines(const std::string& str); | ||||
|     std::string concatenateLines(const std::vector<std::string>& lines); | ||||
| 
 | ||||
|     void one_part_update_min_start_wsp_non_empty(const std::string& str, bool is_first, size_t& min); | ||||
|     std::string one_part_cut_excess_tab(const std::string& str, bool is_first, size_t cut); | ||||
| 
 | ||||
|     void parse_bare_file(const std::string& filename, const std::string& content, | ||||
|         global_elem_set_t& result); | ||||
|  | ||||
| @ -34,54 +34,6 @@ namespace nytl { | ||||
|         return ""; | ||||
|     } | ||||
| 
 | ||||
|     void parse_bare_file(const std::string& filename, const std::string& content, | ||||
|                          global_elem_set_t& result) | ||||
|     { | ||||
|         ASSERT(result.count(filename) == 0, "Repeated element " + filename); | ||||
|         std::vector<std::string> lines; | ||||
|         bool had_nw_line = false; | ||||
|         size_t smallest_tab; | ||||
|         std::string current_line; | ||||
|         auto finish = [&]() { | ||||
|             size_t tab_sz = first_nw_char(current_line); | ||||
|             if (tab_sz == current_line.size()) { | ||||
|                 if (had_nw_line) | ||||
|                     lines.emplace_back(); | ||||
|             } else { | ||||
|                 if (had_nw_line) { | ||||
|                     if (smallest_tab > tab_sz) | ||||
|                         smallest_tab = tab_sz; | ||||
|                 } else { | ||||
|                     smallest_tab = tab_sz; | ||||
|                     had_nw_line = true; | ||||
|                 } | ||||
|                 lines.push_back(current_line); | ||||
|             } | ||||
|             current_line.clear(); | ||||
|         }; | ||||
|         for (char ch: content) { | ||||
|             if (ch == '\n') { | ||||
|                 finish(); | ||||
|             } else { | ||||
|                 current_line += ch; | ||||
|             } | ||||
|         } | ||||
|         finish(); | ||||
|         while (!lines.empty() && lines.back().empty()) | ||||
|             lines.pop_back(); | ||||
| 
 | ||||
|         for (std::string& line: lines) { | ||||
|             if (!line.empty()) { | ||||
|                 assert(line.size() > smallest_tab); | ||||
|                 line = line.substr(smallest_tab); | ||||
|             } | ||||
|         } | ||||
|         Element& el = result[filename]; | ||||
|         el.parts = {ElementPart{element_part_types::code}}; | ||||
|         std::string lines_cat = concatenateLines(lines); | ||||
|         el.parts[0].when_code.lines = mv(lines_cat); | ||||
|     } | ||||
| 
 | ||||
|     int peep(ParsingContext &ctx) { | ||||
|         if (ctx.text.size() <= ctx.pos) | ||||
|             return EOFVAL; | ||||
| @ -115,7 +67,7 @@ namespace nytl { | ||||
|     } | ||||
| 
 | ||||
|     std::vector<std::string> splitIntoLines(const std::string &str) { | ||||
|         std::vector<std::string> result; | ||||
|         std::vector<std::string> result = {""}; | ||||
|         for (char ch: str) { | ||||
|             if (ch == '\n') | ||||
|                 result.emplace_back(); | ||||
| @ -136,9 +88,43 @@ namespace nytl { | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
|     void one_part_update_min_start_wsp_non_empty(const std::string& str, bool is_first, size_t& min) { | ||||
|         std::vector<std::string> lines = splitIntoLines(str); | ||||
|         size_t L = lines.size(); | ||||
|         for (size_t i = is_first ? 0 : 1; i < L; i++) { | ||||
|             size_t first_nw = first_nw_char(lines[i]); | ||||
|             if (first_nw < lines[i].size()) | ||||
|                 min = std::min(min, first_nw); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     std::string one_part_cut_excess_tab(const std::string& str, bool is_first, size_t cut) { | ||||
|         std::vector<std::string> lines = splitIntoLines(str); | ||||
|         size_t L = lines.size(); | ||||
|         for (size_t i = is_first ? 0 : 1; i < L; i++) { | ||||
|             if (!is_space_only(lines[i])) | ||||
|                 lines[i] = lines[i].substr(cut); | ||||
|         } | ||||
|         return concatenateLines(lines); | ||||
|     } | ||||
| 
 | ||||
|     void parse_bare_file(const std::string& filename, const std::string& content, | ||||
|                              global_elem_set_t& result) | ||||
|     { | ||||
|         ASSERT(result.count(filename) == 0, "Repeated element " + filename); | ||||
|         std::string P = clement_lstrip(content); | ||||
|         rstrip(P); | ||||
|         size_t cut = 9999999999999; | ||||
|         one_part_update_min_start_wsp_non_empty(P, true, cut); | ||||
|         P = one_part_cut_excess_tab(P, true, cut); | ||||
|         Element& el = result[filename]; | ||||
|         el.parts = {ElementPart{element_part_types::code}}; | ||||
|         el.parts[0].when_code.lines = mv(P); | ||||
|     } | ||||
| 
 | ||||
|     void parse_special_file(const std::string& filename, const std::string& content, | ||||
|         std::map<std::string, Element>& result) | ||||
|     { | ||||
|         THROW("Don't know how to parse it yet"); | ||||
|         // THROW("Don't know how to parse it yet");
 | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -11,7 +11,7 @@ int main(int argc, char** argv) { | ||||
|     std::string dir_path = argv[1]; | ||||
|     nytl::Templater templater(nytl::TemplaterSettings{nytl::TemplaterDetourRules{dir_path}}); | ||||
|     templater.update(); | ||||
|     std::string answer = templater.render("chat", {}); | ||||
|     std::string answer = templater.render("list-rooms", {}); | ||||
|     printf("%s\n<a><f><t><e><r><><l><f>\n", answer.c_str()); | ||||
|     std::string answer2 = templater.render("test", {}); | ||||
|     printf("%s\n<a><f><t><e><r><><l><f>\n", answer.c_str()); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user