Skip to main content

Mo - Modern, Expressive, Fast Programming Language

Project description

Mo Language

Mo is a lightweight, dynamically-typed scripting language with a clean syntax, a bytecode compiler, and a growing standard library.

Installation

pip install mo-language

After installing, use the mo command:

mo program.mo

Quick Example

fn greet(name) {
    print("Hello, " + name + "!")
}

greet("world")
pip install mo-language

After installing, use the mo command:

mo program.mo

Windows users: If mo is not found after install, add Python's Scripts folder to your PATH.
Mac/Linux users: If mo is not found, run the command the installer prints.

Language Guide

Variables

let x = 42
let name = "Mo"
let flag = true
let nothing = null

Reassign with = (no let):

x = x + 1

Types

Type Example
Number 3.14, 100
String "hello"
Bool true, false
Null null
List [1, 2, 3]
Dict {"key": "value"}

Operators

1 + 2        # arithmetic: + - * /
x == y       # equality: == !=
x < y        # comparison: < > <= >=
true && false  # logical: && ||
!true          # not

String concatenation uses +:

let msg = "Hello, " + "world"

Control Flow

if x > 0 {
    print("positive")
} else if x < 0 {
    print("negative")
} else {
    print("zero")
}
let i = 0
while i < 5 {
    print(i)
    i = i + 1
}
for item in [1, 2, 3] {
    print(item)
}

Functions

fn add(a, b) {
    return a + b
}

let result = add(3, 4)   # 7

Functions are first-class values:

let double = fn(x) { return x * 2 }

Lists

let nums = [10, 20, 30]
print(nums[0])          # 10
push(nums, 40)          # append
let last = pop(nums)    # remove last
print(len(nums))        # 3

Dicts

let user = {"name": "Alice", "age": 30}
print(user["name"])     # Alice
user["age"] = 31

for k in keys(user) {
    print(k + ": " + str(user[k]))
}

Dict keys can also be accessed with .:

print(user.name)
user.age = 32

Classes

class Animal {
    fn init(name) {
        self.name = name
    }
    fn speak() {
        print(self.name + " makes a sound")
    }
}

class Dog extends Animal {
    fn speak() {
        print(self.name + " barks")
    }
}

let d = Dog("Rex")
d.speak()   # Rex barks

Error Handling

try {
    throw "something went wrong"
} catch e {
    print("Caught: " + e)
}

Imports

import "std/math"
print(math_sqrt(16))   # 4.0

Standard Library

All stdlib modules are imported with import "std/<name>".

Core Modules

Module Description
std/math Math functions (sqrt, pow, abs, sin, cos, etc.)
std/random Random numbers (int, float, choice)
std/time Time functions (now, sleep, format)
std/json JSON parse/stringify
std/file File operations (read, write, append, exists, delete)
std/os OS operations (getEnv, cwd, exit)
std/path Path manipulation (join, dir, base, ext, abs)
std/string String operations (toUpper, toLower, trim, split, replace)

Data Formats

Module Description
std/yaml YAML parse/stringify
std/xml XML processing
std/csv CSV parse/stringify
std/base64 Base64 encoding/decoding

Databases & Cache

Module Description
std/sqlite SQLite database
std/redis Redis client
std/cache LRU cache

Networking

Module Description
std/http HTTP server and client
std/net TCP/UDP networking
std/url URL parsing
std/websocket WebSocket client

Security & Validation

Module Description
std/crypto SHA256, HMAC
std/jwt JWT authentication
std/validator Email, URL, phone validation

GUI & Media

Module Description
std/gui Tkinter GUI
std/audio Audio playback

Text Processing

Module Description
std/regex Regular expressions
std/template Template engine
std/fmt String formatting

Utilities

Module Description
std/datetime Date/time handling
std/logging Logging system
std/uuid UUID generation
std/gzip Compression
std/decimal High precision decimals
std/config Config file loader (TOML/YAML/JSON)
std/cli CLI argument parsing
std/test Unit testing framework

Data Structures

Module Description
std/list List operations (map, filter, reduce)
std/collections Stack, queue, set, heap
std/concurrency Threads and locks

System

Module Description
std/process Process management
std/email SMTP email sending

Note: Built-in functions like print, len, str, input, range can be used directly without import.


Built-in Functions

Function Description
print(x) Print value
len(x) Length of string/list/dict
str(x) Convert to string
num(x) Convert to number
type(x) Type name string
range(n) / range(a,b) List of integers
push(list, val) Append to list
pop(list) Remove and return last element
keys(dict) List of dict keys
has(dict, key) True if key exists
delete(dict, key) Remove key from dict
input(prompt) Read line from stdin
floor(x) Floor
ceil(x) Ceil
round(x) Round
abs(x) Absolute value

Testing

Run pytest Suite (Recommended)

pip install pytest
pytest tests/test_basic.py -v

The pytest suite covers core language features:

  • Variables, operators, functions
  • Lists, control flow (if/while/for)
  • Exceptions (try/catch/throw)
  • Built-in functions

Run Python Test Runner

python tests/test_runner.py          # run all tests
python tests/test_runner.py -v       # verbose mode
python tests/test_runner.py test.mo   # run specific file

