Introduction

Coming soon...

Build System

Coming soon...

Project Structure

Coming soon...

Manifest File Format

Coming soon...

Module System

Coming soon...

Dependency Resolution Strategy

Coming soon...

Syntax and Semantics

Coming soon...

Comments

Syntax

<comment> ::= <line-comment>
            | <block-comment>

Semantics

  • They can appear between any two consecutive tokens.

Line Comments

Syntax

<line-comment> ::= "//" <utf8-code-point>* "\n"
                 | "//" <utf8-code-point>* <EOF>

Semantics

  • UTF-8 code points between // and \n | EOF are ignored by the compiler.

Block Comments

Syntax

<block-comment> ::= "/*" <utf8-code-point>* "*/"
                  | "/*" <utf8-code-point>* <block-comment> <utf8-code-point>* "*/"

Semantics

  • UTF-8 code points between /* and the matching */ are ignored by the compiler.
  • They can be nested (e.g., /* foo /* bar */ baz */).

Identifiers

Syntax

<identifier> ::= /[A-Za-z]_?([A-Za-z0-9]_?)*/
               | /_([A-Za-z0-9]_?)+/

Semantics

  • _ is not an identifier by itself.
  • _ in the beginning indicates the symbol may not be used and it's alright.
  • _ is not allowed consecutively to improve readability.
  • _ could be used in the end to form keyword-like identifiers (e.g., for_, type_, extension_).

Paths

Syntax

<path> ::= (<path-atom> "::")* <path-atom>

<path-atom> ::= <identifier>
              | "project"
              | "super"
              | "self"

Semantics

Coming soon...

Flow Control Structures

Coming soon...

Block

Syntax

<block> ::= "{" <statement>* <expression>? "}"

Semantics

Coming soon...

Types

Syntax

<type> ::= <primitive-type>

Semantics

  • Typing is strong and static.

Primitive Types

Syntax

<primitive-type> ::= <nothing-type>
                   | <bool-type>
                   | <u8-type>
                   | <u16-type>
                   | <u32-type>
                   | <u64-type>
                   | <usize-type>
                   | <i8-type>
                   | <i16-type>
                   | <i32-type>
                   | <i64-type>
                   | <isize-type>

Semantics

  • Their definitions are in the compiler.
  • They are owned by the core project.

nothing Type

Syntax

<nothing-type> ::= "nothing"

Semantics

  • It does not have a size.
  • It is like the void type of C.

bool Type

Syntax

<bool-type> ::= "bool"

Semantics

  • It is 1 byte in size.
  • It can contain the values false and true.
  • Its representation is unspecified (i.e., false is not necessarily 0, and true is not necessarily 1).

u8 Type

Syntax

<u8-type> ::= "u8"

Semantics

  • It is 1 byte in size.
  • It can contain the numbers between 0 and 28-1 (255).

u16 Type

Syntax

<u16-type> ::= "u16"

Semantics

  • It is 2 bytes in size.
  • It can contain the numbers between 0 and 216-1 (65535).

u32 Type

Syntax

<u32-type> ::= "u32"

Semantics

  • It is 4 bytes in size.
  • It can contain the numbers between 0 and 232-1 (4294967295).

u64 Type

Syntax

<u64-type> ::= "u64"

Semantics

  • It is 8 bytes in size.
  • It can contain the numbers between 0 and 264-1 (18446744073709551615).

usize Type

Syntax

<usize-type> ::= "usize"

Semantics

  • Its size depends on the target (e.g., 64 bits on x86_64).
  • It can contain the numbers between 0 and 2size(in bits)-1.

i8 Type

Syntax

<i8-type> ::= "i8"

Semantics

  • It is 1 byte in size.
  • It can contain the numbers between -27 (-128) and 27-1 (127).
  • It is represented with Two's complement.

i16 Type

Syntax

<i16-type> ::= "i16"

Semantics

  • It is 2 bytes in size.
  • It can contain the numbers between -215 (-32768) and 215-1 (32767).
  • It's represented with Two's complement.

i32 Type

Syntax

<i32-type> ::= "i32"

