Skip to content

Extractor: Add extract_ruby_options across all language bindings#675

Merged
marcoroth merged 15 commits into
marcoroth:mainfrom
Lusqinha:enhancement/add_method_extract_ruby_with_semicolons_to_Herb_module
Feb 13, 2026
Merged

Extractor: Add extract_ruby_options across all language bindings#675
marcoroth merged 15 commits into
marcoroth:mainfrom
Lusqinha:enhancement/add_method_extract_ruby_with_semicolons_to_Herb_module

Conversation

@Lusqinha

@Lusqinha Lusqinha commented Oct 17, 2025

Copy link
Copy Markdown
Contributor

This pull request adds semicolons, comments, and preserve_positions options to Herb.extract_ruby across all language bindings (Ruby, JavaScript, Java, Rust).

This was originally requested to use the extract Ruby code with semicolons in Steep/RBS, more specifically in this PR: soutaro/steep#1836. It's because we need the Ruby code with semicolons to display the static typing errors correctly. I think this functionality could also be used in others projects like Sorbet and Packwerk.

Resolves #100

@marcoroth marcoroth left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Lusqinha, thanks for opening this pull request!

I'm happy to expose this functionality, but I'm really curious what the use case for this pull request is, do you have a specific need for this? 😅

Regarding the design, I'm wondering if we instead should expose this with some options on the existing extract_ruby method. Something like:

Herb.extract_ruby(source, semicolons: true)

@felixefelip

felixefelip commented Oct 19, 2025

Copy link
Copy Markdown
Contributor

@marcoroth thanks for the feedback!

We are planning to use this in Steep/RBS, more specifically in this PR: soutaro/steep#1836. It's because we need the Ruby code with semicolons to display the static typing errors correctly. I think this functionality could also be used in others projects like Sorbet and Packwerk.

Sorry for the lack of information in the description of this PR, we are going to update this soon.

About the design, I agree to use existing extract_ruby adding some options. We are going to do this.

@Lusqinha Lusqinha changed the title Parser: add method extract ruby with semicolons to herb module Parser: add public API method extract_ruby_with_semicolons_to_herb Oct 21, 2025

require_relative "../test_helper"

module Extractor

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felixefelip

Copy link
Copy Markdown
Contributor

Hello @marcoroth,

Sorry for the long time to update this PR.

We made the changes to use the optional argument, I think could be better the semicolons argument be default false to not affect the current users of this method. Do you agree?

@Lusqinha Lusqinha marked this pull request as ready for review November 18, 2025 03:08
@felixefelip

Copy link
Copy Markdown
Contributor

Hello @marcoroth. We made the adjustments to the PR, could you review it again?

@marcoroth

Copy link
Copy Markdown
Owner

Hey @Lusqinha and @felixefelip, Sorry for the delay here.

I think given that we merged #902 this pull request might actually not be needed anymore. Unless I'm missing something:

irb(main):003> source = "<% x = 1 %> <% y = 2 %>"
irb(main):004> result = Herb.extract_ruby(source)
=> "   x = 1  ;    y = 2  ;"

@marcoroth

Copy link
Copy Markdown
Owner

Maybe we could still add the semicolons kwarg to Herb.extract_ruby so you could do the opposite and call it with false:

Herb.extract_ruby(source, semicolons: false)

What do you think?

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Feb 13, 2026
@marcoroth marcoroth changed the title Parser: add public API method extract_ruby_with_semicolons_to_herb Extractor: Add extract_ruby_options across all language bindings Feb 13, 2026
@marcoroth

Copy link
Copy Markdown
Owner

Merged main and implemented the options-based API. Added three options:

  • semicolons (default: true) - can set to false to omit semicolons
  • comments (default: false) - include ERB comments with # prefix
  • preserve_positions (default: true) - set to false for readable multi-line output

Exposed across Ruby, JavaScript (WASM + Node native), Java, and Rust bindings with tests and docs.

@marcoroth marcoroth added this to the v1.0.0 milestone Feb 13, 2026
@marcoroth marcoroth merged commit 475830e into marcoroth:main Feb 13, 2026
24 checks passed
@marcoroth

Copy link
Copy Markdown
Owner

Thank you @Lusqinha, @felixefelip, and @esantos92! 🙏🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor herb_extract_ruby (extract.c) with options

3 participants