DEVELOPMENT EDITION · 769442725406
Vibe syntax
On this page

Vibe source and lexical structure

Vibe source files use the .vb extension and are read as UTF-8. Names are made of ASCII letters, digits and underscores (B0001 otherwise). A string may hold any Unicode character: a str is a text of code points, as Python's is.

Lines, indentation, and comments

A logical statement normally ends at the physical newline. Blank lines and comment-only lines do not open or close a block. # begins a comment extending to the end of the physical line. There is no block-comment delimiter. A string used as a standalone statement is treated as documentation and omitted from execution; a leading string in a function is its docstring. Comments participate in translation, but identical placement after translation is not guaranteed.

An increase in indentation opens a block after a colon; a decrease must return to an indentation depth already established by an enclosing block. Use spaces. Tabs in indentation or dedents to an unmatched depth produce B0201. Four spaces are a useful convention; the lexer tracks actual indentation depths rather than requiring a fixed width.

Inside (), [], or {}, physical lines join into one logical line. A backslash immediately before a newline also joins the lines. Use bracketed continuation for ordinary code. A semicolon separates simple statements on one logical line, with an optional trailing semicolon. A colon may introduce either an indented suite or a simple-statement suite:

if ready:
    send()
else: wait()

This is a statement fragment: ready, send, and wait must be defined with suitable types. Compound statements such as another if need their own suite; a semicolon is not a way to put arbitrary compound statements on one line.

Names and keywords

Names follow [A-Za-z_][A-Za-z_0-9]*. Case matters. A name beginning with _ is hidden from the module's public interface. Restrictions on module-level case collisions and fields are explained under names.

The reserved words are:

False None True and as assert async await break class continue def del
elif else except finally for from global if import in is lambda nonlocal
not or pass raise return try while with yield

They are reserved as in Python, including the ones Vibe's statements do not use (async, await, yield; see the excluded features). match, case, type, and _ are soft keywords, as in Python: keywords in their grammar positions, names elsewhere.

Numeric literals

Kind Examples Meaning
Decimal integer 0, 123, 1_000 Exact integer literal, subsequently constrained by context
Hexadecimal 0x2a, 0XFF Integer in base 16
Octal 0o52 Integer in base 8
Binary 0b101010 Integer in base 2
Decimal real 1.0, .5, 2., 1e3, 1.25e-2 Exact decimal literal before conversion to its runtime real type

A leading sign is an operator, not part of a numeric token. Underscores separate digits as in Python, one between two digits (or after a base's prefix, 0x_ff): 1__0, 1_ and 1_.5 are B0004. Imaginary literals such as 2j are B0004: Vibe has no complex type.

Integer/static evaluation can hold values larger than a runtime integer while resolving a constant. The final typed value still needs to fit its type. int is signed 64-bit Integer; float is Long_Float. See types and integer ranges for exact bounds.

Ordinary and raw strings

Single and double quotes have the same value meaning. Triple quotes permit a multiline ordinary string. Adjacent ordinary string tokens concatenate during parsing:

message = "Hello, " 'Vibe'

This assignment fragment has the value Hello, Vibe. Escapes are Python's:

Escape Character
\n \t \r Line feed, tab, carriage return
\a \b \f \v Bell, backspace, form feed, vertical tab
\\ \' \" Backslash and quotes
\0, \ooo Octal, one to three digits: "\101" is A
\xhh Two hexadecimal digits
\uhhhh, \Uhhhhhhhh A character by its code point, up to 10FFFF
backslash and newline Nothing: the string continues on the next line

Any other backslash stays in the string with the character after it, as in Python: "a\qb" is the four characters a\qb. A named escape, \N{...}, is B0602: write the character, or \u and its code.

Prefixes r/R introduce raw strings, in which a backslash is an ordinary character (a backslash before a quote keeps both, as in Python). b/B bytes literals are B0001: Vibe's text is str.

Vibe's str is immutable copyable text. A literal can be resolved as a Character when a character context requires one, or as a fixed string in a context requiring that type. Neither choice gives it Python's arbitrary Unicode semantics. The expression rules cover indexing, images, and conversions.

Formatted strings

f"..." and f'...' support literal text and expression fields. Double braces produce literal braces. For example, the reference project contains:

print(f"text {text[0]} {len(text)} {{ok}}")

With text = "Vibe", it prints text L 4 {ok}. A field is an expression, and its value is written as print writes it (strings and printing).

After the expression, a field takes Python's other parts:

f"""...""" spans lines as a triple-quoted string does, and rf"..." (or fr"...") keeps its backslashes, as a raw string does; its fields are still fields.

Delimiters

The delimiters and operators are Python's. @ is the matrix product of Array matrices (expressions), and ... is the placeholder body of an abstract or protocol method. The grammar gives every production and the operator precedence.

Source evidence: lexer, tokens and reserved words, and parser.