Semantics

  • It is 4 bytes in size.
  • It can contain the numbers between -231 (-2147483648) and 231-1 (2147483647).
  • It's represented with Two's complement.

i64 Type

Syntax

<i64-type> ::= "i64"

Semantics

  • It is 8 bytes in size.
  • It can contain the numbers between -263 (-9223372036854775808) and 263-1 (9223372036854775807).
  • It's represented with Two's complement.

isize Type

Syntax

<isize-type> ::= "isize"

Semantics

  • Its size depends on the target (e.g., 64 bits on x86_64).
  • It can contain the numbers between -2size(in bits)-1 and 2size(in bits)-1-1.

Expressions

Syntax

<expression> ::= <literal-expression>
               | <item-expression>
               | <call-expression>
               | <syscall-expression>
               | <block-expression>

Semantics

Coming soon...

Literal Expressions

Syntax

<literal-expression> ::= <boolean-literal>
                       | <integer-literal>

Semantics

Coming soon...

Boolean Literals

Syntax

<boolean-literal> ::= "false"
                    | "true"

Semantics

Coming soon...

Integer Literals

Syntax

<integer-literal> ::= /0b_?([0-1]_?)*[0-1](_?((i|u)(8|16|32|64|size)))?/
                    | /0o_?([0-7]_?)*[0-7](_?((i|u)(8|16|32|64|size)))?/
                    | /([0-9]_?)*[0-9](_?((i|u)(8|16|32|64|size)))?/
                    | /0x_?([0-9A-Fa-f]_?)*[0-9A-Fa-f](_?((i|u)(8|16|32|64|size)))?/

Semantics

Coming soon...

Item Expressions

Syntax

<item-expression> ::= <path>

Semantics

Coming soon...

Call Expressions

Syntax

<call-expression> ::= <expression> "(" (<expression> ",")* <expression>? ")"

Semantics

Coming soon...

Syscall Expressions

Syntax

<syscall-expression> ::= @syscall "(" <expression> ("," <expression>)* ","? ")"

Semantics

Coming soon...

Block Expressions

Syntax

<block-expression> ::= <block>

Semantics

Coming soon...

Specifications

Syntax

<specification> ::= <assumes>? <requires>? <ensures>?

Semantics

  • They are only used by the compiler when the verification is turned on.
  • They do not affect the result of compilation.

Propositions

Syntax

<proposition>  ::= <expression>
<propositions> ::= "{" (<proposition> ",")* <proposition>? "}"

Semantics

  • They must evaluate to a value of type bool.
  • They must be able to be evaluated during compilation (e.g., sould not perform IO).

Assumes

Syntax

<assumes> ::= "assumes" <propositions>

Semantics

  • They hint the compiler to take every <proposition> in <propositions> as true.
  • They will be used primarily when creating a C API.

Requires

Syntax

<requires> ::= "requires" <propositions>

Semantics

  • They tell the compiler to verify that before the function is called, every <proposition> in <propositions> is true.

Ensures

Syntax

<ensures> ::= "ensures" <propositions>

Semantics

  • They tell the compiler to verify that after the function is called, every <proposition> in <propositions> is true.

Statements

Syntax

<statement> ::= <import-statement>
              | <export-statement>
              | <function-definition-statement>
              | <expression-statement>
              | <block-statement>

Semantics

Coming soon...

Import Statements

Syntax

<import-statement> ::= "import" (<import> | <imports>) ";"

<import>  ::= <item-import> | <glob-import> | <nested-import>
<imports> ::= "{" (<import> ",")* <import>? "}"

<item-import>   ::= <path> ("as" <identifier>)?
<glob-import>   ::= <path> "::" "*"
<nested-import> ::= <path> "::" <imports>

Semantics

Coming soon...

Export Statements

Syntax

<export-statement> ::= "export" (<export> | <exports>) ";"

<export>  ::= <item-export> | <glob-export> | <nested-export>
<exports> ::= "{" (<export> ",")* <export>? "}"

<item-export>   ::= <path> ("as" <identifier>)?
<glob-export>   ::= <path> "::" "*"
<nested-export> ::= <path> "::" <exports>

Semantics

