Regions Overview
What are regions?
A .tape file can contain multiple regions, each with its own parser and purpose. The region splitter divides the file at #region markers, then each region is processed separately.
#code
import io from "io";
var count: i64 = 0;
fn increment() { count = count + 1; }
#view
component Counter {
view {
widgets.Label { text: str.from_i64(count); }
widgets.Button { label: "+"; on_click: increment; }
}
}
#test
test "increment works" {
count = 0;
increment();
assert count == 1;
}Available regions
| Region | Purpose | Status |
|---|---|---|
#code | Standard tape logic (default) | Implemented |
#view | Component declarations | Implemented |
#test | Inline test cases | Implemented |
#style | Component styling | Planned (splitter recognizes, not processed) |
#bytecode | Inline assembly (t0) | Planned (splitter recognizes, not processed) |
#localization | Translatable strings | Planned (splitter recognizes, not processed) |
#resource | Embedded assets | Planned (splitter recognizes, not processed) |
Default region
If no region marker appears, the entire file is #code. Most programs don’t need explicit region markers.
Region ordering
Regions must appear in a fixed order. The splitter rejects out-of-order or duplicate regions:
#code → #view → #style → #localization → #resource → #test → #bytecodeNot all regions need to be present — only the ordering of those that appear is enforced.
Preamble
Content before the first explicit region marker (if any) is treated as preamble and prepended to #code. This allows imports and declarations at the top of a multi-region file to be visible in #code:
import io from "io";
import str from "str";
#code
fn greet(name: string) { io.println("hello " + name); }
#view
component App { ... }How each region is processed
#code
Parsed by the standard tape parser. Produces the module AST (functions, structs, enums, components, constants, imports).
#view
Parsed by tape_parse_view — a component-focused parser. Components declared in #view are merged into the module’s component list alongside any components in #code.
#test
Parsed by tape_parse_tests. Each test "name" { ... } block becomes a function. The test region supports:
test "description" { ... }— test casessetup { ... }— runs before each testassertexpressions and trap blocks- Test intrinsics (
__test_assert_fail,__test_fail,__test_trap_begin/end)
Tests are compiled and run via tape test <file>.
#style
#style region is recognized by the splitter but not processed. No style parser exists yet. Component styling is intended to work via CSS-like selectors targeting component names, props, and state pseudo-selectors.#bytecode, #localization, #resource
Cross-region references
#viewcomponents can reference functions and variables from#code#testcan call functions from#codeand instantiate#viewcomponents#codecan define and use components directly (no#viewrequired)
Last modified: