Indexion Kgf

作者 trkbt107ad5ad35a668无许可证2 个星标收录于 2026年10月8日更新于 2026年10月8日仓库2周前更新

Debug and inspect KGF specs — view tokenization results, parse trees, and extracted edges from source files. Use when adding/fixing language support or when indexion's analysis output looks wrong.

AI 生成的概览

通过查看词元、解析事件和提取的依赖边来检查和调试 KGF 语言规范。

功能
封装 indexion kgf 命令行,用于列出、更新和安装 KGF 语言规范,并检查源文件的词元化结果、解析事件和提取出的依赖边。它还记录了编写 KGF 规范时的常见陷阱,例如 PEG 项顺序、文档注释与关键字之间的换行处理、自底向上的事件顺序以及词元优先级冲突。输出为终端中显示的诊断文本。
适用场景
适用于为 indexion 添加或修复语言支持、文件分析输出看起来不正确,或 grep 模式无法匹配而需要查看实际词元类型时。
运行要求
需要安装 indexion CLI 及其 kgf 子命令并可在 PATH 中调用。update 和 add 子命令会从 GitHub 下载规范,因此这些操作需要网络访问。该技能不附带脚本,仅为说明文档。

indexion kgf

Inspect and debug KGF language specs by viewing tokens, parse events, and extracted edges.

When to Use

  • User wants to debug how indexion processes a specific file
  • User is developing or modifying a KGF spec
  • User asks "how does indexion parse this file?"
  • Verifying that tokenization/parsing works correctly for a language
  • Debugging grep patterns: when a grep pattern doesn't match, use kgf tokens to see the actual token kinds

Subcommands

indexion kgf list — List Installed Specs

bash
indexion kgf list

indexion kgf update — Update All Specs

Download the latest specs from GitHub.

bash
indexion kgf update

indexion kgf add — Install a Single Spec

bash
indexion kgf add <spec-name>

indexion kgf inspect — Full Inspection

Show tokens, events, and edges all at once.

bash
indexion kgf inspect <file>indexion kgf inspect --spec=typescript src/app.ts

indexion kgf tokens — Tokenization Only

Show how a file is tokenized.

bash
indexion kgf tokens <file>indexion kgf tokens --spec=go-mod go.mod

indexion kgf events — Parse Events Only

Show parse events generated from tokens.

bash
indexion kgf events <file>

indexion kgf edges — Extracted Edges Only

Show the dependency edges extracted from a file.

bash
indexion kgf edges <file>indexion kgf edges fixtures/project/npm/package.json

Options

OptionDefaultDescription
--spec=NAMEauto-detectKGF spec name to use
--kgf-dir=PATHkgfsKGF specs directory

Relationship to grep

indexion grep uses KGF tokenization under the hood. Pattern aliases (pub → KW_pub) are derived from the === lex section of KGF specs.

When a grep pattern doesn't match as expected:

bash
# 1. See the actual tokens for a fileindexion kgf tokens src/config/paths.mbt
# 2. Check which token kinds existindexion kgf tokens src/config/paths.mbt | head -20
# 3. Then adjust your grep pattern to match the actual token kindsindexion grep "KW_pub KW_fn Ident" src/config/paths.mbt

Common token kinds (MoonBit):

  • KW_pub, KW_fn, KW_struct, KW_enum, KW_type, KW_trait, KW_let, KW_for
  • Ident (lowercase identifiers), TypeIdent (PascalCase type names)
  • LPAREN, RPAREN, LBRACE, RBRACE, LBRACKET, RBRACKET
  • NL (newline), SKIP (whitespace — filtered from grep patterns)
  • DocComment, DocLine, DocSection, LineComment, BlockComment
  • String, Number, Char

Workflow

  1. Run indexion kgf inspect <file> to see the full processing pipeline
  2. If something looks wrong, drill down with tokens, events, or edges
  3. Compare with the KGF spec file (kgfs/<lang>.kgf) to diagnose issues

KGF Development Pitfalls

Common bugs found when writing or modifying KGF specs:

PEG Item Ordering (first-match-wins)

KGF uses PEG parsing. In Item -> A / B / C, if A matches, B and C are never tried. DocComment as a standalone alternative before declaration rules will consume doc comments that should be attached to declarations.

# BAD: DocComment before FuncDecl — doc is consumed as standalone itemItem -> NL / DocComment / FuncDecl / Other
# GOOD: DocComment after declarations — FuncDecl's doc:DocComment? gets itItem -> NL / FuncDecl / DocComment / Other

NL Between Doc and Keyword

Source code has newlines between doc comments and declarations. Without NL? or NL*, the optional doc capture fails silently:

# BAD: DocComment immediately followed by keyword — NL breaks the matchFuncDecl -> doc:DocComment? KW_fn id:Ident ...
# GOOD: NL? allows the typical newline between doc and keywordFuncDecl -> doc:DocComment? NL? KW_fn id:Ident ...

Bottom-Up Event Order (bind/scope)

Events fire bottom-up: child rules before parent rules. If ExportDecl wraps FunctionDecl, FunctionDecl fires first. Use bind/$scope to pass data from child to parent:

on FunctionDecl {  bind ns "value" name "child_decl_id" to $id  edge declares from $file to sym_id attrs obj(...)}on ExportDecl when $doc {  let id = $scope("value", "child_decl_id")  edge declares from $file to sym_id attrs obj("doc", $doc, ...)}

Token Priority Conflicts

Tokens defined earlier take priority. A generic Operator /[=+\-*]+/ before EQ /=/ will consume = as Operator. Define specific tokens first:

# BAD: Operator matches = before EQ canTOKEN Operator /[!$%&*+\-.\/:<=>?@^|~]+/TOKEN EQ       /=/
# GOOD: EQ defined first, takes priorityTOKEN EQ       /=/TOKEN Operator /[!$%&*+\-.\/:<=>?@^|~]+/

Verifying Doc Extraction

After modifying a KGF, always verify doc appears in declares edges:

bash
# Must show doc="..." in the declares edgeindexion kgf edges test_file.ts --spec=typescript | grep declares
# If doc is missing, check events to see where the DocComment wentindexion kgf events test_file.ts --spec=typescript | grep DocComment

来源与署名

来源:trkbt10/indexion-skills位于skills/indexion-kgf提交7ad5ad3

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架