All Projects → inherd → Chapi

inherd / Chapi

Licence: mpl-2.0
Chapi is A common language meta information convertor, convert different languages to same meta-data model. 一个通用语言元信息转换器,能将不同语言转换为相同的模型。

Programming Languages

kotlin
9241 projects

Labels

Projects that are alternatives of or similar to Chapi

Imagine Old
Modeling and simulations using computational graphs
Stars: ✭ 25 (-80.77%)
Mutual labels:  modeling
Emod
Source files for building the IDM EMOD disease transmission model.
Stars: ✭ 69 (-46.92%)
Mutual labels:  modeling
Indra
INDRA (Integrated Network and Dynamical Reasoning Assembler) is an automated model assembly system interfacing with NLP systems and databases to collect knowledge, and through a process of assembly, produce causal graphs and dynamical models.
Stars: ✭ 105 (-19.23%)
Mutual labels:  modeling
Cryptobeauty
Crypto Beauty 密碼女孩 - 你專屬的區塊鏈少女卡片創作交易平台. Live on the TRON Blockchain.
Stars: ✭ 37 (-71.54%)
Mutual labels:  modeling
Prysm
physical optics: integrated modeling, phase retrieval, segmented systems, polynomials and fitting, ...
Stars: ✭ 57 (-56.15%)
Mutual labels:  modeling
Wrf hydro nwm public
WRF-Hydro model code
Stars: ✭ 85 (-34.62%)
Mutual labels:  modeling
Ditras
DITRAS (DIary-based TRAjectory Simulator), a mathematical model to simulate human mobility
Stars: ✭ 19 (-85.38%)
Mutual labels:  modeling
Model2app
Turn your Swift data model into a working CRUD app.
Stars: ✭ 118 (-9.23%)
Mutual labels:  modeling
Opensource
Code for geophysical 3D/2D Finite Difference modelling, Marchenko algorithms, 2D/3D x-w migration and utilities.
Stars: ✭ 60 (-53.85%)
Mutual labels:  modeling
Citools
An R Package for Quick Uncertainty Intervals
Stars: ✭ 101 (-22.31%)
Mutual labels:  modeling
Opengeode
Open source framework for representing and manipulating geometric models
Stars: ✭ 46 (-64.62%)
Mutual labels:  modeling
Broom
Convert statistical analysis objects from R into tidy format
Stars: ✭ 1,087 (+736.15%)
Mutual labels:  modeling
Network traffic modeler py3
pyNTM - This is the network traffic modeler written in python 3: pip3 install pyNTM
Stars: ✭ 93 (-28.46%)
Mutual labels:  modeling
Jomini
Historical battle simulation package for Python
Stars: ✭ 31 (-76.15%)
Mutual labels:  modeling
Webgme
Web-based Generic Modeling Environment
Stars: ✭ 112 (-13.85%)
Mutual labels:  modeling
Fastscape
A fast, versatile and user-friendly landscape evolution model
Stars: ✭ 22 (-83.08%)
Mutual labels:  modeling
Componentarrays.jl
Arrays with arbitrarily nested named components.
Stars: ✭ 72 (-44.62%)
Mutual labels:  modeling
Hbayesdm
Hierarchical Bayesian modeling of RLDM tasks, using R & Python
Stars: ✭ 124 (-4.62%)
Mutual labels:  modeling
Peartree
peartree: A library for converting transit data into a directed graph for sketch network analysis.
Stars: ✭ 116 (-10.77%)
Mutual labels:  modeling
Machinelearning
A repo with tutorials for algorithms from scratch
Stars: ✭ 96 (-26.15%)
Mutual labels:  modeling

Chapi

Build Status codecov Maintainability Java CI GitHub release (latest by date) Download

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 C++
syntax parse 🆕 🆕 🆕 🆕 🆕
function call 🆕 🆕
arch/package
real world validate
expression (TBD)

Language Family wiki

Algol Family https://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?

TBC:

Chapi-base projects

PS: welcome to PR to send your projects

  • Chapi-TBS a simple example with Chapi to Analysis Java project's bad smell.

Usage

  1. add to package manager repositories
allprojects {
    repositories {
        ...
        jcenter()
    }
}
  1. add to dependencies
dependencies {
    implementation 'com.phodal.chapi:chapi-application:0.0.5'

    // or choose languages target
    implementation 'com.phodal.chapi:chapi-ast-java:0.0.5'
    implementation 'com.phodal.chapi:chapi-domain:0.0.5'
}
  1. add aliyun gradle and maven repo mirror to build file
allprojects {
    ...
    repositories {
        maven{ setUrl("http://maven.aliyun.com/nexus/content/groups/public/") }
        maven{ setUrl("http://maven.aliyun.com/nexus/content/repositories/jcenter")}
        ...
    }
}

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:

  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)

环境准备:Intellij IDEA、JDK 1.8、Antlr 4.8 CLI(可选,参见Antlr)

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

  2. 执行构建:./gradlew build

参与开发

为了保证不易出现 bug,项目采用 TDD 的方式进行,即先编写对应的语法测试,然后实现代码。通过尽可能高的测试覆盖率,降低 bug 的出现。

项目主要由 domain + 各种语言的 AST + application 构建:

  • domain,构建统一的代码模型
  • 各语言 AST
  • application,对外暴露的简易 API

每个 AST 项目的入口是 xxAnalyser,返回的是一个 CodeContainer,即代码容器。在非 C# 语言里,等同于 CodeFile,即代码文件。

CodeContainer 内对应的领域模型如下所示:

// class-first or function-first
code_data_struct // 类、struct、interface 等
code_function    // 函数。如果是头等函数的语言(first-class function”),会用 NodeName = "default" 包在 code_data_struct 模型中

// function or class detail
code_annotation  // 注解
code_field       // 全局变量
code_import      // 包依赖
code_member      // 保留字段
code_position    // 位置信息
code_property    // 参数相关

// method call information
code_call        // 函数调用,如 fmt.Println

加入开发

  1. 寻找感兴趣的语言 / 添加新的语言 AST

通过 TDD 的方式一点点实现下面的功能(可以考虑按顺序),参照示例见 JavaFullIdentListenerTest.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...

提交信息格式

用于发布时,使用标准的 CHANGELOG.md

<type>: <message>,示例:feat: <grammars> init python & go grammars Phodal Huang 2020/2/2, 5:01 PM

所有的 type 见:

  • build: 影响构建系统或外部依赖关系的更改(示例范围:gulp,broccoli,npm)
  • ci: 更改我们的持续集成文件和脚本(示例范围:Travis,Circle,BrowserStack,SauceLabs)
  • docs: 仅文档更改
  • feat: 一个新功能
  • fix: 修复错误
  • perf: 改进性能的代码更改
  • refactor: 代码更改,既不修复错误也不添加功能
  • style: 不影响代码含义的变化(空白,格式化,缺少分号等)
  • test: 添加缺失测试或更正现有测试

Refs

Goal: source code data model for different language & different language family from Language support

License

Phodal's Idea

@ 2020 A Phodal Huang's Idea. This code is distributed under the MPL license. See LICENSE in this directory.

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].