cpp_to_hatena

  • C++言語のキーワードを色付けした、はてな用のHTMLの断片を出力します
  • Biscuit Version 1.00.4 以降の"libs/test/"にあります
  • Mingw32(英語のみ)とVC++7.1で動作確認
  • ディレクティブにはほとんど対応していません
  • 以下、自分自身で色付けされたソースコードの一部


[]#pragma[] []once[]

[]#include[] []"../../../../biscuit/parser.hpp"[]

[]#include[] []"config.hpp"[]

[]#include[] []"act_as_is.hpp"[]
[]#include[] []"cpp_token.hpp"[]
[]#include[] []"line_escape.hpp"[]

[]namespace[] []cpp_to_hatena[][] {[]

[]////////////////////////////////////////////////////////////////////////////////[]
[]// actions[]
[]//[]
[]struct[] []act_keyword[]
[]{[]
[]template[][]< [][]class[] []Range[][], [][]class[] []Out[][] >[]
[]void[] []operator[][]()([][]Range[][]& [][]rng[][], [][]Out[][]& [][]out[][]) [][]const[]
[] {[]
[]out[][] << [][]HATENA_L[][]([][]"<span class=\"cpp_keyword\">"[][]);[]
[]act_line_escape[][]()([][]rng[][], [][]out[][]);[]
[]out[][] << [][]HATENA_L[][]([][]"</span>"[][]);[]
[] }[]
[]};[]

[]struct[] []act_string_literal[]
[]{[]
[]template[][]< [][]class[] []Range[][], [][]class[] []Out[][] >[]
[]void[] []operator[][]()([][]Range[][]& [][]rng[][], [][]Out[][]& [][]out[][]) [][]const[]
[] {[]
[]out[][] << [][]HATENA_L[][]([][]"<span class=\"cpp_string_literal\">"[][]);[]
[]act_line_escape[][]()([][]rng[][], [][]out[][]);[]
[]out[][] << [][]HATENA_L[][]([][]"</span>"[][]);[]
[] }[]
[]};[]

[]struct[] []act_number_literal[]
[]{[]
[]template[][]< [][]class[] []Range[][], [][]class[] []Out[][] >[]
[]void[] []operator[][]()([][]Range[][]& [][]rng[][], [][]Out[][]& [][]out[][]) [][]const[]
[] {[]
[]out[][] << [][]HATENA_L[][]([][]"<span class=\"cpp_number_literal\">"[][]);[]
[]act_line_escape[][]()([][]rng[][], [][]out[][]);[]
[]out[][] << [][]HATENA_L[][]([][]"</span>"[][]);[]
[] }[]
[]};[]

[]struct[] []act_identifier[]
[]{[]
[]template[][]< [][]class[] []Range[][], [][]class[] []Out[][] >[]
[]void[] []operator[][]()([][]Range[][]& [][]rng[][], [][]Out[][]& [][]out[][]) [][]const[]
[] {[]
[]out[][];[]
[]//out << HATENA_L("<span class=\"cpp_identifier\">");[]
[]act_line_escape[][]()([][]rng[][], [][]out[][]);[]
[]//out << HATENA_L("</span>");[]
[] }[]
[]};[]

[]struct[] []act_comment[]
[]{[]
[]template[][]< [][]class[] []Range[][], [][]class[] []Out[][] >[]
[]void[] []operator[][]()([][]Range[][]& [][]rng[][], [][]Out[][]& [][]out[][]) [][]const[]
[] {[]
[]out[][] << [][]HATENA_L[][]([][]"<span class=\"cpp_comment\">"[][]);[]
[]act_line_escape[][]()([][]rng[][], [][]out[][]);[]
[]out[][] << [][]HATENA_L[][]([][]"</span>"[][]);[]
[] }[]
[]};[]

[]struct[] []act_pp_directive[]
[]{[]
[]template[][]< [][]class[] []Range[][], [][]class[] []Out[][] >[]
[]void[] []operator[][]()([][]Range[][]& [][]rng[][], [][]Out[][]& [][]out[][]) [][]const[]
[] {[]
[]out[][] << [][]HATENA_L[][]([][]"<span class=\"cpp_pp_directive\">"[][]);[]
[]act_line_escape[][]()([][]rng[][], [][]out[][]);[]
[]out[][] << [][]HATENA_L[][]([][]"</span>"[][]);[]
[] }[]
[]};[]

[]struct[] []act_pp_include_path[]
[]{[]
[]template[][]< [][]class[] []Range[][], [][]class[] []Out[][] >[]
[]void[] []operator[][]()([][]Range[][]& [][]rng[][], [][]Out[][]& [][]out[][]) [][]const[]
[] {[]
[]out[][] << [][]HATENA_L[][]([][]"<span class=\"cpp_pp_include_path\">"[][]);[]
[]act_line_escape[][]()([][]rng[][], [][]out[][]);[]
[]out[][] << [][]HATENA_L[][]([][]"</span>"[][]);[]
[] }[]
[]};[]

[]////////////////////////////////////////////////////////////////////////////////[]
[]// parsers[]
[]//[]
[]using[] []namespace[] []biscuit[][];[]

[]struct[] []non_spaces[][] :[]
[]star[][]< [][]not_[][]<[][]space[][]> >[]
[]{ };[]

[]struct[] []preprocessor[][] :[]
[]or_[][]<[]
[]seq[][]<[]
[]actor[][]< [][]cpp_token[][]::[][]pp_include_directive[][], [][]act_pp_directive[][] >,[]
[]actor[][]< [][]star[][]<[][]biscuit[][]::[][]space[][]>, [][]act_as_is[][] >,[]
[]actor[][]< [][]non_spaces[][], [][]act_pp_include_path[][] >[]
[] >,[]
[]actor[][]< [][]cpp_token[][]::[][]pp_directive[][], [][]act_pp_directive[][] >,[]
[]actor[][]< [][]cpp_token[][]::[][]pp_null_directive[][], [][]act_pp_directive[][] >[]
[] >[]
[]{ };[]

[]struct[] []start[][] :[]
[]or_[][]<[]
[]preprocessor[][],[]
[]// add anything you want[]
[]actor[][]< [][]cpp_token[][]::[][]comment[][], [][]act_comment[][] >,[]
[]actor[][]< [][]cpp_token[][]::[][]keyword[][], [][]act_keyword[][] >,[]
[]actor[][]< [][]cpp_token[][]::[][]string_literal[][], [][]act_string_literal[][] >,[]
[]actor[][]< [][]cpp_token[][]::[][]character_literal[][], [][]act_string_literal[][] >,[]
[]actor[][]< [][]cpp_token[][]::[][]number_literal[][], [][]act_number_literal[][] >,[]
[]actor[][]< [][]cpp_token[][]::[][]identifier[][], [][]act_identifier[][] > [][]// must be after keyword[]
[] >[]
[]{ };[]

[]} [][]// namespace cpp_to_hatena[]