spline

module
v0.0.0-...-3e171d2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2022 License: MIT

README

This is official repo of so called Spline programming language.

Implementation progress:

  • lexer
  • parser
  • codegen
  • docgen
  • standart library
  • documentation
Hello world

Basic hello world programm in Spline:

pub fun main() {
    printf("hello world")
}

Loops

Basic while loop example:

generic(T int | float)
pub fun sumOfDigits(n T) T {
    let result = 0;
    while (n > 0) {
        result += (n % 10);
        n /= 10;
    }
    return result;
}

Strings

Basic strings example:

pub fun main() {
    let s = "hello world";
    printf("%s\n", s);
    printf("%d\n", s.len());

    s += "!";
    printf("%d\n", s.len());

    s.removeCharAt(2);
    s.pushCharTo(3, 'o');
    s.pushTo(4, "aa");

    printf("%s\n", s);

    let a = s.clone();

    destroy s;
    destroy a;
}

Dynamic arrays

pub fun main() {
    let a = array({1, 2.1, 3});
    printf("%d\n", a.len());

    foreach index, elem in a {
        printf("%d: %f\n", index, elem);
    }

    a.pushTo(2, 3.3);
    printf("%f", a[2]); // 3.3

    destroy a;
}

Structures

pub struct Person {
    pub name string;
    pub age int;

    pub init(name string, age int) {
        this.name = name.clone();
        this.age = age;
    }

    pub clone() *Person {
        return new Person(
            this.name,
            this.age
        );
    }

    pub destroy() {
        destroy this.name;
    }
}

Directories

Path Synopsis
cmd
spline command
pkg
ast
Package ast declares the types used to represent abstract syntax trees for Spline source files.
Package ast declares the types used to represent abstract syntax trees for Spline source files.
diagnostics
Package diagnostics provides structures for better comple-time error handling.
Package diagnostics provides structures for better comple-time error handling.
lexer
Package lexer implements a lexer for Spline source text.
Package lexer implements a lexer for Spline source text.
parser
Package parser implements a parser for Spline source files.
Package parser implements a parser for Spline source files.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL