Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/t-gebauer/replant
Prototype: Kotlin to TypeScript data-structure transpiler
https://github.com/t-gebauer/replant
kotlin node-tree-sitter tree-sitter tree-sitter-kotlin
Last synced: 18 days ago
JSON representation
Prototype: Kotlin to TypeScript data-structure transpiler
- Host: GitHub
- URL: https://github.com/t-gebauer/replant
- Owner: t-gebauer
- License: mit
- Created: 2020-07-25T14:25:21.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-04-21T04:16:36.000Z (over 1 year ago)
- Last Synced: 2024-07-30T20:56:09.775Z (3 months ago)
- Topics: kotlin, node-tree-sitter, tree-sitter, tree-sitter-kotlin
- Language: Clojure
- Homepage:
- Size: 120 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# replant
Kotlin to TypeScript data-structure transpilerUses [tree-sitter](https://github.com/tree-sitter/tree-sitter) via [Node.js bindings](https://github.com/tree-sitter/node-tree-sitter) with [Kotlin grammar](https://github.com/fwcd/tree-sitter-kotlin)
## Status
Prototype - proof of concept
## Goals
- The focus lies on transpiling data classes or [POJO](https://en.wikipedia.org/wiki/Plain_old_Java_object)s. It is not planned to try to convert any logic.
- Simplicity (usage of the tree-sitter AST is even easier than using regular expressions?)
- Resistant to syntax changes (compared to regular expressions)
- Easy to adapt to different source (and output?) languages## Examples
### Data classes
Kotlin input:
```kotlin
data class Apple(
var id: Long?,
val color: String,
val size: Int,
val updated: LocalDate
)
```Generated TypeScript output:
(At least that is what is planned, we are not there yet)
```typescript
interface IApple {
readonly id: number | null
readonly color: string
readonly size: number
readonly updated: Date
}export class Apple implements IApple {
constructor (
public readonly id: number | null,
public readonly color: string,
public readonly size: number,
public readonly updated: Date,
) {}copy(update: Partial): Apple {
return /* new object with updated fields */
}static from(obj: IApple): Apple {}
}
```### Enums
... tbd ...
## Development
This project currently uses [shadow-cljs](http://shadow-cljs.org/) to compile ClojureScript. This makes it very easy to add npm dependencies and requires nearly zero configuration.
1. (Optionally) `shadow-cljs server start` Speeds up the following commands
2. `shadow-cljs watch :test` to compile the :test target (and recompile on changes)## Comparison to alternative implementations
### Regular Expressions
Pros:
- SimpleCons:
- Prone to unforseen syntax changes### Annotation Processor
Pros:
- Integrated into compilation via [kapt](https://kotlinlang.org/docs/reference/kapt.html), no extra setup (but not with IntelliJ's build system)Cons:
- Integrated into compilaton, can't be run on it's own
- `kapt` the Kotlin annotation processing tool is quite slow
- The Java annotation processing API is not easy to use with Kotlin sources