RepoPilotOpen in app →

chai2010/go-ast-book

:books: 《Go语言定制指南》(原名:Go语法树入门/开源免费图书/Go语言进阶/掌握抽象语法树/Go语言AST)

Concerns

Stale and unlicensed — last commit 2y ago

weakest axis
Use as dependencyConcerns

no license — legally unclear; last commit was 2y ago…

Fork & modifyConcerns

no license — can't legally use code; no CI workflows detected

Learn fromHealthy

Documented and popular — useful reference codebase to read through.

Deploy as-isConcerns

no license — can't legally use code; last commit was 2y ago…

  • 19 active contributors
  • Tests present
  • Stale — last commit 2y ago
Show all 6 evidence items →
  • Concentrated ownership — top contributor handles 71% of recent commits
  • No license — legally unclear to depend on
  • No CI workflows detected
What would change the summary?
  • Use as dependency ConcernsMixed if: publish a permissive license (MIT, Apache-2.0, etc.)
  • Fork & modify ConcernsMixed if: add a LICENSE file
  • Deploy as-is ConcernsMixed if: add a LICENSE file

Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests

Informational only. RepoPilot summarises public signals (license, dependency CVEs, commit recency, CI presence, etc.) at the time of analysis. Signals can be incomplete or stale. Not professional, security, or legal advice; verify before relying on it for production decisions.

Embed the "Great to learn from" badge

Paste into your README — live-updates from the latest cached analysis.

