[][src]Crate zypo_rs

About

zypo-rs is the official refrence compiler for the Zypo programming language. This compiler was built in Rust and targets Python bytecode primarily.

Objectives

Below are some of the core sentients and objectives that Zypo aims towards.

  • Python inter-compatibility
  • Compiler portability (lightweight)
  • Fast compile speeds + optimizations
  • Standard library only

Disclaimers

  • There is currently no formal standard for Zypo so please stick to a documented compiler version and stick with it
  • This project is heavily work-in-progress so please do not use this compiler in production.

Installing zypo-rs

Building from source

You can easily build zypo-rs from source using the in-built crates builder. Below are some simple steps on how to do so.

  1. Clone the zypo-rs repository with git clone https://gitlab.com/zypo/zypo-rs/
  2. Make sure you have Rust installed.
  3. Enter the repository and type cargo build to build the compiler.
  4. That's it! You have successfully built the compiler from source code. Please view the relevant documentation for further information.

Language syntax

Basic blocks and class example:

get requests;

--- This is a docstring, it is 3x `-` and they should be parsed in
--- ***MARKDOWN*** (similar to what Rust does).
fun send_url(url: string) -> string {
    if (url == null) {
        return "No URL provided";
    }
    else {
        return requests.post(url).json();
    }
}

--- CoolClass is a simple testing class that you can easily add your full name
--- to and edit if you so wish.
---
--- # Examples
---
--- ```zypo
--- var new_class: CoolClass = CoolClass("Owen", "[last_name]");
--- new_class.print_name();
---
--- new_class.change_name("John", "Matthews");
--- new_class.print_name();
--- ```
class CoolClass {
    fun __init__(self, first_name: string, last_name: string) {
        change_name(first_name, last_name);
    }

    fun print_name(self) {
        print(self.name);
    }

    fun change_name(self, first_name: string, last_name: string) {
        var self.name: string = self._swap_name_full(
            concat(" ", first_name, last_name)
        );
    }
}

fun main() {
    -- Testing send_url

    var url: string = "https://duck.com";
    var return_msg: string = "";

    try {
        return_msg = send_url(url);
    }
    catch {
        return_msg = "Unsuccessful";
    }
    else {
        print("Sent successfully!");
    }

    if (return_msg) {
        print(return_msg);
    }

    -- Testing CoolClass

    var new_class: CoolClass = CoolClass("Owen", "[last_name]");
    new_class.print_name();

    new_class.change_name("John", "Matthews");
    new_class.print_name();
}

Other infomation

Credits

Licensing

As you may find in LICENSE inside of this compiler's source code (found here), this repository is licensed under the MIT license.

Structs

Function

The function eration node. This is the AST node for a function in Zypo.

Parameter

A eration of a parameter. This would originally look like my_id: str when being parsed.

WhileLoop

A while loop. condition is the condition to run the while loop and body is the body of the while loop.

Enums

BinOp

A binary operation type.

Constant

Like VarType but with defined data in each possible option.

ExpressionNode

An expression type

StatementNode
VarType

Variable types for zypo-rs.

Functions

ast_result

Gets the abstract syntax tree generated from the parser of zypo-rs. This function will panic is parsing fails and is intended for developers aiming to implament the parser into code generation.