Wyrd

Build Status Coverage Status

Wyrd is a strongly-typed toy programming language whose syntax is partially inspired by Ruby lang.

Although it may be a personal project, it is evolving in high speed. 🔥

Check out new released Wryd documentation here! 🚧Under Construction 🚧

Wyrd programming language compiles its code into JavaScript. The primary goal would be to write Front-End code and Back-End code (NodeJS) using Wyrd programming language. I may want to try writing React (or Vue) component code using Wyrd lang if possible.

Why the "Wyrd" Name?

Wyrd although officially pronounced as "weird", but sometimes I accidentally pronounce it as "w-ei-rid". However, personally I think both of them are okay.

Wyrd is a concept in Anglo-Saxon culture roughly corresponding to fate or personal destiny. The word is ancestral to Modern English weird, which retains its original meaning only dialectically.

The cognate term in Old Norse is urðr, with a similar meaning, but also personalized as one of the Norns, Urðr and appearing in the name of the holy well Urðarbrunnr in Norse mythology.

Install CLI

Install the CLI globally:

npm install -g @wyrd/cli

Check if the CLI is installed successfully:

which wyrd

Create a simple "Hello world!" program and the file name will be hello.wyrd:

# hello.wyrd

def greet(msg: Str): Str => msg
def greet(prefix: Str, msg: Str): Str do
  prefix.concat("! ").concat(msg)
end

greet("Hello", "Wyrd is awesome!")
greet("Wyrd is created by Alexius!")

Run the program:

wyrd -e hello.wyrd

It should compile into hello.js file with the following content:

function greet(msg) {
  return msg;
}

function greet_1(prefix, msg) {
  return prefix.concat('! ').concat(msg);
}

greet_1('Hello', 'Wyrd is awesome!');
greet('Wyrd is created by Alexius!');

Congratulations! You've just compiled your first Wyrd program!

You can also view the wyrd-cli repository for more information about the usage of CLI.

@wyrd/cli is in early development, there will be more features released such as more compilation options. (e.g. the minify option which compiles the minified version of the program)

Table of Content [WIP]

  • Variable and Constant Declarations

    • Constant Declaration

    • Variable Declaration

    • "maybe" Types Declaration

  • Built-in Types

    • Primitives

      • Numbers, Strings and Booleans

      • Concept of "Empty" - Null

    • Lists

      • List Literal

      • Encourages Homogeneous Typed List

  • Arithmetics

    • Arithmetic Expressions

    • Precedence

    • Prioritization

  • Logical Expressions

    • Comparison Operators

    • Comparison Operators Accept Identical Types Only

    • Logical Chaining

  • Conditional Expressions

    • Basic Syntax

      • "One-Liner" If-Arrow Expression

      • "Single-Line-Block" If-Then Expression

      • "Multi-Line-Block" If-Do Expression

    • Conditional Expression Returns Value

    • If-Condition Must Receive Boolean Type

    • Return Type of Each Branch Must Be Identical

    • Conditional Expression Without Else Part Returns "Maybe" Types

  • Function Declaration

    • Components of Function's Declaration

    • Declaration Syntax

      • "Do-Block" Declaration

      • "One-Liner Arrow" Declaration

      • Functions Without Arguments

      • Returned Result Type Checking

    • Function Overriding

      • Function Redeclaration is Prohibited

      • Overriding Function

      • Before and After Override Function

      • Allows Change of Output Types

    • Function Overloading

      • Identical Function Name with Different Arguments Pattern

      • Overriding Overloaded Function

  • Functions (Legacy)

  • Comment (Legacy)

Supported Syntax Rules

Method Invocation

Wyrd Code

# Builtin Methods for Primitives
"Hello world".repeat(3)
"Wyrd Lang is Awesome".upcase()
(1 + 2 * 3).toStr()

# Chained Invocation
"Hello".concat(" world").concat(", Wyrd-Lang!")

# Invocation as Parameter
"Hello".concat(" world".concat(", Wyrd-Lang!"))

Compiled Result

('Hello world').repeat(3);
('Wyrd Lang is Aweseom').toUpperCase();
(1 + (2 * 3)).toString();
('Hello').concat(' world').concat(' , Wyrd-Lang!');
('Hello').concat((' world').concat(' , Wyrd-Lang!'));

Function Invocation

Wyrd Code

funcA("Hello world")
funcB(1, 2, 3)
funcC(1, 2, funcD(3, 4), 5)
funcE(1, funcF(2, 3, funcG(4)), 5)
funcI(1, (funcJ(2, 3) + 4) * funcK(5))
funcL(1 / (funcM(2, 3) - 4), 5)
funcN((1 - funcO(2) * 3) / 4, funcP(5))

Compiled Result

funcA('Hello world');
funcB(1, 2, 3);
funcC(1, 2, funcD(3, 4), 5);
funcE(1, funcF(2, 3, funcG(4)), 5);
funcI(1, (funcJ(2, 3) + 4) * funcK(5));
funcL(1 / (funcM(2, 3) - 4), 5);
funcN((1 - (funcO(2) * 3)) / 4, funcP(5));

Comment

Wyrd Code

foo = 123 # Singleline comment

##
Multiline comment
##

bar = ## Comment between expression ## 456

Compiled Result

const foo = 123;
const bar = 456;

Maintainers

Last updated