The HypnoScript CLI relies on a few but effective debugging mechanisms. This guide shows how to quickly isolate errors and which commands help make program state visible.
Debug and Verbose Mode
--debugdisplays the source code, generated tokens, the AST, and type checker results before the interpreter starts.--verboseadds status messages (e.g., "Running file" or "Program executed successfully").- Both flags can be combined:
hypnoscript run script.hyp --debug --verbose.
Token and AST Analysis
bash
hypnoscript lex script.hyp
hypnoscript parse script.hyp
- Use
lexto check which keywords and literals the lexer recognizes. parseprovides the complete AST – ideal when control structures or sessions are not built as expected.
Type Checking Without Execution
bash
hypnoscript check script.hyp
- The type checker reports missing functions, incorrect return values, or unsuitable assignments.
- The CLI executes the program even with type errors; use
checkto catch errors beforehand.
Typical Debug Workflow
bash
# 1. Type Checking
hypnoscript check scripts/deep_trance.hyp
# 2. Inspect tokens & AST
hypnoscript lex scripts/deep_trance.hyp
hypnoscript parse scripts/deep_trance.hyp
# 3. Run with debug output
hypnoscript run scripts/deep_trance.hyp --debug
Tips
- Temporarily comment out complex sections (
//) and run the rest with--debugto isolate the problem locally. - For array operations,
hypnoscript builtinshelps find suitable helper functions (e.g.,ArrayJoin,ArrayContains). - Save debug output with
> debug.logif you want to compare it later (hypnoscript run script.hyp --debug > debug.log).