The test runner discovers .mo test files in tests/, runs them with mo, and checks exit code.

Run Mo Test Files Directly

mo tests/run_tests.mo

Note: Some test files may have parser compatibility issues with newer language features.

Example test metadata file (tests/foo.mo.meta.json):

{
  "exit_code": 0,
  "output": "42"
}

CLI Reference

mo program.mo           # run with bytecode VM (default)
mo --interp program.mo  # run with tree-walk interpreter
mo --dis program.mo     # disassemble bytecode
mo                      # interactive REPL

Requirements

  • Python 3.9+
  • No external dependencies (stdlib only)

std/http fetch functions use urllib (built-in). For advanced HTTP needs, install requests separately.


Advanced Features

Type System

let x: int = 42          # type annotation
let y = 10  # int         # type comment

is_number(x)              # check type
is_string(x)
is_bool(x)
is_list(x)
is_dict(x)

cast(x, "string")         # type cast

std/regex

import "std/regex"

regex_match("^[a-z]+", "hello")   # true/false
regex_replace("cat", "the cat sat", "dog")  # "the dog sat"
regex_split("\\s+", "a b c")    # ["a", "b", "c"]

std/sqlite

import "std/sqlite"

let db = sqlite_open("data.db")
let rows = sqlite_exec(db, "SELECT * FROM users WHERE age > ?", [18])

for row in rows {
    print(row["name"])
}

sqlite_close(db)

std/yaml

import "std/yaml"

yaml_parse("key: value")       # string → dict
yaml_stringify({"key": "val"}) # dict → string

std/xml

import "std/xml"

xml_parse("<root><item>text</item></root>")  # string → element
xml_to_string(elem)                     # element → string

std/csv

import "std/csv"

csv_read("data.csv")                  # list of dicts
csv_write("output.csv", [{"a": "1"}])  # write list of dicts

std/net

import "std/net"

let sock = net_listen(8080)

while true {
    let conn = net_accept(sock)
    let data = net_recv(conn)
    net_send(conn, "HTTP/1.0 200 OK\r\n\r\nHello")
    net_close(conn)
}

std/gui

GUI module using Python's tkinter (requires pip install pillow for images).

import "std/gui"

let win = window("My Game", 800, 600)

rectangle(100, 100, 50, 50, "#00ff00")
circle(300, 200, 30, "#ff0000")
text(100, 160, "Player", 16, "#ffffff")
line(0, 0, 800, 600, "#888888")

on_click(fn(pos) {
    print("Clicked at: " + str(pos))
})

on_key(fn(key) {
    print("Pressed: " + key)
})

loop()

std/audio

import "std/audio"

audio_play("sound.mp3")

Package Manager

Mo has a package ecosystem for sharing reusable modules.

Search packages

mo search redis
mo search http

Install packages

mo install user/repo           # from GitHub
mo install user/repo@v1.0.0    # specific version
mo install https://example.com/foo.mo  # direct URL

List installed packages

mo list

Remove a package

mo remove <package-name>

Publish a package

mo publish

See mo publish for detailed publishing instructions.


LSP (Language Server Protocol)

Mo includes an LSP server for IDE editor support (hover, completion, diagnostics).

Start LSP Server

mo lsp                    # Start via stdio
mo lsp --stdio            # Explicit stdio mode
mo lsp --tcp --port 8765  # TCP mode on port 8765

VS Code Extension

A VS Code extension scaffold is provided in mo-vlang/:

  • package.json - VS Code extension configuration
  • syntaxes/mo.tmLanguage.json - Syntax highlighting
  • src/extension.ts - LSP client

To install the extension:

cd mo-vlang
npm install
code .
# Press F5 to run the extension in development mode

Supported Features

  • Hover: Hover over variables to see their type
  • Completion: Auto-complete keywords and symbols
  • Diagnostics: Real-time syntax error reporting

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mo_language-0.4.6.tar.gz (148.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mo_language-0.4.6-cp314-cp314-macosx_26_0_arm64.whl (174.7 kB view details)

Uploaded CPython 3.14macOS 26.0+ ARM64

File details

Details for the file mo_language-0.4.6.tar.gz.

File metadata

  • Download URL: mo_language-0.4.6.tar.gz
  • Upload date:
  • Size: 148.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for mo_language-0.4.6.tar.gz
Algorithm Hash digest
SHA256 463e4090a533c7a0d79a9f96c235f941be0b017a6a17d7f70cedbd80d7446dfd
MD5 43bdfa526d48a36a88c13f2e745afcbe
BLAKE2b-256 dd810f97f2032d1bee648796c40e1c1b093c754302ad7d8a3c716521a25c9880

See more details on using hashes here.

File details

Details for the file mo_language-0.4.6-cp314-cp314-macosx_26_0_arm64.whl.

File metadata

File hashes

Hashes for mo_language-0.4.6-cp314-cp314-macosx_26_0_arm64.whl
Algorithm Hash digest
SHA256 491b46e9c402711aff1cbd2eb0d3ec356f04e889e15f4890f32221588ac2baf1
MD5 7fdfb643aa87b9134266fe85c3a72ab8
BLAKE2b-256 3f9844dcf7f43610eb9dabcdabf4820155989bac591a4e369c1cfc1ba367e55e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page