Home

Awesome

Makrell

<img src="./doc/makrell.png" style="width:10em" />

Makrell is a family of programming languages implemented in Python. It consists currently of these languages:

The project is in an early stage of development and is not yet ready for production use.

Community: Chat on Gitter

Quick Start

Installation

pip install makrell

MakrellPy REPL usage

makrell
> 2 + 3
5
> [2 3 5] | sum
10

Run a MakrellPy script

makrell myscript.mr

IDE Support

MakrellPy is supported by the MakrellPy Language Server, included in the Makrell package. The language server is based on the LSP protocol and can be used with any LSP-compatible editor, such as Visual Studio Code, Sublime Text, Atom, Vim, Emacs etc. A VS Code extension is available here.

VS Code Extension

MakrellPy

The following is a quick introduction by example to the MakrellPy language. See examples and tests for more code examples.

Syntax

MakrellPy uses the Makrell Base Format as its base syntax (see below). MakrellPy-specific syntax is built on top of this. The following is a simple example of a MakrellPy program:

# This is a comment.
a = 2
b = a + 3
{sum [a b 5]}  # function call
[a b 5] | sum  # function call by pipe operator
sum \ [a b 5]  # function call by reverse pipe operator

# Conditional expression
{if a < b
    "a is less than b"
    "a is not less than b"}

# Function definition
{fun add [x y]
    x + y}

# Partial application
add3 = {add 3 _}
{add3 5}  # 8

# Operators as functions
a = 2 | {+ 3} | {* 5}  # 25

# Custom operators with precedence levels
{operator 😐 100
    $left + $right + 1}
{operator 😵 90
    $left - $right}
a = 2 😵 3 😐 5
a | print
{assert a == -7}
b = 2 | {😐 3}
b | print
{assert b == 6}

# A macro that composes a sequence of functions
{macro pipe [ns]
    ns = {regular ns}
    p = ns@0
    i = 1
    {while i < {len ns}
        p = {quote {unquote p} | {unquote ns@i}}
        i = i+1
    }
    p
}
f = [x] -> x * 2
mul = [x y] -> x * y
c = {pipe 3 f f {mul 10 _} f f}  # 480

Note:

Other Features

See the examples and tests directories for examples of the following features:

TODOs, wishlist and ideas

MRON

Sample MRON document:

owner "Rena Holm"
last_update "2023-11-30"

books [
    {
        title  "That Time of the Year Again"
        year   1963
        author "Norton Max"
    }
    {
        title  "One for the Team"
        year   2024
        author "Felicia X"
    }
]

The above code corresponds to the following Python dictionary tree:

{
    "owner": "Rena Holm",
    "last_update": "2023-11-30",
    "books": [
        {
            "title": "That Time of the Year Again",
            "year": 1963,
            "author": "Norton Max"
        },
        {
            "title": "One for the Team",
            "year": 2024,
            "author": "Felicia X"
        }
    ]
}

It's possible to embed MakrellPy code in MRON documents, and vice versa. Example:

a 2
b {$ 3 + 5 }

This will be evaluated to this Python dictionary:

{
    "a": 2,
    "b": 8
}

MRML

Sample MRML document:

{html
    {head
        {title A Test}
    }
    {body
        {h1 This is a Test}
        {p [style="color: red"] Just some {b bold} text here.}
    }
}

The above code corresponds to the following HTML:

<html>
    <head>
        <title>A Test</title>
    </head>
    <body>
        <h1>This is a Test</h1>
        <p style="color: red">Just some <b>bold</b> text here.</p>
    </body>
</html>

It's possible to embed MakrellPy code in MRML documents, and vice versa. Example:

{a [b = {$ [2 3 5 7] | sum}] asd}

This will be evaluated to:

<a b="17">asd</a>

Makrell Base Format

The Makrell Base Format is a simple data format that forms the basis for both MakrellPy, MRON and MRML. It is a simple text-based format that is easy to read and write. It is designed to be easy to parse and generate, and to be easy to work with in a text editor.

These element types are supported:

For parsing purposes, the following element types are also defined:

In addition, the following element type is defined in the core library:

License

Makrell is developed by Hans-Christian Holm and licensed under the MIT License. See LICENSE for details.