$ show goplus/xgo
XGo (formerly Go+) is a Go-superset programming language delivered as a complete compiler toolchain. The repository implements the full language pipeline: a custom scanner (scanner/), parser (parser/), extended AST (ast/), semantic compiler (cl/), and code generator that lowers XGo source to standard Go via the gogen code builder. The xgo CLI (cmd/xgo) exposes subcommands for build, run, test, fmt, go, install, mod, pack, serve, watch, and version, wrapping the Go toolchain after transpilation. The language extends Go with command-style calls, keyword arguments, tuples, list/map/select comprehensions, error-wrapping operators (expr!, expr?), overloaded functions and operators, enums, domain-text literals, and classfile frameworks for domain-specific applications (spx games, MCP servers, shell scripts). The architecture follows a classic compiler design: XGo source → scanner → parser → AST → cl semantic analysis/code generation → gogen → Go source → standard Go toolchain. The tool/ package orchestrates module loading, go.mod management, and delegation to go build/run/test. A language server (x/langserver) with a bundled JSON-RPC2 library (x/jsonrpc2) supports editor tooling. Two notable sub-systems ship alongside the compiler: DQL (dql/), a unified query language over HTML/XML/JSON/YAML/Go AST trees, and TPL (tpl/), a grammar-based DSL parser generator used for domain-text literals. Hundreds of golden-test pairs (in.xgo/out.go) validate compiler output across Go versions 1.18-1.27. External dependencies include github.com/goplus/gogen (code builder), github.com/goplus/mod (module handling), github.com/qiniu/x (errors/streams), and cobra for CLI construction. The codebase forks several Go standard library internals (scanner, printer, ast) to support extended syntax, creating ongoing maintenance burden as Go evolves. Some features remain incomplete (panic("TODO") in matrix literal compilation, fully commented-out ast/resolve.go), and legacy naming aliases (gop vs xgo, gop.mod vs gox.mod) coexist throughout.
The LLM identified 5 files worth highlighting for reuse:
Complete bidirectional JSON-RPC 2.0 connection implementation with async Call/Notify/Respond handling, preemption, and idle-timeout listeners. Self-contained and extractable into any Go project needing RPC over arbitrary transports. Demonstrates clean separation of Listener/Dialer/Binder/Handler interfaces with a well-tested async message queue.
Unified query language over tree-structured data. The NodeSet API (One/All/Single/OnError, XGo_Select/XGo_Child/XGo_Any) is implemented uniformly across HTML, XML, JSON, YAML, maps, and Go/XGo ASTs using lazy iter.Seq iterators. The pattern is directly reusable for building query layers over any hierarchical data format.
Grammar-based DSL parser generator with its own scanner, parser, AST, matcher (Choice/Sequence/Repeat/Adjoin/Var with conflict detection), and delayed-evaluation variant system. Self-contained and reusable for embedding domain-specific languages in applications.
Queryable node-set API over XGo/Go ASTs providing selector-style traversal (child, any, attr) similar to DQL but for source code. Reusable for code analysis, refactoring tools, and AST exploration without coupling to the compiler pipeline.
In-memory filesystem implementation satisfying the parser's fsx abstraction, enabling deterministic parser/compiler testing without disk I/O. The pattern is reusable for testing any file-based toolchain component.