README
¶
Chapi
Chapi is a common language data structure parser, which will parse different language to same JSON object.
Languages Stages (Welcome to PR your usage languages)
| Features/Languages | Java | Python | Go | Kotlin | TypeScript | C | C# | Scala |
|---|---|---|---|---|---|---|---|---|
| syntax parse | ✅ | ✅ | ✅ | TBC | ✅ | TBC | 🆕 | 🆕 |
| function call graph | ✅ | |||||||
| arch/package graph | ✅ | |||||||
| real world validate | ✅ |
Language Family wiki
| Languages | plan support | |
|---|---|---|
| Algol | Ada, Delphi, Pascal, ALGOL, ... | Pascal? |
| C family | C#, Java, Go, C, C++, Objective-C, Rust, ... | 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? |
Todo:
- Migrate Coca ast
- Pluggable
- Publish to Maven / GitHub
TBC:
- SQL (refs: antlr4-oracle && sqlgraph)
Usage
Import by Jitpack
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.phodal:chapi:Tag'
}
Import by GitHub Packages
<dependency>
<groupId>com.phodal</groupId>
<artifactId>chapi-domain</artifactId>
<version>0.0.3</version>
</dependency>
<dependency>
<groupId>com.phodal</groupId>
<artifactId>chapi-ast-java</artifactId>
<version>0.0.3</version>
</dependency>
Usage
import chapi.domain.core.CodeCall
import chapi.domain.core.CodeDataStruct
import chapi.app.analyser
...
val nodes = ChapiAnalyser().analysisByPath(path.absolutePath)
...
Examples
examples Java source code:
package adapters.outbound.persistence.blog;
public class BlogPO implements PersistenceObject<Blog> {
@Override
public Blog toDomainModel() {
}
}
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:
- 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
- setup Antlr:
brew install antlr - 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
Refs
Goal: source code data model for different language & different language family from Language support
License
@ 2020 A Phodal Huang's Idea. This code is distributed under the MPL license. See LICENSE in this directory.
Click to show internal directories.
Click to hide internal directories.