treescript: A language to transform source code from/between different languages.

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Warnings:

Please see the README on GitHub at https://github.com/jakobeha/treescript#readme


[Skip to Readme]

Properties

Versions 0.1.0.0
Change log ChangeLog.md
Dependencies array, autoexporter, base (>=4.7 && <5), bifunctors, binary, bytestring, containers, data-msgpack, directory, exceptions, filepath, fsnotify, megaparsec (>=7.0.4), monad-logger, monad-loops, mtl, optparse-applicative, process, rainbow, semigroupoids, shelly, system-filepath, text, transformers, treescript, unix, vector, yaml [details]
License GPL-3.0-only
Copyright 2018 Jakob Hain
Author Jakob Hain
Maintainer jakobeha@gmail.com
Category Language
Home page https://github.com/jakobeha/treescript/src/master/README.md
Bug tracker https://github.com/jakobeha/treescript/issues
Source repo head: git clone https://github.com/jakobeha/treescript
Uploaded by jakobeha at 2019-03-31T15:22:14Z

Modules

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for treescript-0.1.0.0

[back to package description]

TreeScript

A language to transform source code from/between different languages.

objc'for (\i = 0; \i < \n; \i++) \expr' &Env[]: swift'for \i in 0..<\n \expr';

&Env[].
---
TypeOf[\i]: "Int";
TypeOf[\n]: "Int";
Modifies[\expr; \i]: False[];
Modifies[\expr; \n]: False[];

Install via the following commands:

stack install treescript

Purpose

TreeScript is a DSL for writing code to analyze and transform syntax trees.

TreeScript is especially designed to:

TreeScript could also:

TreeScript is very minimal, but it can easily be extended. It relies on "libraries" to handle logic and operations like function lookup. You can download libraries, or easily create them yourself in any language.

Eventually TreeScript could even transform its own syntax trees (with a TreeScript language plugin).

Motivation

Often, if you want to transform a language's syntax, you must learn and use a language-specific API (e.g. SourceKit for Swift, HaRe for Haskell, Scalameta for Scala). Or if the language doesn't have an API, you must create one yourself. Furthermore, these APIs are often implemented in languages which aren't designed for syntax transformation.

TreeScript is one API, explicitly designed to transform syntax, which works for many languages. To support a language, TreeScript only needs a specification, parser, and printer. You can transform the syntax of one language using a library created in a completely different language, or transform the syntax of your own language using a library created by someone else.

How to Use

Writing Source Code

Basically, a TreeScript program consists of reducers (syntax - <input>: <output>;). A reducer takes a specific block of code and replaces it with another block of code.

r'print(\msg)': r'cat(\msg)';

The above program transforms:

print("Hello")
print("Hola")
print("Bonjour")

into

cat("Hello")
cat("Hola")
cat("Bonjour")

See doc/Semantics.md for informal semantics, and doc/examples for examples.

Running Source Code

Run treescript run <EXEC>.tscr <INPUT> -o <OUTPUT> to take the source code from <INPUT>, transform it using <EXEC>.tscr, and write the result to <OUTPUT>.

Compiling Source Code

TreeScript programs can also be compiled into executables.

Run treescript compile <SRC>.tscr to compile <SRC>.tscr into <SRC>.tprg. Then run ./<SRC>.tprg <INPUT> -o <OUTPUT>.

How to Extend

TreeScript relies a lot on plugins. TreeScript comes with built-in plugins, and you can download or create more.

You can add/modify plugins using treescript plugin update <plugin-path> --type <lib/lang/template-lib/template-lang> (TODO). Plugins are stored in <app-data>/treescript/env (<app-data> is ~/Library/Application Support on OSX and ~/%APPDATA%/ on Windows).

See Plugins.md for how to create plugins.

Internals

See Internals.md for how the TreeScript compiler / interpreter works.

History

This is based on an earlier project, Descript.