Build and Run Mech Programs

Basic Usage

Usage

Commands

Arguments

Options

Running a Mech Program

Subcommands

format

serve

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]... [COMMAND]

Commands

Command

Description

format

Format Mech source code into standard format.

serve

Serve Mech program over an HTTP server.

help

Print help message.

Arguments

Source .mec files and directories. You can specify one or more .mec files or directories containing Mech scripts. The command will execute the specified files in the order they are provided, and alpha-numeric sorting is applied to the files.

  [mech_paths]... 

Options

Option

Description

-d, --debug

Prints debug information.

-e, --tree

Prints the parse tree of the Mech program.

-t, --time

Measures execution time of the program.

-r, --repl

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

Running a Mech Program

To execute a Mech script, provide the path to one or more .mec files or directories containing Mech scripts. The command will execute the specified files in the order they are provided:

mech program.mec
mech script1.mec script2.mec dir1

Subcommands

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.

Example:

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).

Example:

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