Libclang
Perl 6 bindings for libclang
Note: This is currently experimental and API may change. Please DO NOT use in a production environment.
Example
use v6; use Libclang; my $index = Libclang::Index.new; LEAVE $index.destroy if $index.defined; my $file-name = $*SPEC.catfile($*PROGRAM.IO.parent, "header.hpp"); my $translation-unit = Libclang::TranslationUnit.new($index, $file-name); LEAVE $translation-unit.destroy if $translation-unit.defined; my $cursor = $translation-unit.cursor; LEAVE $cursor.destroy if $cursor.defined; $cursor.visit-children(sub ($cursor, $parent) { printf("Cursor '%15s' of kind '%s'\n", $cursor.spelling, $cursor.kind-spelling); return child-visit-recurse; });
Dependencies
Please follow the instructions below based on your platform to install libclang
development libraries / headers:
Platform | Installation command |
---|---|
Debian | apt-get install libclang-dev |
macOS | brew update; brew install llvm --with-clang |
Windows | Install mingw-w64-install.exe. Install Clang for Windows 64-bit. |
Installation
- Install this module using zef:
$ zef install Libclang
Testing
- To run tests:
$ AUTHOR_TESTING=1 zef test --verbose .
- To run all tests including author tests (Please make sure Test::Meta is installed):
$ zef install Test::META
$ AUTHOR_TESTING=1 prove -e "perl6 -Ilib"
See Also
- https://gist.githubusercontent.com/raphaelmor/3150866/raw/4f722b922ae19c9d6c328d79d5a5ca8cb018fb77/clanglib.c
- https://shaharmike.com/cpp/libclang/
- http://bastian.rieck.ru/blog/posts/2015/baby_steps_libclang_ast/
Author
Ahmad M. Zawawi, azawawi on #perl6.