go-ruby-parser

A Ruby front-end in pure Go โ€” lexer, parser, AST. No cgo, no Prism.

pure Go ยท zero cgo stateful lexer recursive-descent + Pratt typed AST Ruby 4.0 subset pattern matching heredocs MRI 4.0.5 differential-tested 100% coverage 6 arches ยท WebAssembly
Documentation GitHub
Documentation (MkDocs Material + mike) License: BSD-3-Clause Go 1.26.4+ Coverage 100%

go-ruby-parser turns Ruby source into a syntax tree: a stateful lexer, a recursive-descent parser with a Pratt expression core, and a typed AST โ€” all in pure Go, with cgo disabled. No cgo, no Prism, no shelling out to Ruby: the front-end the Go ecosystem lacked for building Ruby tooling (linters, formatters, analysers, doc generators, LSP servers, transpilers) in pure Go. It was extracted from go-embedded-ruby โ€” which now consumes it โ€” and is grown test-first against MRI Ruby 4.0.5, with 100% coverage enforced in CI across the six 64-bit targets.

parser ready

The front-end: parser.Parse(src) (*ast.Program, error), with sub-packages token, ast and lexer. A stateful lexer (MRI spaceSeen semantics), a recursive-descent + Pratt expression parser with a scope stack, and a typed AST for a broad, practical subset of Ruby 4.0 โ€” literals, operators, control flow, case/in pattern matching, methods/blocks, classes/modules/metaprogramming. 100% covered, differential-tested against MRI Ruby 4.0.5.

A pure-Go, cgo-disabled front-end, so it cross-compiles and embeds anywhere โ€” and, being CGO=0, also compiles to WebAssembly (js/wasm and wasip1/wasm). It parses a broad, practical subset of Ruby 4.0 to a typed AST, differential-tested against MRI's reference parser, over a clean Parse โ†’ *ast.Program API any Go tool can build on. It is a standalone, reusable module and the front-end member of the sibling family go-ruby-marshal ยท go-ruby-regexp, consumed by github.com/go-embedded-ruby.