Skip to main content

Lexical Structure

This document describes the low-level lexical structure of Mux: tokens, keywords, identifiers, literals, and comments.

Source Files

Mux source files use UTF-8 encoding. File extension is .mux.

Case Sensitivity

Mux is case-sensitive. Keywords, identifiers, and type names must match the exact case as defined.

snippet.mux
Loading...

Whitespace

The only significant whitespace in Mux is the Newline character (\n), which separates statements. Other whitespace characters (space, tab, carriage return) are ignored except for separating tokens.

snippet.mux
Loading...

Multi-Line Comments

Multi-line comments start with /* and end with */. They can span multiple lines:

snippet.mux
Loading...

Multi-line comments do not nest. The first */ terminates the comment.

Identifiers

Identifiers name variables, functions, types, and other entities.

Rules

  • Must start with a letter
  • Can contain letters, digits, and underscores
  • Cannot be a reserved keyword

Valid Identifiers

snippet.mux
Loading...

Note: Most Mux code uses snake_case, with some exceptions of course, but this is a convention, not a requirement.

Invalid Identifiers

snippet.mux
Loading...

Underscore Placeholder

The underscore _ is a special identifier used as a placeholder:

snippet.mux
Loading...

The underscore has special semantics:

  • Cannot be read (assigning to _ discards the value)
  • Multiple uses of _ in the same scope do not conflict

Keywords

The following words are reserved keywords and cannot be used as identifiers:

Declaration Keywords

KeywordPurpose
funcFunction declaration
returnsReturn type specification for functions
constConstant declaration
autoType inference declaration
classClass declaration
interfaceInterface declaration
enumEnum declaration
commonStatic/class method

Control Flow Keywords

KeywordPurpose
matchPattern matching expression
ifConditional expression
elseElse branch of conditional
forIteration loop
whileWhile loop
breakExit loop
continueSkip to next iteration
returnReturn from function

Module Keywords

KeywordPurpose
importModule import
asImport alias

Operator Keywords

KeywordPurpose
isType constraint / interface implementation
inMembership test
trueBoolean true literal
falseBoolean false literal
noneoptional none literal
someoptional some literal
okresult ok literal
errresult error literal

Special Keywords

KeywordPurpose
selfInstance reference (inside class methods only)

Literals

Integer Literals

Decimal integers:

snippet.mux
Loading...

Float Literals

snippet.mux
Loading...

Character Literals

Single Unicode code point in single quotes:

snippet.mux
Loading...

String Literals

UTF-8 sequences in double quotes:

snippet.mux
Loading...

Escape sequences:

  • \\ - Backslash
  • \" - Double quote
  • \' - Single quote
  • \n - Newline
  • \t - Tab
  • \r - Carriage return

Boolean Literals

snippet.mux
Loading...

none Literal

snippet.mux
Loading...

Operators and Punctuation

Arithmetic Operators

SymbolMeaning
+Addition
-Subtraction / Negation
*Multiplication
/Division
%Modulo
**Exponentiation

Comparison Operators

SymbolMeaning
==Equality
!=Inequality
<Less than
<=Less than or equal
>Greater than
>=Greater than or equal

Logical Operators

SymbolMeaning
&&Logical AND (short-circuit)
`
!Logical NOT

Other Operators

SymbolMeaning
=Assignment
+=Compound assignment
-=Compound assignment
*=Compound assignment
/=Compound assignment
%=Compound assignment
++Postfix increment
--Postfix decrement
.Member access
&Reference creation
*Dereference

Punctuation

SymbolUsage
( )tuple literals, Grouping, function calls, parameters
[ ]List literals, indexing
{ }Block statements, map literals, set literals
< >Type parameters (generics)
,Separator

Line Continuation

Mux does not support implicit line continuation. Each statement must be on its own line. The only way to continue an expression across lines is with explicit grouping:

snippet.mux
Loading...

See Also