Crate umbra_lang[][src]

Expand description

A simple macro-based language inspired by Rust and Python.

This crate can be used either directly as an interpreter binary or embedded in another program.

Parsing is still a little weird but just add parentheses! :^)

Direct Usage

To run the REPL simply use cargo run. To see examples of possible code constructs look at the scripts in test/. You can run scripts by providing the name as an argument as follows: cargo run -- scriptname. You can also run modules with cargo run -- modname. This is the same as running cargo run -- modname/main.um. One such module is test.

Embedded Usage

This crate can be added to your dependencies by adding the following to your project’s Cargo.toml:

[dependencies]
umbra_lang = "0.19"

To use the library, call the desired run*() functions (documented below). For example:

let env = Env::prelude();
let (vars, val) = run_path("script.um", &env, true);

Crate Features

  • readline - Default, enables use of rustyline for input in run_interactive().
  • compile - Enables the ability to serialize ASTs and deserialize them for execution. This is generally untested and currently not any faster than normal.

Macros

teprintln

Prints to the current Thread’s local error out.

tprintln

Prints to the current Thread’s local output.

Structs

Args

A collection of interpreter flags and script arguments.

Env

The environment that scripts use to store and access variables.

Pos

Denotes a specific position within a script.

RefTVal

A reference to a TVal, locked via Mutex.

Runnable

A collection of all data required for final script execution.

TVal

A Type-Value pair along with an attribute map.

ThreadHandle

The context for a running Thread. Can be joined from multiple threads.

Token

A piece of the tokenized script.

Enums

AST

The parsed representation of a script expression.

Callable

A function that is either called natively via Rust or run via an AST.

Error

An error that occured during argument handling, parsing, script execution, or for control flow or other purposes.

FnArgs

Function arguments for various types of functions.

TokenType

Easily differentiates Tokens.

Type

A representation of a kind of Value. Most variants just represent the corresponding Value variants.

Value

A representation of any valid value in a script.

Functions

compile

Splits, tokenizes, parses, and constructs a Runnable from script. Generally not necessary to use directly.

run

Compiles the script then executes it in the given environment.

run_interactive

Start an interactive interpreter session (REPL) in the given environment.

run_path

Loads a script from path and runs it in the given environment.

Type Definitions

FnReturn

A pair of updated environment vars and the evaluated value.