Build and Run Mech Programs

Basic Usage

Usage

Subcommands

Arguments

Options

Examples

Subcommands

build

Options

Examples

format

Options

Examples

serve

Options

Examples

Additional Help

Build and Run Mech Programs

The mech command-line tool provides various functionalities for working with Mech programs, including executing scripts, debugging, formatting code, and serving applications over HTTP. Below are the available options and subcommands.

Basic Usage

Usage

mech [OPTIONS] [mech_paths]... [SUBCOMMAND]

Subcommands

Command

Description

build

Build Mech program into bytecode.

format

Format Mech source code into standard format.

help

Print help message.

serve

Serve Mech program over an HTTP server.

Arguments

Source .mec files and directories. You can specify one or more .mec/.mecb files, or directories containing Mech scripts / bytecode.

If you run the Mech command without any files or subcommands, it will start the REPL.

Options

Option

Description

-d, --debug

Prints debug information.

-r, --repl

Starts the Mech Read-Eval-Print Loop (REPL).

-t, --time

Measures execution time of the program.

-e, --tree

Prints the parse tree of the Mech program.

Examples

mech file1.mec file2.mec dir1
mech -d -e file.mec
mech -t file.mec
mech -r file.mec

Subcommands

build

Compiles Mech source code into bytecode.

mech build [OPTIONS] [FILES]

Options

Option

Value

Description

-o, --out

PATH

Specifies the output directory.

Examples

mech build -o out_dir file1.mec
mech build -o out_dir file1.mec file2.mec dir1 dir2

format

Formats Mech source code into a standard format.

mech format [OPTIONS] [FILES]

Options

Option

Value

Description

-o, --out

PATH

Specifies the output directory.

-s, --stylesheet

STYLESHEET

Sets the stylesheet for HTML output.

-t, --html

Outputs formatted code as HTML.

Examples

mech format -o formatted/ my_script.mec

serve

Serves a Mech program over an HTTP server.

mech serve [OPTIONS] [FILES]

Options

Option

Value

Description

-p, --port

PORT

Sets the port for the server (default: 8081).

-a, --address

ADDRESS

Sets the server address (default: 127.0.0.1).

Examples

mech serve -p 3000 -a 0.0.0.0 my_script.mec

Additional Help

For more information on a specific command, you can use the --help option with that command. For example:

mech --help
mech serve --help