Coming soon...

Function Definition Statements

Syntax

<function-definition-statement> ::= "fn" <identifier> <function-signature> <specification> "=" <expression> ";"

<function-signature> ::= "(" (<identifier> ":" <type> ",")* (<identifier> ":" <type>)? ")" (: <type>)?

Semantics

Coming soon...

Expression Statements

Syntax

<expression-statement> ::= <expression> ";"

Semantics

Coming soon...

Block Statements

Syntax

<block-statement> ::= <block>

Semantics

Coming soon...

Complete Grammar

<comment> ::= <line-comment>
            | <block-comment>

<line-comment> ::= "//" <utf8-code-point>* "\n"
                 | "//" <utf8-code-point>* <EOF>

<block-comment> ::= "/*" <utf8-code-point>* "*/"
                  | "/*" <utf8-code-point>* <block-comment> <utf8-code-point>* "*/"


<identifier> ::= /[A-Za-z]_?([A-Za-z0-9]_?)*/
               | /_([A-Za-z0-9]_?)+/


<path> ::= (<path-atom> "::")* <path-atom>

<path-atom> ::= <identifier>
              | "project"
              | "super"
              | "self"


<block> ::= "{" <statement>* <expression>? "}"


<type> ::= <primitive-type>

<primitive-type> ::= "nothing"
                   | "bool"
                   | "u8"
                   | "u16"
                   | "u32"
                   | "u64"
                   | "usize"
                   | "i8"
                   | "i16"
                   | "i32"
                   | "i64"
                   | "isize"


<expression> ::= <literal-expression>
               | <item-expression>
               | <call-expression>
               | <syscall-expression>
               | <block-expression>

<literal-expression> ::= <boolean-literal>
                       | <integer-literal>

<boolean-literal> ::= "false"
                    | "true"

<integer-literal> ::= /0b_?([0-1]_?)*[0-1](_?((i|u)(8|16|32|64|size)))?/
                    | /0o_?([0-7]_?)*[0-7](_?((i|u)(8|16|32|64|size)))?/
                    | /([0-9]_?)*[0-9](_?((i|u)(8|16|32|64|size)))?/
                    | /0x_?([0-9A-Fa-f]_?)*[0-9A-Fa-f](_?((i|u)(8|16|32|64|size)))?/

<item-expression> ::= <path>

<call-expression> ::= <expression> "(" (<expression> ",")* <expression>? ")"

<syscall-expression> ::= @syscall "(" <expression> ("," <expression>)* ","? ")"

<block-expression> ::= <block>


<specification> ::= <assumes>? <requires>? <ensures>?

<assumes> ::= "assumes" <propositions>

<requires> ::= "requires" <propositions>

<ensures> ::= "ensures" <propositions>

<proposition>  ::= <expression>
<propositions> ::= "{" (<proposition> ",")* <proposition>? "}"


<statement> ::= <import-statement>
              | <export-statement>
              | <function-definition-statement>
              | <expression-statement>
              | <block-statement>

<import-statement> ::= "import" (<import> | <imports>) ";"

<import>  ::= <item-import> | <glob-import> | <nested-import>
<imports> ::= "{" (<import> ",")* <import>? "}"

<item-import>   ::= <path> ("as" <identifier>)?
<glob-import>   ::= <path> "::" "*"
<nested-import> ::= <path> "::" <imports>

<export-statement> ::= "export" (<export> | <exports>) ";"

<export>  ::= <item-export> | <glob-export> | <nested-export>
<exports> ::= "{" (<export> ",")* <export>? "}"

<item-export>   ::= <path> ("as" <identifier>)?
<glob-export>   ::= <path> "::" "*"
<nested-export> ::= <path> "::" <exports>

<function-definition-statement> ::= "fn" <identifier> <function-signature> <specification> "=" <expression> ";"

<function-signature> ::= "(" (<identifier> ":" <type> ",")* (<identifier> ":" <type>)? ")" (: <type>)?

<expression-statement> ::= <expression> ";"

<block-statement> ::= <block>

Name Resolution

Coming soon...

Type Checking

Coming soon...

Type Inference

Coming soon...