sigmal-docs

Sigmal Language Specification — Part 04

Surface Syntax and Core Syntax Constraints

Top > Design docs > Core design > Part 04


Sigmal surface syntax is:

All constructs are expressions.


1. Lexical Structure

1.1 Identifiers

Identifiers:

Identifiers are never reserved.

Their meaning depends solely on syntactic position.


1.2 Reserved Symbols

Only symbolic tokens are reserved:

\     abstraction
$     universe
@     symbol injection
&     record
##     inductive
.     projection
{ }   block
( )   grouping
:     type annotation
=     binding (blocks/records)
;     definition separator
->    arrow sugar
^     pattern match
=>    match arm separator

No alphanumeric keyword is reserved.

Sigmal defines no user-definable infix operators or precedence rules.


2. Expressions

All constructs are expressions.

There are no statements.

There is no let, import, or match keyword.


3. Abstraction

Dependent abstraction:

\ (x : A) -> T = body

This single form serves both:

Multiple parameters:

\ (x : A) (y : B) -> T = body

Arrow sugar:

A -> B

means:

\ (_ : A) -> B

4. Application

Application is whitespace-based.

f x
f x y
g f x

Application is left-associative:

f x y  ≡  (f x) y

Parentheses are used only for grouping:

f (g x)

Parentheses are not used for function calls.


5. Records

5.1 Record Types

&{
  k1 : T1;
  k2 : T2;
}

5.2 Record Values

&{
  k1 = v1;
  k2 = v2;
}

Field order is irrelevant.

Trailing semicolon inside records is optional.


6. Inductive Types

#{
  C1;
  C2(v : T);
}

Constructors may carry arguments.


7. Pattern Matching

Pattern matching uses ^:

^ x {
  C1 => e1;
  C2(y) => e2;
}

Patterns must be exhaustive.

^ introduces a match expression.

=> separates patterns from result expressions.


8. Projection

Projection uses ..

r.k

means:

r.@{ TextSym "k" }

Projection is left-associative:

a.b.c

means:

(a.b).c

There is no alternate meaning of . anywhere in the language.


9. Top-Level Module Access

The operator . denotes record projection.

A dot-starting projection expression:

.std.alloc

is interpreted as projection from a distinguished top-level module record supplied by the resolver.

The core language does not define a value corresponding to . itself. Instead, the resolver provides the root record used for dot-starting projection.

A resolver may choose to:

Provided that resolution is deterministic for a fixed resolver configuration and target.

The core language defines only structural record projection. Any meaning assigned to dot-starting projection is external to the core type system.


10. Symbol Injection

Symbol injection syntax:

@{ e }

where:

Valid only in symbol-key positions:

Identifiers in key positions are sugar for:

@{ TextSym "identifier" }

Note: TextSym (and related symbol construction utilities) are provided by .std.core.


11. Universes

Universe levels:

$ { e }

where:

Sugar:

$0  ≡  $ { 0 }
$1  ≡  $ { 1 }

12. Top-Level Structure

A source file consists of:

Definition syntax:

name = expr;

The final expression:

There is no implicit record wrapping of definitions.

If the final expression is a record, the compilation unit may serve as a namespace.

If not, it is simply a value.


13. Comments

Single-line comments:

// comment

Block comments:

/* comment */

Block comment nesting is implementation-defined.


14. Deterministic Parsing

Parsing is deterministic because:

No token changes meaning based on context.

There are no reserved alphanumeric keywords.


15. Summary

Sigmal surface syntax:

All syntax corresponds directly to core semantic constructs.


Sigmal.org - the calculus we can build on