Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: How to use the pure Ruby version of racc #272

Open
mohamedhafez opened this issue Jul 11, 2024 · 1 comment
Open

Documentation: How to use the pure Ruby version of racc #272

mohamedhafez opened this issue Jul 11, 2024 · 1 comment

Comments

@mohamedhafez
Copy link

It says in https://railsatscale.com/2023-08-29-ruby-outperforms-c/

An interesting feature of Racc is that it actually ships with a pure Ruby implementation of the parser runtime.

But I don't see documentation about how to choose to use the pure ruby variant of racc instead of the c-extension version, could that be added somewhere?

@headius
Copy link
Contributor

headius commented Jul 11, 2024

It looks like this currently falls back to the pure-Ruby version only if the extension (JRuby or CRuby) does not load:

racc/lib/racc/parser.rb

Lines 189 to 214 in 2c5a142

begin
if Object.const_defined?(:RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
require 'jruby'
require 'racc/cparse-jruby.jar'
com.headius.racc.Cparse.new.load(JRuby.runtime, false)
else
require 'racc/cparse'
end
unless new.respond_to?(:_racc_do_parse_c, true)
raise LoadError, 'old cparse.so'
end
if Racc_No_Extensions
raise LoadError, 'selecting ruby version of racc runtime core'
end
Racc_Main_Parsing_Routine = :_racc_do_parse_c # :nodoc:
Racc_YY_Parse_Method = :_racc_yyparse_c # :nodoc:
Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_C # :nodoc:
Racc_Runtime_Type = 'c' # :nodoc:
rescue LoadError
Racc_Main_Parsing_Routine = :_racc_do_parse_rb
Racc_YY_Parse_Method = :_racc_yyparse_rb
Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_R
Racc_Runtime_Type = 'ruby'
end

I think we would need some additional code to allow users to opt into the pure-Ruby version or opt out of loading the extensions.

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

No branches or pull requests

2 participants