whatisgithub

What is parser?

rubys/parser — explained in plain English

Analysis updated 2026-07-16 · repo last pushed 2021-04-13

YaccAudience · developerComplexity · 3/5DormantSetup · easy

In one sentence

A pure-Ruby tool that reads Ruby source code and converts it into a structured tree format, letting other programs understand and manipulate code without running it. Used by popular code-quality tools like RuboCop.

Mindmap

mindmap
  root((repo))
  What it does
    Reads Ruby code
    Builds syntax trees
    Tracks code locations
    Shows warnings
  Tech stack
    Pure Ruby
    Yacc parser
  Use cases
    Code style checking
    Security analysis
    Auto-formatting tools
  Audience
    Tool builders
    Ruby developers
  Version support
    Ruby 1.8 to 2.3
    MacRuby and RubyMotion

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Build a tool that automatically checks Ruby code style and flags violations.

USE CASE 2

Create a security scanner that finds vulnerabilities by analyzing code structure.

USE CASE 3

Develop an auto-formatter that rewrites Ruby code based on its structure.

USE CASE 4

Build a tool that highlights errors by tracking where code pieces appear in a file.

What is it built with?

RubyYacc

How do you get it running?

Difficulty · easy Time to first run · 5min

Pure Ruby with no external dependencies or infrastructure required.

The explanation does not mention a specific license.

So what is it?

Parser is a production-grade tool that reads Ruby source code and converts it into a structured format called an Abstract Syntax Tree (AST). In simple terms, it takes the text that a human programmer wrote and breaks it down into a logical map that a computer program can understand and manipulate. It is written entirely in pure Ruby and is designed to be highly accurate and easy to use. At a high level, the tool reads a string of code, like a simple math equation or a complex method, and identifies the individual pieces, such as numbers, variables, and operators. It organizes these pieces into a tree-like structure that shows exactly how the code is built. Beyond just reading the code, it keeps precise track of where every piece originally appeared in the text, which is incredibly useful for things like highlighting errors or modifying code. It can also display warnings and diagnostic messages similar to how a compiler might warn you about a potential mistake. This tool is mainly used by developers who build tools that analyze or manipulate Ruby code. For example, if someone is building a tool that automatically checks code style, detects security vulnerabilities, or automatically fixes formatting, they need a reliable way to understand the underlying structure of that code. Projects like RuboCop, a widely used Ruby code analyzer, rely on it to understand what the code does without having to execute it. A notable aspect of the project is how it handles different versions of Ruby. The tool is built to understand the specific syntax rules of multiple Ruby versions, from 1.8 all the way through 2.3, as well as variations like MacRuby and RubyMotion. Because the official Ruby language parser frequently changes in subtle ways between releases, this project intentionally tracks the syntax of the latest minor version of Ruby rather than trying to replicate every tiny patch. This tradeoff keeps the tool manageable and reliable for the vast majority of real-world code.

Copy-paste prompts

Prompt 1
I want to use the 'parser' gem to read a Ruby file and print out its Abstract Syntax Tree. Show me how to parse a simple Ruby method and inspect the resulting tree structure in pure Ruby.
Prompt 2
Help me use the 'parser' gem to find all method definitions in a Ruby file and report their line numbers, using the location tracking feature.
Prompt 3
I am building a Ruby code analysis tool similar to RuboCop. Show me how to use the 'parser' gem to parse code for a specific Ruby version and walk the AST to detect unused variables.
Prompt 4
Demonstrate how to use the 'parser' gem to parse Ruby code and display any diagnostic warnings it generates for syntax issues.

Frequently asked questions

What is parser?

A pure-Ruby tool that reads Ruby source code and converts it into a structured tree format, letting other programs understand and manipulate code without running it. Used by popular code-quality tools like RuboCop.

What language is parser written in?

Mainly Yacc. The stack also includes Ruby, Yacc.

Is parser actively maintained?

Dormant — no commits in 2+ years (last push 2021-04-13).

What license does parser use?

The explanation does not mention a specific license.

How hard is parser to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is parser for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.