Blog
0 pixels scrolled
  • Home
  • Work
  • Services
  • About
  • Blog
  • Contact
Ruby’s New Parser:
Why Prism Is the Future of Ruby Development
Jared Norman on September 27, 2024
I sat down with Kevin Newton to explore Ruby's new parser, Prism, and what it means for the Ruby developer tooling ecosystem.
Ruby’s New Parser:
Why Prism Is the Future of Ruby Development
Jared Norman on September 27, 2024
Posted in Ruby
← Back to the blog

Ruby devs, hold on to your keyboards. The Ruby’s language tooling is unifying around a new parser called Prism.

In the latest episode of Dead Code, I spoke with Kevin Newton, Staff Software Engineer at Shopify, and the driving force behind Ruby’s brand-new parser, Prism. If you’ve ever cursed at Ruby’s quirks or struggled with its complex syntax, this conversation will hit home.

Before we get into the technical nitty-gritty, let’s start with the big question: Why does Ruby need a new parser in the first place? 🤔

The Ruby Parser Problem No One Talks About

Most of us have used Ruby’s parser without even thinking twice. But here’s the thing—Ruby’s original parser, first built in 1993, was starting to show its age. The parser was tightly bound to CRuby, which made it difficult to use across other tools (like languages servers and linters), as well as other Ruby implementations. Worse yet, there were 11 actively maintained parsers in the Ruby ecosystem. Yes, 11.

Maintaining multiple parsers created a lot of duplicate work. Developers were spending valuable time fixing parsers instead of working on higher-level tools and applications. That’s where Prism comes in.

Prism was born out of the need for a unified, portable, and error-tolerant parser—one that could work across all Ruby implementations and still give developers control over the language’s quirks.

Parsing Through the Pain: Ruby’s Complex Syntax

Kevin alos shared a horror story that all Ruby developers will recognize: Ruby’s syntax is weird, and it’s not just us saying that. Whether it’s nested heredocs or regular expressions, Ruby’s syntax can be a minefield for parsers.

One of the biggest challenges Kevin faced was handling heredocs. If you’ve ever looked at a heredoc in Ruby, you know the pain. Nested heredocs, quoted heredocs, and multi-line Ruby code crammed onto the same line—Prism had to manage all of this without breaking a sweat. Not only did Kevin and his team handle it, but they also made the parser error-tolerant. This means that even if your code has syntax errors, tools built on Prism can still parse it and provide useful feedback.

Now, let’s talk about regular expressions. Ruby integrates regex so deeply into the language that Prism had to build a regex parser into itself. That’s right—Prism isn’t just parsing Ruby code; it’s also parsing the regex that Ruby depends on for encoding.

Prism: The Future of Ruby Tooling

What really sets Prism apart is its ability to power a new generation of Ruby tooling. Kevin and his team have designed Prism to be the backbone for language servers, formatters, linters, and more. Shopify, for example, has already implemented Prism in the Ruby LSP. The result? Smarter tools with better syntax highlighting, code navigation, and even performance optimization.

And here’s the kicker: Prism has just been merged as the default parser in Ruby’s 3.4 preview release. This means that we might see Prism as the default parser in Ruby 3.4, but that remains to be seen.

Why You Should Care About Prism

You might be thinking, “Great, a new parser. But why should I care?” Well, if you’re working in Ruby—whether you’re a beginner or a seasoned pro—Prism is going to impact the way you write, debug, and optimize your code.

Here’s why:

  • Unified Ecosystem: With Prism, there’s now one parser to rule them all. All your tools will parse Ruby code the same way.
  • Error Tolerance: Say goodbye to syntax errors breaking your tools. Prism is built to handle mistakes gracefully.
  • Future-Proofing: Prism opens the door to better Ruby tools—think smarter linters, more reliable formatters, and faster IDEs.

Join the Conversation

So, what do you think? Is Prism the game-changer Ruby needs? Or are we just scratching the surface of what’s possible with Ruby tooling?

Follow Kevin Newton’s work on GitHub and check out more updates on his blog here: https://kddnewton.com.

Work ServicesAboutBlogCareersContact


Privacy policyTerms and conditions© 2024 Super Good Software Inc. All rights reserved.