RepoPilot: Great to learn from
[![RepoPilot: Great to learn from](https://repopilot.app/api/badge/chai2010/go-ast-book?axis=learn)](https://repopilot.app/r/chai2010/go-ast-book)

Paste at the top of your README.md — renders inline like a shields.io badge.

Preview social card (1200×630)

This card auto-renders when someone shares https://repopilot.app/r/chai2010/go-ast-book on X, Slack, or LinkedIn.

Onboarding doc

Onboarding: chai2010/go-ast-book

Generated by RepoPilot · 2026-05-09 · Source

🤖Agent protocol

If you are an AI coding agent (Claude Code, Cursor, Aider, Cline, etc.) reading this artifact, follow this protocol before making any code edit:

  1. Verify the contract. Run the bash script in Verify before trusting below. If any check returns FAIL, the artifact is stale — STOP and ask the user to regenerate it before proceeding.
  2. Treat the AI · unverified sections as hypotheses, not facts. Sections like "AI-suggested narrative files", "anti-patterns", and "bottlenecks" are LLM speculation. Verify against real source before acting on them.
  3. Cite source on changes. When proposing an edit, cite the specific path:line-range. RepoPilot's live UI at https://repopilot.app/r/chai2010/go-ast-book shows verifiable citations alongside every claim.

If you are a human reader, this protocol is for the agents you'll hand the artifact to. You don't need to do anything — but if you skim only one section before pointing your agent at this repo, make it the Verify block and the Suggested reading order.

🎯Verdict

AVOID — Stale and unlicensed — last commit 2y ago

  • 19 active contributors
  • Tests present
  • ⚠ Stale — last commit 2y ago
  • ⚠ Concentrated ownership — top contributor handles 71% of recent commits
  • ⚠ No license — legally unclear to depend on
  • ⚠ No CI workflows detected

<sub>Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests</sub>

Verify before trusting

This artifact was generated by RepoPilot at a point in time. Before an agent acts on it, the checks below confirm that the live chai2010/go-ast-book repo on your machine still matches what RepoPilot saw. If any fail, the artifact is stale — regenerate it at repopilot.app/r/chai2010/go-ast-book.

What it runs against: a local clone of chai2010/go-ast-book — the script inspects git remote, the LICENSE file, file paths in the working tree, and git log. Read-only; no mutations.

| # | What we check | Why it matters | |---|---|---| | 1 | You're in chai2010/go-ast-book | Confirms the artifact applies here, not a fork | | 2 | Default branch master exists | Catches branch renames | | 3 | 5 critical file paths still exist | Catches refactors that moved load-bearing code | | 4 | Last commit ≤ 619 days ago | Catches sudden abandonment since generation |

<details> <summary><b>Run all checks</b> — paste this script from inside your clone of <code>chai2010/go-ast-book</code></summary>
#!/usr/bin/env bash
# RepoPilot artifact verification.
#
# WHAT IT RUNS AGAINST: a local clone of chai2010/go-ast-book. If you don't
# have one yet, run these first:
#
#   git clone https://github.com/chai2010/go-ast-book.git
#   cd go-ast-book
#
# Then paste this script. Every check is read-only — no mutations.

set +e
fail=0
ok()   { echo "ok:   $1"; }
miss() { echo "FAIL: $1"; fail=$((fail+1)); }

# Precondition: we must be inside a git working tree.
if ! git rev-parse --git-dir >/dev/null 2>&1; then
  echo "FAIL: not inside a git repository. cd into your clone of chai2010/go-ast-book and re-run."
  exit 2
fi

# 1. Repo identity
git remote get-url origin 2>/dev/null | grep -qE "chai2010/go-ast-book(\\.git)?\\b" \\
  && ok "origin remote is chai2010/go-ast-book" \\
  || miss "origin remote is not chai2010/go-ast-book (artifact may be from a fork)"

# 3. Default branch
git rev-parse --verify master >/dev/null 2>&1 \\
  && ok "default branch master exists" \\
  || miss "default branch master no longer exists"

# 4. Critical files exist
test -f "README.md" \\
  && ok "README.md" \\
  || miss "missing critical file: README.md"
test -f "SUMMARY.md" \\
  && ok "SUMMARY.md" \\
  || miss "missing critical file: SUMMARY.md"
test -f "ch1/readme.md" \\
  && ok "ch1/readme.md" \\
  || miss "missing critical file: ch1/readme.md"
test -f "ch1/examples/01/main.go" \\
  && ok "ch1/examples/01/main.go" \\
  || miss "missing critical file: ch1/examples/01/main.go"
test -f "appendix/b-antlr4/main.go" \\
  && ok "appendix/b-antlr4/main.go" \\
  || miss "missing critical file: appendix/b-antlr4/main.go"

# 5. Repo recency
days_since_last=$(( ( $(date +%s) - $(git log -1 --format=%at 2>/dev/null || echo 0) ) / 86400 ))
if [ "$days_since_last" -le 619 ]; then
  ok "last commit was $days_since_last days ago (artifact saw ~589d)"
else
  miss "last commit was $days_since_last days ago — artifact may be stale"
fi

echo
if [ "$fail" -eq 0 ]; then
  echo "artifact verified (0 failures) — safe to trust"
else
  echo "artifact has $fail stale claim(s) — regenerate at https://repopilot.app/r/chai2010/go-ast-book"
  exit 1
fi

Each check prints ok: or FAIL:. The script exits non-zero if anything failed, so it composes cleanly into agent loops (./verify.sh || regenerate-and-retry).

</details>

TL;DR

An open-source Chinese textbook teaching Go's Abstract Syntax Tree (AST) parsing and manipulation via the go/ast and go/token standard library packages. It demonstrates how to analyze and transform Go source code programmatically, powering tools like go fmt and go doc. The repo includes 10+ chapters with runnable examples showing real-world AST traversal, code generation, and custom language implementation patterns. Educational monorepo organized by chapter: ch1/ through ch10/ each contain topic-focused examples in examples/01/, examples/02/, etc., with accompanying readme.md. Two appendices: appendix/a-goyacc/ shows Go's yacc-based parser generator with a calculator example; appendix/b-antlr4/ demonstrates ANTLR4 integration. Top-level book.ini and SUMMARY.md are waBook (custom Go-based markdown-to-HTML tool) metadata; actual book content appears in ch*/readme.md files.

👥Who it's for

Go developers and language enthusiasts who want to understand compiler internals, build custom Go analysis tools, create code generators, or design domain-specific languages (DSLs). Particularly valuable for those developing linters, refactoring tools, or exploring language implementation via the AST layer rather than raw text parsing.

🌱Maturity & risk

Actively maintained and educationally mature. Published as a physical book (京东, 当当, 异步出版社), indicating editorial polish and established author credibility (chai2010 is a respected Go community figure). The repo shows structured progression through 10 chapters with professional appendices. However, commits appear sporadic and the latest code targets Go 1.14+, so active maintenance is not continuous—it functions as a stable reference rather than a rapidly evolving project.

Low technical risk for reading/learning; content is educational, not production library code. Single primary author (chai2010) means no distributed maintenance, but the book's published status suggests stability. The goyacc/ANTLR examples in appendix use external tools (Yacc, Lex, ANTLR4) that require separate installation. No visible CI/CD pipeline (no .github/workflows) and minimal automated tests, so if you fork to add custom examples, you're responsible for validation.

Active areas of work

No active development indicated in provided data. The repo exists as a stable educational resource. A companion project, wa-lang/wa (Wasm-focused language), and wa-lang/wabook (the Go-based ebook builder) are linked as related modern tooling, suggesting the author has moved focus to language design rather than AST book updates.

🚀Get running

Check README for instructions.

Daily commands: Per-chapter examples: cd ch{N}/examples/{M} && go run main.go (e.g., cd ch1/examples/01 && go run main.go). Appendix goyacc: cd appendix/a-goyacc/examples/calculator && make (compiles Lex+Yacc, runs calculator). Appendix ANTLR4: cd appendix/b-antlr4 && make (generates parser from Calc.g4, runs listener/visitor examples). Build book HTML: wabook build (requires installing wa-lang/wabook). No traditional dev server; this is educational content.

🗺️Map of the codebase

  • README.md — Primary entry point explaining the book's scope: Go AST fundamentals, standard library packages (go/ast, go/token), and connections to compiler design.
  • SUMMARY.md — Table of contents defining the 14 chapters and appendices; essential for understanding the book's progression from basics to advanced compiler topics.
  • ch1/readme.md — Chapter 1 introduces AST concepts and the go/ast package; foundational reading for all subsequent examples.
  • ch1/examples/01/main.go — Minimal AST parsing example demonstrating how to load and inspect Go source code via the standard library.
  • appendix/b-antlr4/main.go — ANTLR4-based parser example; shows alternative parsing approach beyond Go's built-in AST tools.
  • ch14/examples/01-hello/Makefile — LLVM/IR compilation example; demonstrates the book's progression to lower-level code generation.
  • book.ini — Build configuration for waBook; controls how markdown chapters are assembled into the final electronic book.

🧩Components & responsibilities

  • Markdown chapters (ch1–ch13, appendix) (Markdown, waBook) — Narrative explanation of AST concepts, parsing paradigms, code generation, and compiler design
    • Failure mode: Inaccurate or outdated explanations; readers misunderstand AST or tool usage
  • Standalone code examples (chN/examples/NN/main.go) (Go standard library, goyacc, ANTLR4, LLVM) — Runnable demonstrations of AST inspection, parsing, and code generation; each is independent and executable
    • Failure mode: Example

🛠️How to make changes

Add a new AST analysis example chapter

  1. Create a new chapter directory (e.g., ch15) following the pattern: chN/readme.md for explanation (ch15/readme.md)
  2. Create examples subdirectory with numbered example programs (ch15/examples/01/main.go)
  3. Add chapter to SUMMARY.md in the correct hierarchical position (SUMMARY.md)

Add a new calculator parser using goyacc

  1. Create grammar file in appendix/a-goyacc/examples/newcalc/calc.y following appendix/a-goyacc/examples/calculator/calc.y (appendix/a-goyacc/examples/newcalc/calc.y)
  2. Create Makefile with goyacc and Go build rules (appendix/a-goyacc/examples/newcalc/Makefile)
  3. Implement main.go to use the generated parser (appendix/a-goyacc/examples/newcalc/main.go)

Add ANTLR4 language grammar extension

  1. Extend or create new .g4 grammar file in appendix/b-antlr4/, following Calc.g4 syntax (appendix/b-antlr4/MyLang.g4)
  2. Update Makefile to generate Go code from the new grammar (appendix/b-antlr4/Makefile)
  3. Implement visitor.go or listener.go to handle parse tree traversal (appendix/b-antlr4/visitor.go)

🔧Why these technologies

  • Go standard library (go/ast, go/token, go/parser, go/format) — Native, zero-dependency AST tooling; demonstrates how Go's own tooling (go fmt, go doc) works internally
  • waBook (Go-native markdown compiler) — Pure Go replacement for traditional ebook builds; allows contributors to build locally without Node.js or Python
  • goyacc (Go port of yacc) — Shows traditional compiler construction via bottom-up parsing; suitable for teaching classic compiler patterns
  • ANTLR4 — Modern, widely-used parser generator; demonstrates contemporary parsing techniques and visitor/listener patterns
  • LLVM IR (ch14 examples) — Bridges from AST to executable code; shows end-to-end compiler pipeline for custom language implementation

⚖️Trade-offs already made

  • Book-first, not library-first approach

    • Why: Repository is an educational textbook, not a reusable tooling library
    • Consequence: Code examples prioritize clarity and pedagogy over production robustness; no package exports or APIs
  • Cover multiple parsing paradigms (go/ast, goyacc, ANTLR4)

    • Why: Teaches breadth of parsing approaches and when each is appropriate
    • Consequence: Reader must learn three separate tool ecosystems; integration between them is minimal
  • Markdown-based with waBook build system

    • Why: Pure Go tooling, easy to extend, integrates GitHub discussion comments (giscus)
    • Consequence: No LaTeX/PDF support; primarily an online reading experience
  • Examples are standalone binaries, not a cohesive toolkit

    • Why: Each example is self-contained and runnable independently
    • Consequence: Code duplication across examples; no shared library or utility modules

🚫Non-goals (don't propose these)

  • Production-grade code transformation tooling (examples are educational, not hardened for real code)
  • Alternative Go compiler implementation (the book recommends 《从头实现µGo语言》 for that)
  • Package/library distribution (no published Go modules for book content)
  • Real-time or interactive IDE features (static markdown + code examples only)
  • Formal language theory or type system proofs (pragmatic, implementation-focused)

🪤Traps & gotchas

Yacc/Lex toolchain not bundled: appendix/a-goyacc/examples/calculator/Makefile invokes lex and yacc directly; you must have C toolchain (gcc, bison, flex) installed on your system—Makefile fails silently or with cryptic errors if missing. ANTLR4 requires Java: appendix/b-antlr4/Makefile calls antlr4 CLI, which requires JDK; not bundled. Go version assumption: Examples target Go 1.14+ (from calc example module); some stdlib APIs (e.g., go/ast field names) changed between versions, and code may break on Go 1.10 or earlier. No error handling in examples: Many chapter examples omit err != nil checks for brevity—production code must add these. Chinese content: Entire book text is in Mandarin; non-Chinese speakers cannot read chapter narratives without translation tools. Book.ini and waBook dependency: To build HTML locally, you need the external wa-lang/wabook tool installed separately (not a standard Go build tool).

🏗️Architecture

💡Concepts to learn

  • Abstract Syntax Tree (AST) — The core abstraction taught throughout this book—understanding AST structure is essential to programmatically analyze and transform Go code, which is the foundation for linters, refactoring tools, and compilers.
  • Visitor Pattern (in context of AST traversal) — Go's ast.Walk and custom visitor functions enable systematic traversal and transformation of AST nodes; this pattern appears implicitly in all chapter examples.
  • Lexical Analysis (Tokenization) — The go/token package and the Lex examples (appendix/a-goyacc/calc.l) show how source code is split into tokens; prerequisite to understanding how parsers consume tokens to build ASTs.
  • Context-Free Grammars (CFG) and Parser Generators (Yacc, ANTLR4) — Appendices demonstrate formal grammar definition (calc.y, Calc.g4) and automatic parser generation; shows how language syntax rules translate into parsing logic.
  • Code Generation via AST Transformation — Core capability of AST manipulation—traversing parsed code, modifying nodes, and emitting new code; essential for implementing go fmt, code generators, and domain-specific language tooling.
  • Semantic Analysis and Type Information — While go/ast provides syntax tree structure, the go/types package (referenced in context of advanced analysis) adds semantic understanding; distinguishing parse trees from fully-analyzed ASTs.
  • chai2010/ugo-compiler-book — Companion project by the same author showing how to build a complete µGo compiler from scratch, extending AST concepts into a full implementation (next logical step after go-ast-book).
  • golang/tools — Official Go tools repository containing real-world examples of go/ast usage in golang.org/x/tools (goimports, go/analysis, etc.), canonical reference for production AST patterns.
  • wa-lang/wa — WebAssembly-focused language by the same author, demonstrating practical application of AST parsing and code generation concepts taught in this book.
  • wa-lang/wabook — Go-based markdown-to-HTML ebook builder that powers the online presentation of go-ast-book; useful for understanding the tooling infrastructure.
  • antlr/antlr4 — Official ANTLR4 project repository; essential reference for the grammar-based parsing alternative shown in appendix/b-antlr4.

🪄PR ideas

To work on one of these in Claude Code or Cursor, paste: Implement the "<title>" PR idea from CLAUDE.md, working through the checklist as the task list.

Add Go module initialization and dependency management for all example directories

The repo contains multiple example projects (ch1-ch11 examples, appendix/a-goyacc/examples/calculator, appendix/b-antlr4) but many lack go.mod files. This causes build failures and makes examples non-reproducible. Only calculator and antlr4 examples have go.mod. Adding go.mod to all example directories with proper module paths and dependencies would make the book's examples executable and testable.

  • [ ] Create go.mod files in ch1/examples/01, ch1/examples/02, and other chapter example directories
  • [ ] Add go.mod to appendix/a-goyacc/examples/calculator if missing, and verify all imports are declared
  • [ ] Create a Makefile or shell script in the root to run 'go mod tidy' and 'go build' across all example directories to validate they work
  • [ ] Update README.md or SUMMARY.md with instructions on how to build and run each chapter's examples

Create automated CI workflow to validate all Go examples compile and run

The repo is an educational book with ~20+ Go example programs scattered across ch1-ch11 and appendices, but there's no CI validation that these examples actually compile or run. A GitHub Actions workflow would catch breaking changes when the Go standard library evolves or examples become outdated. This is critical for a book repo where example code is the primary learning material.

  • [ ] Create .github/workflows/go-examples.yml with a matrix strategy to test Go 1.18+ versions
  • [ ] Add steps to run 'go mod tidy' and 'go build ./...' for ch1-ch11/examples, appendix/a-goyacc/examples/calculator, and appendix/b-antlr4
  • [ ] Optionally add 'go vet' and 'go fmt' checks to ensure code quality
  • [ ] Document the CI setup in CONTRIBUTING.md or similar file for new contributors

Create comprehensive examples index with runnable code snippets in README files

Each chapter (ch1/readme.md through ch11/readme.md) has examples but no centralized index of what each example demonstrates. Currently ch1/examples/01, ch1/examples/02 exist but their purpose is unclear from file listing alone. Adding a structured examples section in each chapter's readme.md with brief descriptions, output expectations, and how to run each example would significantly improve usability.

  • [ ] Update ch1/readme.md to add an 'Examples' section listing 01/main.go and 02/main.go with descriptions of what AST concepts they demonstrate
  • [ ] Repeat for ch10/readme.md (which has 10 examples) and other chapters with multiple examples
  • [ ] Include 'Run with: go run ./examples/01' and expected output in each description
  • [ ] Add a table in appendix/readme.md linking to goyacc and antlr4 examples with descriptions of calculator implementations

🌿Good first issues

  • Add English translations for ch1/readme.md and ch2/readme.md as a proof-of-concept, allowing international contributors to propose translating remaining chapters—start with a separate en/ directory to parallel the Chinese structure.
  • Create a testing/ directory with Go test files (*_test.go) for each chapter example, verifying that main.go runs without panic and produces expected AST output. Current examples lack automated validation.
  • Document the Yacc/Lex and ANTLR4 installation steps for macOS, Linux, and Windows in appendix/a-goyacc/readme.md and appendix/b-antlr4/readme.md (e.g., brew install flex bison, apt-get install flex bison, ANTLR4 JAR download links), since the Makefiles assume tools are already installed.

Top contributors

Click to expand

📝Recent commits

Click to expand
  • 6bb3a6f — zz (chai2010)
  • 5a554ca — zz (chai2010)
  • 5b998c7 — Update README.md (chai2010)
  • 6da881d — zz (chai2010)
  • 12433c5 — 删除废弃文件 (chai2010)
  • f881a96 — 切换到 mnook (chai2010)
  • 10b786b — Update README.md (chai2010)
  • 326bf3f — Merge pull request #52 from ns-cn/master (chai2010)
  • b00141c — Update README.md (chai2010)
  • fa693fc — 错误导航序号4.5 -> 4.4 (ns-cn)

🔒Security observations

This is an educational repository (Go AST book) with minimal security risks. The primary concern is the outdated Go 1.14 dependency which should be updated. No hardcoded credentials, injection vulnerabilities, or infrastructure misconfigurations were detected. The codebase consists mainly of documentation and example code rather than production software, which naturally limits the attack surface. Overall security posture is reasonable for an educational resource, but dependencies should be modernized.

  • Medium · Outdated Go Version in Module — go.mod (calculator module). The go.mod file specifies 'go 1.14', which was released in February 2020 and is now significantly outdated. This version lacks security patches and bug fixes from subsequent releases. Fix: Update the Go version to a supported release (1.21 or later). Run 'go mod tidy' after updating the toolchain.
  • Low · Missing License File Reference — go.mod and source files. The module header references an Apache license in the comment, but no explicit LICENSE file is visible in the provided file structure. This could cause license compliance issues. Fix: Ensure a LICENSE file exists in the repository root that matches the claimed Apache license type.
  • Low · Generated Code Without Clear Source Attribution — appendix/b-antlr4/calc/ directory. Several generated files are present (e.g., calc_lexer.go, calc_parser.go, calc_base_listener.go from ANTLR4) but lack clear documentation on how they were generated and their source tool versions. Fix: Document the tool versions and generation process in a README. Consider adding a .gitignore rule for generated files or a generation script.

LLM-derived; treat as a starting point, not a security audit.


Generated by RepoPilot. Verdict based on maintenance signals — see the live page for receipts. Re-run on a new commit to refresh.

Concerning signals · chai2010/go-ast-book — RepoPilot