dmdin / Rhyton

⚙️ Simple R to Python transpiler based on Tree Sitter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rhyton logo

Rhyton - R to Python transpiler

📜 What is Rhyton

Rhyton is a type of ancient Greek drinking vessel that is in the shape of an animal's head or horn and has a hole in the bottom for pouring the liquid. It was often used in religious ceremonies or feasts.

The name came after combination of language names: R and Python

This library helps you to move R codebase to Python. Right now it supports conversion of math equations, expressions, conditions, function definitions and calls

🧲 Installation

The project is published on PyPi, so you can install it via pip

$: pip install rhyton

🚀 Launch

Use transpile or transpile_file to translate your R code

from rhyton import transpile, transpile_file

transpile('x <- 7') # returns transpiled string

# or

transpile_file(
  in_path='<path to your R file>.r', 
  out_path='<Path to generated Python file>.py'
)

🛠 How it works

Rhyton uses tree-sitter under the hood, to compute AST (Abstract Syntax Tree), after that it converts it to new AST that is valid for Python. After that it generates a code, using ast module and astor

📊 Feature plan

  • ✅ Add tree parsers

  • ✅ Semantic analysis for AST

    • ✅ Statements and expressions
    • ✅ Math operations
    • ✅ Conditions: if, else
    • ✅ Function definitions
    • ✅ Function calls
    • ❌ Cycles while and for
    • ❌ Arrays and operations
    • ❌ Function analogs
    • ❌ Import statements
    • ❌ Nested transpilation
  • ✅ Package demo publication

  • ✅ Project site

About

⚙️ Simple R to Python transpiler based on Tree Sitter


Languages

Language:Svelte 52.8%Language:Jupyter Notebook 36.2%Language:Python 8.8%Language:JavaScript 1.4%Language:HTML 0.3%Language:R 0.2%Language:CSS 0.1%Language:TypeScript 0.1%