CHAPI (Common Hierarchical Abstract Parser and Information Converter) streamlines code analysis by converting diverse language source code into a unified abstract model, simplifying cross-language development. Chapi Thị nhất cá thông dụng tằng thứ trừu tượng giải tích khí dữ tín tức chuyển hoán khí, tha khả dĩ tương bất đồng biên trình ngữ ngôn đích nguyên đại mã chuyển hoán vi thống nhất đích tằng thứ trừu tượng mô hình.
Chapi => Cha Pi => Tea Pi => Tea π => trà π. See on in refs:Tea if by sea, cha if by land.
Chapi (pronounce /tʃɑpi/) also pronounce XP in Chinese if you always call X in xoa.
language stages:
Features | Java | Python | Go | Kotlin | TS/JS | C | C# | Scala | C++ | Rust |
---|---|---|---|---|---|---|---|---|---|---|
http api decl | ✅ | 🆕 | 🆕 | ✅ | ✅ | 🆕 | 🆕 | ✅ | 🆕 | |
syntax parse | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 🆕 | ✅ | 🆕 | ✅ |
function call | ✅ | ✅ | 🆕 | ✅ | ✅ | 🆕 | ✅ | |||
arch/package | ✅ | ✅ | ✅ | 🆕 | ✅ | ✅ | 🆕 | |||
real world | ✅ | ✅ | ✅ |
- ArchGuard- ArchGuard is an architecture workbench, also for architecture governance, which can analysis architecture in container, component, code level, create architecture fitness functions, and analysis system dependencies.
- UnitGenis a code fine-tuning data framework that generates data from your existing codebase.
- ChocolateFactoryis a cutting-edge LLM toolkit designed to empower you in creating your very own AI assistant.
PS: welcome to PR to send your projects
language versions ( tested ):
- Java: 8, 11, 17
- TypeScript/JavaScript
- Kotlin
- Rust: v1.60.0
- Python: 2, 3
// tier 1 languages
":chapi-ast-java",
":chapi-ast-typescript",
// tier 2 languages
":chapi-ast-kotlin",
":chapi-ast-go",
":chapi-ast-python",
// tier 3 languages
":chapi-ast-c",
":chapi-ast-rust",
":chapi-ast-csharp",
":chapi-ast-scala",
":chapi-ast-cpp",
Language Familywiki
Algol Familyhttps://wiki.c2.com/?AlgolFamily
Languages | plan support | |
---|---|---|
C family | C#, Java, Go, C, C++, Objective-C, Rust,... | C++, C, Java, C#, Rust? |
Functional | Scheme, Lisp, Clojure, Scala,... | Scala |
Scripting | Lua, PHP, JavaScript, Python, Perl, Ruby,... | Python, JavaScript |
Other | Fortran, Swift, Matlab,... | Swift?, Fortran? |
scan by twice.In order to success get:
- find data struct in same package
- PackageName will use resolvePath, package of
src/grammar/blbla.ts
is@.grammar
- Function in file will use
default
as DataStructure.Name - export default
Object
in file will usedefault
as FunctionName, and will belong todefault
DataStructure
- interpolated_string parse issue:official grammar , Antlr issues:antlr/grammars-v4#1146
- import analysis support
- in C#, import
namespace
can use call in namespace
- in C#, import
We usehttps://github.com/shevek/jcppto pre-process C code.
- need to implementation
warpTargetFullType
to got Class in same package.
- add to
dependencies
dependencies {
implementation 'com.phodal.chapi:chapi-ast-java:2.3.6'
implementation 'com.phodal.chapi:chapi-domain:2.3.6'
}
importchapi.domain.core.CodeDataStruct
importkotlinx.coroutines.async
importkotlinx.coroutines.awaitAll
importkotlinx.coroutines.runBlocking
importorg.archguard.scanner.core.sourcecode.LanguageSourceCodeAnalyser
importorg.archguard.scanner.core.sourcecode.SourceCodeContext
importjava.io.File
classCSharpAnalyser(overridevalcontext:SourceCodeContext)
privatevalclient=context.client
privatevalimpl=chapi.ast.csharpast.CSharpAnalyser()
funanalyse():List<CodeDataStruct>=runBlocking {
getFilesByPath(context.path) {
it.absolutePath.endsWith(".cs")
}
.map { async { analysisByFile(it) } }.awaitAll()
.flatten()
.also{ client.saveDataStructure(it) }
}
funanalysisByFile(file:File):List<CodeDataStruct> {
valcodeContainer=impl.analysis(file.readContent(), file.name)
returncodeContainer.Containers.flatMap { container->
container.DataStructures.map {
it.apply{
it.Imports=codeContainer.Imports
it.FilePath=file.absolutePath
}
}
}
}
}
examples Java source code:
packageadapters.outbound.persistence.blog;
publicclassBlogPOimplementsPersistenceObject<Blog> {
@Override
publicBlogtoDomainModel() {
}
}
examples output
{
"Imports":[],
"Implements":[
"PersistenceObject<Blog>"
],
"NodeName":"BlogPO",
"Extend":"",
"Type":"CLASS",
"FilePath":"",
"InOutProperties":[],
"Functions":[
{
"IsConstructor":false,
"InnerFunctions":[],
"Position":{
"StartLine":6,
"StartLinePosition":133,
"StopLine":8,
"StopLinePosition":145
},
"Package":"",
"Name":"toDomainModel",
"MultipleReturns":[],
"Annotations":[
{
"Name":"Override",
"KeyValues":[]
}
],
"Extension":{},
"Override":false,
"extensionMap":{},
"Parameters":[],
"InnerStructures":[],
"ReturnType":"Blog",
"Modifiers":[],
"FunctionCalls":[]
}
],
"Annotations":[],
"Extension":{},
"Parameters":[],
"Fields":[],
"MultipleExtend":[],
"InnerStructures":[],
"Package":"adapters.outbound.persistence.blog",
"FunctionCalls":[]
}
Syntax Parse Identify Rules:
- package name
- import name
- class / data struct
- struct name
- struct parameters
- function name
- return types
- function parameters
- function
- function name
- return types
- function parameters
- method call
- new instance call
- parameter call
- field call
- setup Antlr:
brew install antlr
- run compile:
./scripts/compile-antlr.sh
// for multiple project analysis
code_project
code_module
// for package dependency analysis
code_package_info
code_dependency
// package or file as dependency analysis
code_package
code_container
// class-first or function-first
code_data_struct
code_function
// function or class detail
code_annotation
code_field
code_import
code_member
code_position
code_property
// method call information
code_call
Env: Intellij IDEA, JDK 11+
-
Clone code:
git clone https://github.com/phodal/chapi
-
Build:
./gradlew build
Vi liễu bảo chứng bất dịch xuất hiện bug, hạng mục thải dụng TDD đích phương thức tiến hành, tức tiên biên tả đối ứng đích ngữ pháp trắc thí, nhiên hậu thật hiện đại mã. Thông quá tẫn khả năng cao đích trắc thí phúc cái suất, hàng đê bug đích xuất hiện.
Hạng mục chủ yếu do domain + các chủng ngữ ngôn đích AST + application cấu kiến:
- domain, cấu kiến thống nhất đích đại mã mô hình
- Các ngữ ngôn AST
- application, đối ngoại bạo lộ đích giản dịch API
Mỗi cá AST hạng mục đích nhập khẩu thịxxAnalyser
,Phản hồi đích thị nhất cá CodeContainer, tức đại mã dung khí. Tại phi C# ngữ ngôn lí, đẳng đồng vu CodeFile, tức đại mã văn kiện.
CodeContainer nội đối ứng đích lĩnh vực mô hình như hạ sở kỳ:
// class-first or function-first
code_data_struct // loại, struct, interface đẳng
code_function // hàm sổ. Như quả thị đầu đẳng hàm sổ đích ngữ ngôn ( first-class function” ), hội dụng NodeName = "default" bao tại code_data_struct mô hình trung
// function or class detail
code_annotation // chú giải
code_field // toàn cục biến lượng
code_import // bao y lại
code_member // bảo lưu tự đoạn
code_position // vị trí tín tức
code_property // tham sổ tương quan
// method call information
code_call // hàm sổ điều dụng, như fmt.Println
- Tầm trảo cảm hưng thú đích ngữ ngôn / thiêm gia tân đích ngữ ngôn AST
Thông quá TDD Đích phương thức nhất điểm điểm thật hiện hạ diện đích công năng ( khả dĩ khảo lự án thuận tự ), tham chiếu kỳ lệ kiếnJavaFullIdentListenerTest.kt:
- package name
- import name
- class / data struct
- struct name
- struct parameters
- function name
- return types
- function parameters
- function
- function name
- return types
- function parameters
- method call
- new instance call
- parameter call
- field call
- other calls...
Dụng vu phát bố thời, sử dụng tiêu chuẩn đíchCHANGELOG.md
<type>[Language]: <message>
,Kỳ lệ:feat(java): <grammars> init python & go grammars Phodal Huang 2020/2/2, 5:01 PM
Sở hữu đích type kiến:
- build: Ảnh hưởng cấu kiến hệ thống hoặc ngoại bộ y lại quan hệ đích canh cải ( kỳ lệ phạm vi: gulp, broccoli, npm )
- ci: Canh cải ngã môn đích trì tục tập thành văn kiện hòa cước bổn ( kỳ lệ phạm vi: Travis, Circle, BrowserStack, SauceLabs )
- docs: Cận văn đương canh cải
- feat: Nhất cá tân công năng
- fix: Tu phục thác ngộ
- perf: Cải tiến tính năng đích đại mã canh cải
- refactor: Đại mã canh cải, kí bất tu phục thác ngộ dã bất thiêm gia công năng
- style: Bất ảnh hưởng đại mã hàm nghĩa đích biến hóa ( không bạch, cách thức hóa, khuyết thiếu phân hào đẳng )
- test: Thiêm gia khuyết thất trắc thí hoặc canh chính hiện hữu trắc thí
@2020 APhodal Huang'sIdea.This code is distributed under
the MPL license. SeeLICENSE
in this directory.