1

我正在获得一个网络主机,并且我有团队垫的项目。我认为拥有自己的粘贴站点是一个不错的主意,该站点没有粘贴到期日期(我知道http://pastie.org/存在)和其他内容。我想知道。我可以在代码上使用的简单高亮库是什么?我只会使用 C/C++。

4

2 回答 2

2

问题被标记为“php”,但您“只会使用 C/C++”?

PHP 解决方案是GeSHi

于 2008-11-19T07:51:21.257 回答
0

只为一种语言(无上下文,使用 C++ 等常规词位)构建荧光笔实际上非常容易,因为您基本上可以将所有词位包装到一个大的正则表达式中:

$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>";
}
于 2008-11-19T08:22:38.713 回答