Skip to content
/ surn Public

A powerful Transpiler to transpile a friendly easy to use syntax to PHP

License

Notifications You must be signed in to change notification settings

Suruloon/surn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Surn

A powerful transpiler enabling you to write in one syntax, many languages.

What is Surn?

Surn is a powerful source-to-source compiler that allows anyone to write in one syntax, but recieve the benefits of using multiple languages by compiling to that language.

Supported Languages

Language Surn Version Source
PHP 8.x.x v0.0.1-alpha.rc.1 master
C v0.0.1-beta.rfc.12

How to support a language?

Surn uses a poly filling language known as "sast".

Here's an example that compiles the following code to JS.

The surn code:

use std::fmt;

var hello: string = "Hello, {?}";
var world: string = "World!";

pub fn main() {
    print(hello.fmt(world));   
}

The js.sast file:

translate VarStatement(var @> name, assignment):
    name = var.name
    right = var.assignment?
    
    return:
        // Anything below a return block with proper indentation is translated
        let $name = $assignment;

translate FunctionStatement(fn @> name):
    args = fn.inputs map(input: input.name)

    return:
        function $name(${"," <@ args}) {
            ${NEW_LINE <@ fn.body}
        }
    }

translate CallExpression(call @> name, args) {
    return:
        {name}({", " <@ args});
}

support [std.fmt] fmt((owner is String), (append is Any)):
    return:
        function fmt(owner, append) {
            // js has it's own conversion for strings
            return $owner.split("{?}").join($append.toString());
        }

support [std.io] print((v is Any)):
    return:
        function print(v) {
            console.log(v);
        }

Translates to:

/**
 * This file was gernerated by the Surn Compiler.
 * Surn: https://github.com/Suruloon/surn
 *
 * @std: std-js options: [mangled: true]
 *
 * Copyright (c) 2021, Suruloon Studios. All rights reserved.
 * Licensed under the CC0-1.0 License.
 */
function a1krm(_e, _d) {
    return _e.split('{?}').join(_d);
}

function b93af(_a) {
    console.log(_a);
}

/**
 * User script
 * @author surn
 */
let hello = "Hello, {?}";
let world = "World!";

function main() {
    b93af(a129(hello, world));
}

About

A powerful Transpiler to transpile a friendly easy to use syntax to PHP

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages