Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/arpaka/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def generate(ruby_source: nil, parse_y: nil, class_name:)
end
source = "# frozen_string_literal: true\n" \
"# Generated by Arpaka #{Lrama::Ruby::VERSION}. Do not edit.\n" \
"# Ruby source profile: #{ruby_source ? RubyGrammar::REVISION : 'parse.y only'}\n" \
"# Ruby source profile: #{ruby_source ? artifacts.fetch('source_profile') : 'parse.y only'}\n" \
"# parse.y SHA256: #{Digest::SHA256.file(grammar_filename).hexdigest}\n" \
"#{notices.join("\n").lines.map { |line| "# #{line}" }.join}\n" \
"class #{class_name}\n#{parser}\n#{runtime}\nend\n"
Expand Down
30 changes: 20 additions & 10 deletions lib/arpaka/profile/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,34 @@ module RUBY
def self.select(grammar)
if grammar.rules.any? { |rule| rule.lhs.id.s_value == "value_expr_command" }
CURRENT
elsif grammar.rules.any? { |rule| rule.lhs.id.s_value == "top_compstmt" }
elsif grammar.rules.any? { |rule| rule.lhs.id.s_value == "top_compstmt" &&
rule.rhs.any? { |symbol| symbol.id.s_value == "option_terms" } }
legacy
elsif grammar.rules.any? { |rule| rule.lhs.id.s_value == "top_compstmt" &&
rule.rhs.any? { |symbol| symbol.id.s_value == "opt_terms" } }
legacy_3_3
else
raise ::Arpaka::Error, "Unsupported Ruby parse.y profile"
end
end

def self.legacy
@legacy ||= begin
box = ::Ruby::Box.new
profile = box.eval(File.read(File.join(__dir__, "ruby_3_4.rb")))
unless profile.is_a?(Hash) && profile["name"] == "ruby-3.4"
raise ::Arpaka::Error, "Invalid Ruby 3.4 profile"
end
profile.freeze
rescue SyntaxError, TypeError => error
raise ::Arpaka::Error, "Ruby legacy profile loading failed: #{error.message}"
@legacy ||= load("ruby_3_4.rb", "ruby-3.4")
end

def self.legacy_3_3
@legacy_3_3 ||= load("ruby_3_3.rb", "ruby-3.3")
end

def self.load(filename, name)
box = ::Ruby::Box.new
profile = box.eval(File.read(File.join(__dir__, filename)))
unless profile.is_a?(Hash) && profile["name"] == name
raise ::Arpaka::Error, "Invalid #{name} profile"
end
profile.freeze
rescue SyntaxError, TypeError => error
raise ::Arpaka::Error, "Ruby profile loading failed: #{error.message}"
end
end
end
Expand Down
Loading
Loading