Skip to content

Syntax

Syntax

Thagore uses Python-style indentation for blocks and a colon at the end of block-introducing lines. The parser is strict about layout and the lexer treats indentation errors as hard errors.

Indentation

Rules:

  • indentation width is 2 spaces
  • TAB characters are rejected by the lexer
  • block headers end with :
  • if and while conditions must be wrapped in parentheses

Valid:

func main() -> i32:
let value: i32 = 3
if (value > 0):
return 0
return 1

Invalid:

func main() -> i32:
return 0

The second example uses 3 spaces and is rejected as invalid indentation.

Comments

Single-line comments start with #:

# this is a comment
func main():
# comments can appear inside blocks
println("ok")

Keywords

The current compiler recognizes these declaration and control-flow keywords directly:

KeywordRole
letlocal or top-level binding
consttop-level constant
funcfunction declaration
ifconditional branch
elsealternate branch
whileloop
forloop over Array[T]
returnreturn from function
importimport declaration
fromselective import
externexternal function declaration
structnominal struct declaration
implmethod block
intentintent declaration
flowflow declaration
includeimport ... include all form

The parser also recognizes these contextual keywords in specific positions:

Contextual keywordRole
asalias in imports
allinclude all import form
pubpublic export marker
breakloop exit
continuenext loop iteration
andboolean conjunction
orboolean disjunction
notboolean negation
infor item in items
stage, body, compensate, minimizeflow and intent bodies

Operators

The current parser uses Pratt precedence with the following order, from low to high:

LevelOperators
1=
2or
3and
4prefix not
5==, !=
6<, >, <=, >=
7+, -
8*, /, %
9prefix -
10., [], ()

Example:

func logic(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32):
return a or b and not c == d < e + f * g

Statement forms

Top-level and block-level syntax is direct and explicit:

import std.math as math
const LIMIT: i32 = 5
func classify(value: i32) -> i32:
if (value < 0):
return 1
else:
return 0

Notes on unsupported surface

The current compiler does not implement elif as a separate keyword. Use nested if inside else instead:

func classify(value: i32) -> i32:
if (value < 0):
return 0
else:
if (value == 0):
return 1
else:
return 2