C++ 在站点上粘贴,语法高亮显示
我得到了一个网络主机,我与teammats有项目。我认为这是一个好主意,有我自己的粘贴网站,没有过期日期粘贴(我知道存在)和其他事情。我想知道。我可以在代码中使用什么简单的高亮显示库?我将只使用C/C++。问题标记为“php”,但您“将只使用C/C++”C++ 在站点上粘贴,语法高亮显示,c++,c,syntax-highlighting,paste,C++,C,Syntax Highlighting,Paste,我得到了一个网络主机,我与teammats有项目。我认为这是一个好主意,有我自己的粘贴网站,没有过期日期粘贴(我知道存在)和其他事情。我想知道。我可以在代码中使用什么简单的高亮显示库?我将只使用C/C++。问题标记为“php”,但您“将只使用C/C++” PHP解决方案非常简单。只为一种语言(无上下文,使用C++等常规词素)构建一个highlighter实际上非常简单,因为您基本上可以将所有词素封装到一个大型正则表达式中: $cpplex = '/ (?<string>"(?
PHP解决方案非常简单。只为一种语言(无上下文,使用C++等常规词素)构建一个highlighter实际上非常简单,因为您基本上可以将所有词素封装到一个大型正则表达式中:
$cpplex = '/
(?<string>"(?:\\\\"|.)*?")|
(?<char>\'(?:\\\\\'|.)*?\')|
(?<comment>\\/\\/.*?\n|\\/\*.*?\*\\/)|
(?<preprocessor>#\w+(?:\\\\\n|[^\\\\])*?\n)| # This one is not perfect!
(?<number>
(?: # Integer followed by optional fractional part.
(?:0(?:
x[0-9a-f]+|[0-7]*)|\d+)
(?:\.\d*)?(?:e[+-]\d+)?)
|(?: # Just the fractional part.
(?:\.\d*)(?:e[+-]\d+)?))|
(?<keyword>asm|auto|break|case…)| # TODO Complete. Include ciso646!
(?<identifier>\\w(?:\\w|\\d)*)
/xs';
$matches = preg_match_all($cpplex, $input, $matches, PREG_OFFSET_CAPTURE);
foreach ($matches as $match) {
// TODO: determine which group was matched.
// Don't forget lexemes that are *not* part of the expression:
// i.e. whitespaces and operators. These are between the matches.
echo "<span class=\"$keyword\">$token</span>";
}
$cpplex='1!'/
(?"(?:\\\\"|.)*?")|
(?\'(?:\\\\\'|.)*?\')|
(?\/\\/.*?\n\\/\**?\*\/)|
(?)\w+(?:\n\n[^\\\\])*?\n)|这个不完美!
(?
(?:#整数后跟可选的小数部分。
(?:0(?:
x[0-9a-f]+|[0-7]*)|\d+)
(?:\。\d*)?(?:e[+-]\d+)
|(?:#只是小数部分。
(?:\。\d*)(?:e[+-]\d+)|
(?asm | auto | break | case…)|#待办事项完成。包括ciso646!
(?\\w(?:\\w |\\d)*)
/xs′;
$matches=preg_match_all($cpplex,$input,$matches,preg_OFFSET_CAPTURE);
foreach($matches作为$match进行匹配){
//TODO:确定匹配的组。
//不要忘记表达中*不是*部分的词素:
//例如空格和运算符。它们位于匹配之间。
回显“$token”;
}
因为他假设这样的粘贴站点将用PHP编写…(或者这是一项要求)。