Slang

Example code

# this is a comment
#| and that is a
	multiline one. |#

const u32 n = 123123   # n: const u32 (unsigned 32 bit)
const i64 m = 10**18   # m: const i64 (signed 64 bit)
const int z = 2**128   # z: const int (signed unsized)
const auto q = 2**256  # q: const int (signed unsized)

char f(str x) {        # f(): char, x: str
    auto c = x[1]      # c: char
    return c           # char
}

auto g(str x) {        # g(): char, x: str
    return x[0]        # char
}

int h(int x) = x+1     # h(): int, x: int

main {
    stdio.println(h(n), \  # comments allowed here too
        f('123asd') + g('32') + 1)      #--> «123124 f»
    stdio.println(q/z/2**96)            #--> «4294967296.0»
}

Tokens

Token resolution order

  1. Special
  2. Operator
  3. Literal
  4. Keyword
  5. Identifier

Syntax structures

Note: * after syntax unit means any number of them.

Abstract

Primitive

Non-final

? — if present then argument value, none else.
+ — tuple with at least one argument.
* — tuple with any number of arguments.
** — object with keyword arguments.
= — default value if argument not specified.

Final (ordered by resolution order)

Keywords

Modifiers

Reserved keywords

Identifiers

Non-empty sequence of alphanumeric characters plus underscore («_»), not starting with a digit character.

Regex: [^\W\d][\w]*

Data types

Literals

Note: * after syntax unit here means any number of them, + means at least one.

Literal structures

Operators

Character operators

A set of pre-defined character operators:

Keyword operators

A set of pre-defined keyword operators:

Specials

Footnotes

All character class checks are performed in current locale.



by Sdore, 2021-22
slang.sdore.me