cpp2hatena.hpp


[]#pragma[] []once[]

[]// thanks to[]
[]// http://spirit.sourceforge.net/distrib/spirit_1_7_0/libs/spirit/example/application/cpp_to_html/[]

[]#include[][] <boost/spirit/core.hpp>[]
[]#include[][] <boost/spirit/utility/chset.hpp>[]
[]#include[][] <boost/spirit/utility/escape_char.hpp>[]
[]#include[][] <boost/spirit/utility/confix.hpp>[]

[]namespace[] []pst[] {
[]using[] []namespace[] []std[];
[]namespace[] []spl[] = []boost[]::[]spirit[];
[]namespace[] []mpl[] = []boost[]::[]mpl[];

[]// SemanticActions dispatch tags[]
[]struct[] []cpp2xml_normal_sa_tag[] { };
[]struct[] []cpp2xml_preprocesser_sa_tag[] : []cpp2xml_normal_sa_tag[] { };
[]struct[] []cpp2xml_cpp_comment_sa_tag[] : []cpp2xml_normal_sa_tag[] { };
[]struct[] []cpp2xml_c_comment_sa_tag[] : []cpp2xml_cpp_comment_sa_tag[] { };
[]struct[] []cpp2xml_identifier_sa_tag[] : []cpp2xml_normal_sa_tag[] { };
[]struct[] []cpp2xml_special_sa_tag[] : []cpp2xml_normal_sa_tag[] { };
[]struct[] []cpp2xml_string_literal_sa_tag[] : []cpp2xml_normal_sa_tag[] { };
[]struct[] []cpp2xml_char_literal_sa_tag[] : []cpp2xml_string_literal_sa_tag[] { };
[]struct[] []cpp2xml_number_literal_sa_tag[] : []cpp2xml_normal_sa_tag[] { };
[]struct[] []cpp2xml_unexpected_char_sa_tag[] : []cpp2xml_normal_sa_tag[] { };
[]// cpp2xml[]
[]template[]< []typename[] []SemanticActions[] >
[]class[] []cpp2xml[] : []public[] []spl[]::[]grammar[]< []cpp2xml[] > {
[]public[]:
[]typedef[] []SemanticActions[] []semantic_actions_t[];
[]private[]:
[]typedef[] []spl[]::[]scanner[]< []typename[] []std[]::[]basic_string[]<[]wchar_t[]>::[]iterator[] > []scanner_t[];
[]typedef[] []spl[]::[]rule[]<[]scanner_t[]> []rule_t[];
[]SemanticActions[]& []actions[];
[]public[]:
[]// ctor[]
[]cpp2xml[]([]SemanticActions[]& []actions_[]) : []actions[]([]actions_[]) { }
[]// definition[]
[]template[]< []typename[] []Scanner[] >
[]struct[] []definition[] {
[]typedef[] []spl[]::[]rule[]<[]Scanner[]> []rule_t[];
[]// rules[]
[]rule_t[]
[]program[], []spaces[],
[]preprocessor[],[]preprocessor_aux[],
[]cpp_comment[], []c_comment[],
[]special[], []number_literal[], []string_literal[], []char_literal[], []identifier[];
[]// start[]
[]rule_t[] []const[]& []start[]() []const[] { []return[] []program[]; }
[]// ctor[]
[]definition[]([]cpp2xml[] []const[]& []self_[]) {
[]program[]
= []spaces[] >>
*( []preprocessor[] [ []self_[].[]actions[].[]get_action[]([]cpp2xml_preprocesser_sa_tag[]()) ] >> []spaces[]
| []c_comment[] [ []self_[].[]actions[].[]get_action[]([]cpp2xml_c_comment_sa_tag[]()) ] >> []spaces[]
| []cpp_comment[] [ []self_[].[]actions[].[]get_action[]([]cpp2xml_cpp_comment_sa_tag[]()) ] >> []spaces[]
| []identifier[] [ []self_[].[]actions[].[]get_action[]([]cpp2xml_identifier_sa_tag[]()) ] >> []spaces[]
| []special[] [ []self_[].[]actions[].[]get_action[]([]cpp2xml_special_sa_tag[]()) ] >> []spaces[]
| []string_literal[] [ []self_[].[]actions[].[]get_action[]([]cpp2xml_string_literal_sa_tag[]()) ] >> []spaces[]
| []char_literal[] [ []self_[].[]actions[].[]get_action[]([]cpp2xml_char_literal_sa_tag[]()) ] >> []spaces[]
| []number_literal[] [ []self_[].[]actions[].[]get_action[]([]cpp2xml_number_literal_sa_tag[]()) ] >> []spaces[]
| []spl[]::[]anychar_p[] [ []self_[].[]actions[].[]get_action[]([]cpp2xml_unexpected_char_sa_tag[]()) ]
)
;
[]spaces[]
= (*[]spl[]::[]space_p[]) [ []self_[].[]actions[].[]get_action[]([]cpp2xml_normal_sa_tag[]()) ]
;
[]preprocessor[]
[]// = L'#' //oops, even only # is "null" preprocessor[]
[]// >> *(spl::anychar_p - (spl::eol_p | L"//" | L"/*") )[]
= []L[][]'#'[]
>> *([]spl[]::[]anychar_p[] - ( []spl[]::[]eol_p[] | []L[][]"\\"[] | []L[][]"//"[] | []L[][]"/*"[] ) )
>> *[]preprocessor_aux[] >> ( []spl[]::[]eol_p[] | *([]spl[]::[]anychar_p[] - []L[][]"//"[] - []L[][]"/*"[]) )
;
[]preprocessor_aux[]
= []L[][]'\\'[] >> (*[]spl[]::[]blank_p[]) >> []spl[]::[]eol_p[]
>> *([]spl[]::[]anychar_p[] - ( []spl[]::[]eol_p[] | []L[][]"\\"[] ) )
;
[]cpp_comment[]
= []spl[]::[]comment_p[]([]L[][]"//"[])
;
[]c_comment[]
= []spl[]::[]comment_p[]([]L[][]"/*"[], []L[][]"*/"[])
;
[]special[]
[]// = +spl::chset_p(L"~!%^&*()+={[}]:;,<.>?/|\\-")[]
[]// ;[]
= ( +[]spl[]::[]chset_p[]([]L[][]"~!%^&*()+={[}]:;,<.>?|\\-"[])
| ( []L[][]'/'[] >> !([]spl[]::[]anychar_p[] - []L[][]'/'[] - []L[][]'*'[]) ) )
;
[]string_literal[]
= ![]spl[]::[]as_lower_d[][[]L[][]'l'[]] >> []spl[]::[]confix_p[]([]L[][]'"'[], *[]spl[]::[]c_escape_ch_p[], []L[][]'"'[])
;
[]char_literal[]
= ![]spl[]::[]as_lower_d[][[]L[][]'l'[]] >> []spl[]::[]confix_p[]([]L[][]'\''[], *[]spl[]::[]c_escape_ch_p[], []L[][]'\''[])
;
[]number_literal[]
= ( []spl[]::[]real_p[]
| []spl[]::[]as_lower_d[][[]L[][]"0x"[]] >> []spl[]::[]hex_p[]
| []L[][]'0'[] >> []spl[]::[]oct_p[]
)
>> *[]spl[]::[]as_lower_d[][[]spl[]::[]chset_p[]([]L[][]"ldfu"[])]
;
[]identifier[]
= ( ([]spl[]::[]alpha_p[] | []L[][]'_'[]) >> *([]spl[]::[]alnum_p[] | []L[][]'_'[]) )
;
}
}; []// class definition[]
}; []// class code2xml[]
} []// namespace pst[]