All Projects → xoofx → Cppast.net

xoofx / Cppast.net

Licence: bsd-2-clause
CppAst is a .NET library providing a C/C++ parser for header files powered by Clang/libclang with access to the full AST, comments and macros

Programming Languages

csharp
926 projects
cplusplus
227 projects

Projects that are alternatives of or similar to Cppast.net

Vermin
Concurrently detect the minimum Python versions needed to run code
Stars: ✭ 218 (-4.39%)
Mutual labels:  ast, parser
Php Parser
A PHP parser written in PHP
Stars: ✭ 15,101 (+6523.25%)
Mutual labels:  ast, parser
Participle
A parser library for Go
Stars: ✭ 2,302 (+909.65%)
Mutual labels:  ast, parser
Query Translator
Query Translator is a search query translator with AST representation
Stars: ✭ 165 (-27.63%)
Mutual labels:  ast, parser
Cub
The Cub Programming Language
Stars: ✭ 198 (-13.16%)
Mutual labels:  ast, parser
Command Line Api
Command line parsing, invocation, and rendering of terminal output.
Stars: ✭ 2,418 (+960.53%)
Mutual labels:  parser, dotnet-core
Snapdragon
snapdragon is an extremely pluggable, powerful and easy-to-use parser-renderer factory.
Stars: ✭ 180 (-21.05%)
Mutual labels:  ast, parser
Phplrt
PHP Language Recognition Tool
Stars: ✭ 127 (-44.3%)
Mutual labels:  ast, parser
Dpp
Directly include C headers in D source code
Stars: ✭ 189 (-17.11%)
Mutual labels:  clang, libclang
Flora Sql Parser
Parse SQL (select) statements into abstract syntax tree (AST) and convert ASTs back to SQL.
Stars: ✭ 186 (-18.42%)
Mutual labels:  ast, parser
Json To Ast
JSON AST parser
Stars: ✭ 161 (-29.39%)
Mutual labels:  ast, parser
Sharpyaml
SharpYaml is a .NET library for YAML compatible with CoreCLR
Stars: ✭ 217 (-4.82%)
Mutual labels:  parser, dotnet-core
Lioness
The Lioness Programming Language
Stars: ✭ 155 (-32.02%)
Mutual labels:  ast, parser
Cppsharp
Tools and libraries to glue C/C++ APIs to high-level languages
Stars: ✭ 2,221 (+874.12%)
Mutual labels:  clang, parser
Babylon
PSA: moved into babel/babel as @babel/parser -->
Stars: ✭ 1,692 (+642.11%)
Mutual labels:  ast, parser
Dstep
A tool for converting C and Objective-C headers to D modules
Stars: ✭ 177 (-22.37%)
Mutual labels:  clang, libclang
Cppinsights
C++ Insights - See your source code with the eyes of a compiler
Stars: ✭ 1,382 (+506.14%)
Mutual labels:  ast, clang
Yacep
yet another csharp expression parser
Stars: ✭ 107 (-53.07%)
Mutual labels:  ast, dotnet-core
Deoplete Clang
deoplete.nvim source for C/C++/Obj-C/Obj-C++ with clang-python3
Stars: ✭ 186 (-18.42%)
Mutual labels:  clang, libclang
Tatsu
竜 TatSu generates Python parsers from grammars in a variation of EBNF
Stars: ✭ 198 (-13.16%)
Mutual labels:  ast, parser

CppAst.NET Build Status NuGet

CppAst provides a C/C++ parser for header files with access to the full AST, comments and macros for .NET Framework and .NET Core

Purpose

The target primary usage of this library is to serve as a simple foundation for domain oriented PInvoke/Interop codegen

Features

  • Compatible with .NET Standard 2.0+
  • Using Clang/libclang 10.0.0
  • Allow to parse in-memory C/C++ text and C/C++ files from the disk
  • Simple AST model
  • Full type system
  • Provides basic access to attributes (_declspec(...) or __attribute__((...)))
  • Provides access to attached comments
  • Provides access to expressions for variable and parameter init value (e.g const int x = (1 + 2) << 1 the (1 + 2) << 1 will be retrievable as a binary expression from the AST)
  • Provides access to macro definitions, including tokens via the option CppParserOptions.ParseMacros (default is false)

Documentation

Check the user guide documentation from the doc/ folder.

Usage Example

You can jump-start with the CppParser.Parse method:

// Parse a C++ files
var compilation = CppParser.Parse(@"
enum MyEnum { MyEnum_0, MyEnum_1 };
void function0(int a, int b);
struct MyStruct { int field0; int field1;};
typedef MyStruct* MyStructPtr;
"
);
// Print diagnostic messages
foreach (var message in compilation.Diagnostics.Messages)
    Console.WriteLine(message);

// Print All enums
foreach (var cppEnum in compilation.Enums)
    Console.WriteLine(cppEnum);

// Print All functions
foreach (var cppFunction in compilation.Functions)
    Console.WriteLine(cppFunction);

// Print All classes, structs
foreach (var cppClass in compilation.Classes)
    Console.WriteLine(cppClass);

// Print All typedefs
foreach (var cppTypedef in compilation.Typedefs)
    Console.WriteLine(cppTypedef);

Prints the following result:

enum MyEnum {...}
void function0(int a, int b)
struct MyStruct { ... }
typedef MyStruct* MyStructPtr

Binaries

This library is distributed as a NuGet package NuGet

Known issues

The library libclang used by this project has some known issues and limitations:

  • Attributes are not fully exposed (e.g in function parameters, on typedefs...)
  • Generic instance types are not fully exposed (e.g used as parameters, or as base types...)

License

This software is released under the BSD-Clause 2 license.

Credits

  • ClangSharp: .NET managed wrapper around Clang/libclang

Related

The C++ project cppast serves similar purpose although CppAst.NET does not share API or any implementation details.

Author

Alexandre Mutel aka xoofx.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].