Skip to content
/ chapi Public

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.

License

Notifications You must be signed in to change notification settings

phodal/chapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Repository files navigation

Chapi

Chapi Logo

Chapi CI codecov Maintainability Maven Central

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 Information

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?

Specify Rule

scan by twice.In order to success get:

  • find data struct in same package

TypeScript

  1. PackageName will use resolvePath, package ofsrc/grammar/blbla.tsis@.grammar
  2. Function in file will usedefaultas DataStructure.Name
  3. export defaultObjectin file will usedefaultas FunctionName, and will belong todefaultDataStructure

C# issues

C

We usehttps://github.com/shevek/jcppto pre-process C code.

Kotlin

  • need to implementationwarpTargetFullTypeto got Class in same package.

Usage

  1. add todependencies
dependencies {
implementation 'com.phodal.chapi:chapi-ast-java:2.3.6'
implementation 'com.phodal.chapi:chapi-domain:2.3.6'
}

Usage

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

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":[]
}

Development

Syntax Parse Identify Rules:

  1. package name
  2. import name
  3. class / data struct
    1. struct name
    2. struct parameters
    3. function name
    4. return types
    5. function parameters
  4. function
    1. function name
    2. return types
    3. function parameters
  5. method call
    1. new instance call
    2. parameter call
    3. field call

Build Antlr Grammar

  1. setup Antlr:brew install antlr
  2. run compile:./scripts/compile-antlr.sh

Data Structures

// 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

Development ( Chinese Version )

Env: Intellij IDEA, JDK 11+

  1. Clone code:git clone https://github.com/phodal/chapi

  2. Build:./gradlew build

Tham dữ khai phát

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

Gia nhập khai phát

  1. 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:

  1. package name
  2. import name
  3. class / data struct
    1. struct name
    2. struct parameters
    3. function name
    4. return types
    5. function parameters
  4. function
    1. function name
    2. return types
    3. function parameters
  5. method call
    1. new instance call
    2. parameter call
    3. field call
    4. other calls...

Đề giao tín tức cách thức

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í

License

Phodal's Idea

@2020 APhodal Huang'sIdea.This code is distributed under the MPL license. SeeLICENSEin this directory.

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published