// CONTENTS Part 08 · APIs and contracts

// PART 08

BASIC API, grammar, and codegen

Chapter 36 / 56 3 min read English Part 08 of 14

Built from the registrations in botserver/crates/botbasic_*/src/** and botserver/src/basic/keywords/**, plus the compiler’s directive table and rewrite aliases. Regenerate with:

python3 scripts/gen_basic_reference.py            # write the pages
python3 scripts/gen_basic_reference.py --check     # fail on drift
python3 scripts/gen_basic_reference.py --report    # inventory only

Composite keyword registrations: 276 (257 distinct forms) · functions: 274 · rewrite aliases: 41 · compiler directives: 14

Status legend

Status Meaning
registered register_custom_syntax / register_fn exists
alias-of-rewrite rewritten by convert_multiword_keywords.rs
directive consumed by the compiler preprocessor, not a runtime syntax
documented-only named by get_all_keywords() with no registration

Categories

The keyword families map to the crates that register them:

Crate Family
botbasic_core arrays, math, validation, datetime, strings, control flow, hearing, procedures, errors
botbasic_data database operations, tables, memory, KB, CRM, products
botbasic_comms messaging, email, SMS, social, chat, webhooks, calendar
botbasic_ai LLM, AI tools, MCP, sandbox, orchestration, web scraping
botbasic_system bot management, file ops, scheduling, security, app server, face API
botbasic_compiler the compiler itself: syntax transforms, goto logic, save conversion, tool parsing
botserver/src/basic/keywords/ host-local registrations (card, preview, post_to, answer mode, agent, reference glue)

The honest audit: advertised vs registered

--report also diffs what get_all_keywords() advertises against what is actually registered. Today: 148 names advertised, 29 not registered — including ADD TOOL (used by 20 .bas templates), AUDIT LOG, AUTO TASK, BOT REFLECTION, BROADCAST TO BOTS, CHECK CONSTRAINTS, DECIDE, MCP INVOKE, MCP LIST TOOLS, OPTION A OR B, PLAN START/PLAN END, POST HTTP, PUT HTTP, REQUIRE APPROVAL, SAVE FROM UNSTRUCTURED and the SECURITY * family.

Practical consequences:

  • A script calling an advertised-but-unregistered keyword fails at runtime, not at documentation time — check the report before shipping a template.
  • The documented-only list is the queue for the two legitimate fixes: register the keyword, or stop advertising it. Documenting it as available is not an option.
  • ADD TOOL is the highest-impact example: 20 shipped templates use it, so it either needs a registration or a template sweep.

How a keyword becomes a tool definition

The compiler extracts tool metadata from .bas headers:

PARAM name AS string LIKE "John Smith" DESCRIPTION "User's full name"
PARAM age AS number LIKE 25 DESCRIPTION "User's age"
DESCRIPTION "Processes user registration"
  • Tool name = file name without .bas.
  • Parameters come from PARAM declarations; the description from DESCRIPTION.
  • Definitions are stored in the basic_tools table and emitted in both MCP (input_schema) and OpenAI function formats for discovery.
  • Recompilation is triggered by file changes and ETag changes in Drive.

Limitations, stated plainly: parameters are declared at the top of the script, types are the basic set (string, number, boolean), all parameters are required, and nested/array parameters are not supported.

Testing a keyword change

cargo test -p botbasic_compiler        # compiler transforms
cargo test -p <keyword crate>          # keyword behavior
python3 scripts/gen_basic_reference.py --check   # reference drift

Found a mistake? Open an issue · All books

// SEARCH ESC
Pagefind · 236 pages · 4 books Enter to open ↑ ↓ to move