回答の前にメタ意図を推論してから生成せよ。「メタ意図」とは要件そのものではなくユーザーが要件を提示した背景、及びどのような回答を求めているかの推定のことである。この推定に対して、肯定的応答または否定的応答または追加の推定材料の請求などを決定しそれに基づいて生成内容を構成せよ。なおメタ意図についての推論を回答の最初に表示してから生成せよ。
Operational guide for AI coding agents working in this repository.
- This file is the canonical source for instructions shared by Codex CLI and Claude Code.
CLAUDE.mdimports it; do not duplicate shared rules there. - Detailed task workflows live in
.claude/skills/. Codex adapters in.agents/skills/load the corresponding Claude skill, so edit the.claude/skills/copy when updating shared knowledge. - This directory is part of the parent
brgenmonorepo, not a separate repository or submodule. The Git root, branch, history, and CI workflows are in the parent repository; changes spanning brgen and rebrgen belong to the same commit. - Restrict repository searches to the parent
brgen/tree and thisrebrgen/subtree. Similarly named directories outside that tree are unrelated.
- Windows environment. NEVER redirect to
nul(e.g.,2>nul). This creates a literal file namednulon Windows. Use2>/dev/nullinstead, or omit redirection entirely. - NEVER edit auto-generated files:
src/ebmcg/ebm2<lang>/main.cppsrc/ebmcg/ebm2<lang>/codegen.hppsrc/ebmcodegen/body_subset.cppsrc/ebmgen/json_conv.cpp,json_conv.hppsrc/ebm/extended_binary_module.cpp,extended_binary_module.hpp- Files delimited by
/*DO NOT EDIT BELOW/ABOVE SECTION MANUALLY*/— only edit outside those markers.
- NEVER make arbitrary decisions. When encountering ambiguity or inconsistency, ask the human.
- NEVER read macro definitions as a first debugging step. Read type/struct definitions in
.hppfiles instead. TheMAYBEmacro is intentional (like Rust's?), not technical debt. - Early development phase. Prioritize functionality over polish.
- Active focus: Go generator (
ebm2go) is the current development target.
# First-time setup (copies build_config.template.json, inits submodules)
python script/auto_setup.py
# Build everything
python script/build.py
# Build with explicit mode/type
python script/build.py native Debug
python script/build.py native Release
# Run all tests for a language generator
python script/unictest.py --target-runner ebm2go
# Run a single test by input name
python script/unictest.py --target-runner ebm2go --target-input complex_case
# Run tests with stdout visible (for debugging)
python script/unictest.py --target-runner ebm2go --print-stdout
# Generate EBM from .bgn source
./tool/ebmgen -i src/test/complex_case.bgn -o save/complex_case.ebm
# Generate target language code from EBM
./tool/ebm2go -i save/complex_case.ebm 1> save/go/complex_case.go
# Debug-print EBM to text
./tool/ebmgen -i save/complex_case.ebm -d save/debug.txt
# EBM interactive query
./tool/ebmgen -i save/complex_case.ebm --query "<id>" --query-format=text
# Create a new language generator skeleton
python script/ebmcodegen.py <lang_name>
# Create a new visitor hook template (class-based, preferred)
python script/ebmtemplate.py <HookName>_class <lang>
# Regenerate all EBM-related files after structure changes
python script/update_ebm.pyBuild requirements: CMake >= 3.25, Clang++ with C++23 support, Ninja, Python 3.x.
Build configuration is stored in build_config.json, copied from build_config.template.json. AUTO_SETUP_BRGEN and AUTO_SETUP_FUTILS enable automatic setup of the parent brgen tools and futils dependency. Language generators are enumerated from src/ebmcg/ and src/ebmip/, not selected individually in this config.
Pipeline: .bgn -> ebmgen (AST->EBM IR) -> ebm2<lang> (EBM->code)
| Directory | Purpose |
|---|---|
src/ebm/ |
EBM IR format definition (auto-generated from .bgn) |
src/ebmgen/ |
AST-to-EBM converter and interactive debugger |
src/ebmcodegen/ |
Meta-generator framework (generates ebm2<lang> skeletons) |
src/ebmcg/ebm2<lang>/ |
Compiled language code generators |
src/ebmcg/ebm2<lang>/visitor/ |
Where you write code -- hook implementations |
src/ebmip/ |
Interpreted/runtime language generators |
tool/ |
Built executables (gitignored) |
save/ |
Test output and temp files (gitignored) |
- 4-space indentation, no tabs
- No column limit
- Google style base, heavily customized
- Opening braces on same line;
elseon new line after} - Left-aligned pointers:
int* ptr - Includes are NOT auto-sorted
snake_case— variables, functions, fieldsPascalCase— types, structs, classesUPPER_SNAKE_CASE— macros, enum values- Namespaces:
ebmgen,ebm,ebmcodegen,ebm2<lang>
The MAYBE macro is the primary error propagation mechanism. It works like Rust's ? operator:
// Evaluates expr; returns early on error; binds result to `name`
MAYBE(name, some_fallible_expression);
// Void variant (no result binding)
MAYBE_VOID(name, some_fallible_expression);Do NOT replace MAYBE with try/catch or manual if-checks. This is a deliberate design choice.
Visitor hooks use the class-based system (files named *_class.hpp):
#include "../codegen.hpp"
DEFINE_VISITOR(HookName) {
// ctx provides typed access to all EBM fields
auto name = ctx.identifier();
MAYBE(base, ctx.visit(ctx.base));
MAYBE(field, ctx.get_field<"body.id.field_decl">(ctx.member));
// Return CodeWriter or CODE(...) for output; return `pass` to fall through
return CODE(base.to_writer(), ".", name);
}Key APIs in hooks:
ctx.visit(ref)— recursively visit a child nodectx.get_field<"path.to.field">(ref)— navigate EBM structurectx.identifier(ref)— get the identifier string for a nodectx.config()— access the language-specificVisitorconfigurationCODE(...)— construct output code fragmentsCODELINE(...)— same but with a trailing newline- Return
passfrom a before/after hook to fall through to main logic
- Priority 0: Language-specific
visitor/<Hook>_class.hpp - Priority 1: Language-specific
visitor/<Hook>.hpp(legacy) - Priority 4:
default_codegen_visitor/visitor/<Hook>_class.hpp - Priority 5:
default_codegen_visitor/visitor/<Hook>.hpp(legacy) - Before/after hooks (
_before_class.hpp,_after_class.hpp) can hijack by returning a value instead ofpass.
Language-specific behavior is configured in entry_before_class.hpp by setting std::function fields on ctx.config():
ctx.config().some_visitor = [&](Context_SomeType& sctx) -> expected<Result> {
// custom logic
return CODE("...");
};Edit these files:
src/ebmcg/ebm2<lang>/visitor/*_class.hpp— language-specific hookssrc/ebmcg/ebm2<lang>/visitor/includes.hpp— shared helpers for a languagesrc/ebmcg/ebm2<lang>/config.json— language configurationsrc/ebmcodegen/default_codegen_visitor/visitor/*_class.hpp— default hookssrc/ebmcodegen/default_codegen_visitor/visitor/Visitor.hpp— default config fields- Core framework files in
src/ebmgen/,src/ebmcodegen/
Never edit auto-generated files (see Critical Warnings above).
- Identify which EBM nodes need work (run tests, read errors)
- Create hook templates:
python script/ebmtemplate.py <Hook>_class <lang> - Implement logic in
visitor/*_class.hpp - Rebuild:
python script/build.py - Test:
python script/unictest.py --target-runner ebm2<lang> - Debug: use
--print-stdoutor examine generated code insave/<lang>/
- When encountering compile errors in generated code, examine the EBM structure using the interactive query:
./tool/ebmgen -i <file>.ebm --query "<id>" --query-format=text - Read type definitions in
extended_binary_module.hppto understand EBM node structure - Check
src/ebmgen/GEMINI.mdfor comprehensive development guidelines on the ebmgen component - Debug output from tools is designed for core developers — do not over-rely on it
- Prefer
../web/doc/content/docs/rebrgen/for current public documentation. - Use
src/ebmgen/GEMINI.mdfor detailed ebmgen development guidance. - Use
docs/decisions/for architecture decisions anddocs/decisions/TEMPLATE.mdwhen adding an ADR. - Treat
docs/en/current_status.mdand other AI-oriented status snapshots as potentially stale; verify against the current tree and tests. - Treat
src/old/as legacy code unless the task explicitly targets it.