Core Concepts
This overview summarizes the most important building blocks of the current HypnoScript implementation. When you read the code or tests in the repository, you'll find exactly these concepts.
Program Structure
- Focus/Relax: Every script starts with
Focus {and ends with} Relax. entrance: Optional block directly afterFocus, ideal for setup and greeting.finale: Optional block beforeRelax, always executed (cleanup).
hyp
Focus {
entrance { observe "Hello"; }
// ... regular code ...
finale { observe "Goodbye"; }
} Relax
Declarations & Types
induce name: string = "Text";– mutable variable.implant– alias forinduce.freeze PI: number = 3.14159;– constant.- Arrays are denoted with
[]:induce values: number[] = [1, 2, 3];. - Supported types:
number,string,boolean, arrays, functions, sessions. Atrancetype exists in the type system but is not currently actively used.
Control & Operators
if,else if,elsewhilefor conditional loopsloopsupports both the infinite looploop { ... }and a classic headerloop (init; condition; update) { ... };pendulum (...)is an alias that always requires a condition.snap(aliasbreak),sink(aliascontinue)- Hypnotic operators like
youAreFeelingVerySleepy(==) orunderMyControl(&&) - Booleans can be toggled with
oscillate flag;
Functions
- Defined with
suggestion name(params): returnType { ... } awaken(orreturn) exits a function.- Triggers use
trigger name = suggestion(...) { ... }and behave like callbacks.
hyp
suggestion greet(name: string) {
observe "Hello, " + name + "!";
}
trigger onWelcome = suggestion(person: string) {
greet(person);
}
Sessions (Object Orientation)
session Name { ... }creates a class.- Fields:
expose(public) orconceal(private).dominantmakes fields or methods static. - Methods use
suggestion,imperativeSuggestionordominantSuggestion(the latter enforces static). - Constructors:
suggestion constructor(...) { ... }. - The interpreter injects
thisfor instance methods and prevents static members from being accessed via instances (and vice versa).
hyp
session Counter {
expose name: string;
conceal value: number = 0;
suggestion constructor(name: string) {
this.name = name;
}
expose suggestion increment() {
this.value = this.value + 1;
observe this.name + ": " + this.value;
}
}
induce c: Counter = Counter("HypnoBot");
c.increment();
Builtins
The type checker registers all standard functions. Important categories:
- Math:
Sin,Cos,Sqrt,Pow,Clamp,Factorial,Gcd,Lcm,IsPrime,Fibonacci, … - Strings:
Length,ToUpper,Trim,Replace,Split,Substring,PadLeft,IsWhitespace, … - Arrays:
ArrayLength,ArrayIsEmpty,ArraySum,ArrayAverage,ArraySlice,ArrayDistinct, … - System & Files:
GetOperatingSystem,GetUsername,GetArgs,ReadFile,WriteFile,ListDirectory, … - Time & Statistics:
CurrentTimestamp,CurrentDate,Mean,Median,StandardDeviation,Correlation, … - Validation & Utility:
IsValidEmail,MatchesPattern,HashString,SimpleRandom, …
All builtins are compactly available via hypnoscript builtins.
CLI Workflow
bash
hypnoscript lex file.hyp # Show tokens
hypnoscript parse file.hyp # Inspect AST
hypnoscript check file.hyp # Type checking
hypnoscript run file.hyp # Execute
hypnoscript compile-wasm file.hyp -o file.wat
hypnoscript version # Toolchain info
--debugwith theruncommand shows intermediate steps (source, tokens, type check).--verboseadds additional status messages.
Where to Continue Reading
- Quick Start – Your first script step by step
- CLI Basics – All subcommands in detail
- Syntax Reference – Complete grammar
- Builtin Overview – All functions by category
With these concepts, you can read the repository code easily and write your own scripts.