|
| 1 | +# Syntax Guide |
| 2 | + |
| 3 | +Original Source: [Vala Syntax Guide](https://wiki.gnome.org/Projects/Vala/Syntax) |
| 4 | + |
| 5 | +The syntax of Vala is similar to C#, modified to better fit the GObject type system. Vala supports modern language features as the following: |
| 6 | + |
| 7 | +- OOP (classes, abstract classes, mixin interfaces, type polymorphism) |
| 8 | +- Namespaces |
| 9 | +- Delegates |
| 10 | +- Properties |
| 11 | +- Signals |
| 12 | +- Property change notifications |
| 13 | +- Foreach |
| 14 | +- Lambda expressions / Closures |
| 15 | +- Type inference for local variables |
| 16 | +- Generics |
| 17 | +- Non-null types |
| 18 | +- Assisted memory management (automatic reference counting) |
| 19 | +- Deterministic destructors (suitable for RAII) |
| 20 | +- Exception handling (checked exceptions) |
| 21 | +- Asynchronous methods (coroutines) |
| 22 | +- Preconditions and postconditions (contract programming) |
| 23 | +- Run-time type information |
| 24 | +- Named constructors |
| 25 | +- Verbatim strings and string templates |
| 26 | +- Array and string slicing |
| 27 | +- Conditional compilation |
| 28 | +- Dynamic and static D-Bus support |
| 29 | +- C# like syntax |
| 30 | +- C ABI compatibility |
| 31 | +- Experimental: |
| 32 | + - Chained relational expressions |
| 33 | + - Regular expression literals |
| 34 | + - Main blocks |
| 35 | + |
| 36 | +## Keywords |
| 37 | + |
| 38 | +- Selection: `if, else, switch, case, default` |
| 39 | +- Iteration: `do, while, for, foreach, in` |
| 40 | +- Jumping: `break, continue, return` |
| 41 | +- Exception Handling: `try, catch, finally, throw` |
| 42 | +- Synchronization: `lock, unlock` |
| 43 | +- Type Declaration: `class, interface, struct, enum, delegate, errordomain` |
| 44 | +- Type Modifiers: `const, weak, unowned, dynamic` |
| 45 | +- Modifiers: `abstract, virtual, override, signal, extern, static, async, inline, new, sealed, partial` |
| 46 | +- Access Modifiers: `public, private, protected, internal` |
| 47 | +- Method Parameters: `out, ref` |
| 48 | +- Method Contract Keywords: `throws, requires, ensures` |
| 49 | +- Namespaces: `namespace, using` |
| 50 | +- Operator Keywords: `as, is, in, new, delete, sizeof, typeof` |
| 51 | +- Access Keywords: `this, base` |
| 52 | +- Literal Keywords: `null, true, false` |
| 53 | +- Property Context: `get, set, construct, default, value` |
| 54 | +- Construction Blocks: `construct, static construct, class construct` |
| 55 | +- Other: `void, var, yield, global, owned, with` |
| 56 | + |
| 57 | +## Operators |
| 58 | + |
| 59 | +- Arithmetic: `+`, `-`, `*`, `/`, `%` |
| 60 | +- Bitwise: `~`, `&`, `|`, `^`, `<<`, `>>` |
| 61 | +- Relational: `<`, `>`, `<=`, `>=` |
| 62 | +- Equality: `==`, `!=` |
| 63 | +- Logic: `!`, `&&`, `||` |
| 64 | +- Assignment: `=`, `+=`, `-=`, `*=` , `/=`, `%=`, `&=`, `|=`, `^=`, `<<=`, `>>=` |
| 65 | +- Increment, Decrement: `++`, `--` |
| 66 | +- Pointer: `&`, `*`, `->`, `delete` |
| 67 | +- Conditional: `?:` |
| 68 | +- Null-Coalescing: `??` |
| 69 | +- String Concatenation: `+` |
| 70 | +- Method Invocation: `()` |
| 71 | +- Member Access: `.` |
| 72 | +- Index: `[]` |
| 73 | +- Slice: `[:]` |
| 74 | +- Lambda: `=>` |
| 75 | +- Casting: `(`_Type_`)`, `(!)`, `as` |
| 76 | +- Type Checking: `is` |
| 77 | +- Ownership Transfer: `(owned)` |
| 78 | +- Namespace Alias Qualifier: `::` (currently only with `global`) |
| 79 | +- Other: `new`, `sizeof`, `typeof`, `in` |
0 commit comments