indexion-kgf

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

indexion kgf

indexion kgf

Inspect and debug KGF language specs by viewing tokens, parse events, and extracted edges.
通过查看 token、解析事件和提取的边,检查并调试 KGF 语言规范。

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
  • 用户需要调试 indexion 处理特定文件的流程
  • 用户正在开发或修改 KGF 规范
  • 用户询问「indexion 是如何解析这个文件的?」
  • 验证某门语言的分词/解析功能是否正常工作
  • 调试 grep 模式:当 grep 模式无法匹配时,使用
    kgf tokens
    查看实际的 token 类型

Subcommands

子命令

indexion kgf inspect
— Full Inspection

indexion kgf inspect
— 完整检查

Show tokens, events, and edges all at once.
bash
indexion kgf inspect <file>
indexion kgf inspect --spec=typescript src/app.ts
一次性展示 token、事件和边。
bash
indexion kgf inspect <file>
indexion kgf inspect --spec=typescript src/app.ts

indexion kgf tokens
— Tokenization Only

indexion kgf tokens
— 仅展示分词结果

Show how a file is tokenized.
bash
indexion kgf tokens <file>
indexion kgf tokens --spec=go-mod go.mod
展示文件的分词方式。
bash
indexion kgf tokens <file>
indexion kgf tokens --spec=go-mod go.mod

indexion kgf events
— Parse Events Only

indexion kgf events
— 仅展示解析事件

Show parse events generated from tokens.
bash
indexion kgf events <file>
展示从 token 生成的解析事件。
bash
indexion kgf events <file>

indexion kgf edges
— Extracted Edges Only

indexion kgf edges
— 仅展示提取的边

Show the dependency edges extracted from a file.
bash
indexion kgf edges <file>
indexion kgf edges fixtures/project/npm/package.json
展示从文件中提取的依赖边。
bash
indexion kgf edges <file>
indexion kgf edges fixtures/project/npm/package.json

Options

选项

OptionDefaultDescription
--spec=NAME
auto-detectKGF spec name to use
--kgf-dir=PATH
kgfsKGF specs directory
选项默认值描述
--spec=NAME
自动检测要使用的 KGF 规范名称
--kgf-dir=PATH
kgfsKGF 规范目录

Relationship to grep

与 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
undefined
indexion grep
底层使用 KGF 分词功能。模式别名(
pub
KW_pub
)派生自 KGF 规范的
=== lex
部分。
当 grep 模式未按预期匹配时:
bash
undefined

1. See the actual tokens for a file

1. 查看文件的实际 token

indexion kgf tokens src/config/paths.mbt
indexion kgf tokens src/config/paths.mbt

2. Check which token kinds exist

2. 查看存在哪些 token 类型

indexion kgf tokens src/config/paths.mbt | head -20
indexion kgf tokens src/config/paths.mbt | head -20

3. Then adjust your grep pattern to match the actual token kinds

3. 调整 grep 模式匹配实际的 token 类型

indexion 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`
indexion grep "KW_pub KW_fn Ident" src/config/paths.mbt

常见 token 类型(MoonBit):
- `KW_pub`、`KW_fn`、`KW_struct`、`KW_enum`、`KW_type`、`KW_trait`、`KW_let`、`KW_for`
- `Ident`(小写标识符)、`TypeIdent`(PascalCase 类型名)
- `LPAREN`、`RPAREN`、`LBRACE`、`RBRACE`、`LBRACKET`、`RBRACKET`
- `NL`(换行符)、`SKIP`(空白符——会从 grep 模式中过滤)
- `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
  1. 运行
    indexion kgf inspect <file>
    查看完整处理流程
  2. 如果发现异常,使用
    tokens
    events
    edges
    子命令深入排查
  3. 与 KGF 规范文件(
    kgfs/<lang>.kgf
    )对比诊断问题