A semantic syntax highlighting and code hyper-linking tool for C and C++. It is written in C++ and based on libclang , Clang’s C-Interface.
An example of what it generates is its output when run on itself (note that the directory listing was not generated with synth itself but with the
dir2html.py script run on the output):
synth is a commandline-tool with the following usage syntax:
synth <OPTIONS> (<inroot> [-o <outroot>])... (--db <dbdir>|--cmd <cmd>)
synth has two usage modes: In
--db mode it expects a directory with a Clang compilation database (
compilation_commands.json ) in
<dbdir> . See http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html for how to create such a file for your project (it’s trivial if you already use CMake with Clang).
--cmd mode a full clang command line is passed e.g.
--cmd /usr/bin/clang++ myfile.cpp -I ~/my/include/dir . It is important that the clang path is correct because certain include files are searched relative to it.
synth will execute all given commands (except in
--db mode it only executes commands without filename or with a filename that is under some
<inroot> ). For each file encountered (including all
#include d files) it produces an output file only if the file is in some
<inroot> . The output file will then be written as
<outroot> is the one given next to the matching
<relpath> is the path of the file relative to the matched
<inroot> (if multiple
<inroot> s match, the first one is used).
These options are allowed:
-j <n>: Use
<n>threads. If the option is omitted, the number of CPU cores is used (same when
<n>is zero). Ignored in
-t <templatefile>: Use the
<templatefile>as output-template. All outputs will be formatted according to this file. The following replacements are made:
@@code@@: The highlighted code (without any surrounding
@@filename@@: The name of the input file, relative to the matched
@@rootdir@@: A relative path to the output root. If multiple
<outroot>s are given and their common prefix is under the current working directory, that common prefix is used as output root for all files. Otherwise each file simply has the
<outroot>of the matched
<inroot>as its output root. This is useful e.g. to link to a CSS-file. By default, synth will use a minimal HTML5 template with the filename as
<title>and referencing a
-e <arg>: Can be given multiple times.
<arg>will be appended to the arguments passed to clang. E.g. to specify an additional include directory use
-e -I -e ~/my/include/dir. Useful in
synth my-repo/ -o my-repo-html/ /usr/include/ -o my-repo-html/include / --db my-repo-builddir/
Process all commands of the compilation-database under
my-repo-builddir/ , generating output for files under
my-repo-html/ and for files under
my-repo-html/include . E.g. a file
my-repo/src/main.cpp will be processed to
/usr/include/math.h will be processed to
my-repo-html/include/math.h . If e.g. a file
/usr/local/include/boost/filesystem.hpp was also included, it would not be processed by synth (it will still be parsed though as this is necessary for highlighting files that use it).
The highlighting classes are the same ones that Pygments uses. Additionally the CSS classes
def are given to declarations and definitions respectively (tokens that are both get both classes). Note that most Pygments styles seem to assume that classes such as
Name.Function ) are only emitted for function declarations/definitions but synth also highlights usages. This is the reason for the included
code.css style which is a version of the
colorful style where only declarations and definitions are bold.
- Clone or download the repository
- Set up dependencies (Boost 1.60 and libclang 3.7+ (tested with 3.8), a C++14 compiler (tested with clang).
- Create a build directory and from there run
cmake <path to repo root>.
- Run your build tool on the generated build files e.g.
msbuild synth.sln. If you have a not too ancient CMake you can just use
cmake --build ..
This project is licensed under the MIT license. SeeLICENSE.txt
转载本站任何文章请注明：转载至神刀安全网，谢谢神刀安全网 » Synth: semantic syntax highlighting and code hyperlinking tool for C and C++