Ticket #3029: quickbook.patch
File quickbook.patch, 6.9 KB (added by , 13 years ago) |
---|
-
detail/actions.cpp
968 968 out << "\" />\n"; 969 969 } 970 970 971 void c pp_code_snippet_grammar::pass_thru(iterator first, iterator last) const971 void code_snippet_grammar::pass_thru(iterator first, iterator last) const 972 972 { 973 973 code += *first; 974 974 } … … 978 978 int callout_id = 0; 979 979 } 980 980 981 void c pp_code_snippet_grammar::callout(iterator first, iterator last, char const* role) const981 void code_snippet_grammar::callout(iterator first, iterator last, char const* role) const 982 982 { 983 983 using detail::callout_id; 984 984 code += "``'''"; … … 993 993 callouts.push_back(std::string(first, last)); 994 994 } 995 995 996 void c pp_code_snippet_grammar::inline_callout(iterator first, iterator last) const996 void code_snippet_grammar::inline_callout(iterator first, iterator last) const 997 997 { 998 998 callout(first, last, "callout_bug"); 999 999 } 1000 1000 1001 void c pp_code_snippet_grammar::line_callout(iterator first, iterator last) const1001 void code_snippet_grammar::line_callout(iterator first, iterator last) const 1002 1002 { 1003 1003 callout(first, last, "line_callout_bug"); 1004 1004 } 1005 1005 1006 void c pp_code_snippet_grammar::escaped_comment(iterator first, iterator last) const1006 void code_snippet_grammar::escaped_comment(iterator first, iterator last) const 1007 1007 { 1008 1008 if (!code.empty()) 1009 1009 { … … 1022 1022 } 1023 1023 } 1024 1024 1025 void c pp_code_snippet_grammar::compile(iterator first, iterator last) const1025 void code_snippet_grammar::compile(iterator first, iterator last) const 1026 1026 { 1027 1027 using detail::callout_id; 1028 1028 if (!code.empty()) … … 1081 1081 iterator_type first(code.begin(), code.end(), file); 1082 1082 iterator_type last(code.end(), code.end()); 1083 1083 1084 cpp_code_snippet_grammar g(storage, doc_id); 1084 size_t fname_len = file.size(); 1085 bool is_python = file[--fname_len]=='y' && file[--fname_len]=='p'; 1086 code_snippet_grammar g(storage, doc_id, is_python); 1085 1087 // TODO: Should I check that parse succeeded? 1086 1088 boost::spirit::classic::parse(first, last, g); 1087 1089 -
code_snippet.hpp
15 15 16 16 namespace quickbook 17 17 { 18 struct cpp_code_snippet_grammar 19 : grammar<cpp_code_snippet_grammar> 20 { 21 cpp_code_snippet_grammar(std::vector<template_symbol>& storage, std::string const& doc_id) 18 struct code_snippet_grammar 19 : grammar<code_snippet_grammar> 20 { 21 code_snippet_grammar(std::vector<template_symbol>& storage, 22 std::string const& doc_id, 23 bool is_python) 22 24 : storage(storage) 23 25 , doc_id(doc_id) 26 , is_python(is_python) 24 27 {} 25 28 26 29 template <typename Scanner> 27 30 struct definition 28 31 { 29 definition(cpp_code_snippet_grammar const& self) 32 typedef code_snippet_grammar self_type; 33 34 definition(self_type const& self) 30 35 { 31 typedef cpp_code_snippet_grammar self_type; 36 self.is_python 37 ? definition_python(self) 38 : definition_cpp(self) 39 ; 40 } 41 42 void definition_python(self_type const& self) 43 { 32 44 start_ = 33 45 +( 34 46 snippet [boost::bind(&self_type::compile, &self, _1, _2)] … … 41 53 ; 42 54 43 55 snippet = 44 " //[" >> *space_p56 "#[" >> *space_p 45 57 >> identifier [assign_a(self.id)] 46 >> (*(code_elements - " //]"))47 >> " //]"58 >> (*(code_elements - "#]")) 59 >> "#]" 48 60 ; 49 61 50 62 code_elements = 51 63 escaped_comment 52 64 | ignore 65 | (anychar_p - "#]") [boost::bind(&self_type::pass_thru, &self, _1, _2)] 66 ; 67 68 ignore = 69 *blank_p >> "#<-" 70 >> (*(anychar_p - "#->")) 71 >> "#->" >> *blank_p >> eol_p 72 | "\"\"\"<-\"\"\"" 73 >> (*(anychar_p - "\"\"\"->\"\"\"")) 74 >> "\"\"\"->\"\"\"" 75 | "\"\"\"<-" 76 >> (*(anychar_p - "->\"\"\"")) 77 >> "->\"\"\"" 78 ; 79 80 escaped_comment = 81 *space_p >> "#`" 82 >> ((*(anychar_p - eol_p)) 83 >> eol_p) [boost::bind(&self_type::escaped_comment, &self, _1, _2)] 84 | *space_p >> "\"\"\"`" 85 >> (*(anychar_p - "\"\"\"")) [boost::bind(&self_type::escaped_comment, &self, _1, _2)] 86 >> "\"\"\"" 87 ; 88 } 89 90 void definition_cpp(self_type const& self) 91 { 92 start_ = 93 +( 94 snippet [boost::bind(&self_type::compile, &self, _1, _2)] 95 | anychar_p 96 ) 97 ; 98 99 identifier = 100 (alpha_p | '_') >> *(alnum_p | '_') 101 ; 102 103 snippet = 104 "//[" >> *space_p 105 >> identifier [assign_a(self.id)] 106 >> (*(code_elements - "//]")) 107 >> "//]" 108 | 109 "/*[" >> *space_p 110 >> identifier [assign_a(self.id)] 111 >> *space_p >> "*/" 112 >> (*(code_elements - "/*]*")) 113 >> "/*]*/" 114 ; 115 116 code_elements = 117 escaped_comment 118 | ignore 53 119 | line_callout 54 120 | inline_callout 55 | (anychar_p - "//]" )[boost::bind(&self_type::pass_thru, &self, _1, _2)]121 | (anychar_p - "//]" - "/*]*/") [boost::bind(&self_type::pass_thru, &self, _1, _2)] 56 122 ; 57 123 58 124 inline_callout = … … 111 177 mutable std::vector<std::string> callouts; 112 178 std::vector<template_symbol>& storage; 113 179 std::string doc_id; 180 bool is_python; 114 181 }; 182 115 183 } 116 184 117 185 #endif // BOOST_SPIRIT_QUICKBOOK_CODE_SNIPPET_HPP