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.

tape
#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

RegionPurposeStatus
#codeStandard tape logic (default)Implemented
#viewComponent declarationsImplemented
#testInline test casesImplemented
#styleComponent stylingPlanned (splitter recognizes, not processed)
#bytecodeInline assembly (t0)Planned (splitter recognizes, not processed)
#localizationTranslatable stringsPlanned (splitter recognizes, not processed)
#resourceEmbedded assetsPlanned (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:

plaintext
#code → #view → #style → #localization → #resource → #test → #bytecode

Not 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:

tape
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 cases
  • setup { ... } — runs before each test
  • assert expressions and trap blocks
  • Test intrinsics (__test_assert_fail, __test_fail, __test_trap_begin/end)

Tests are compiled and run via tape test <file>.

#style

PlannedThe #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

PlannedThese regions are recognized by the splitter but not processed. They are reserved for future use.

Cross-region references

  • #view components can reference functions and variables from #code
  • #test can call functions from #code and instantiate #view components
  • #code can define and use components directly (no #view required)

Last modified: