Module: Ibex::CLIRaccMigration
- Defined in:
- lib/ibex/cli/racc_migration.rb,
sig/ibex/cli/racc_migration.rbs
Overview
Static racc migration checks and differential harness generation.
Instance Method Summary collapse
- #migrate_check_options(settings) ⇒ OptionParser
- #migrate_harness_options(settings) ⇒ OptionParser
- #run_migrate_check_command(arguments) ⇒ Integer
- #run_migrate_harness_command(arguments) ⇒ Integer
Instance Method Details
#migrate_check_options(settings) ⇒ OptionParser
70 71 72 73 74 75 76 |
# File 'lib/ibex/cli/racc_migration.rb', line 70 def (settings) OptionParser.new do || . = "Usage: ibex migrate-check [--format=text|json] grammarfile" .on("--format=FORMAT", %w[text json], "text or json") { |value| settings[:format] = value } .on("--help", "show help") { settings[:help] = true } end end |
#migrate_harness_options(settings) ⇒ OptionParser
79 80 81 82 83 84 85 |
# File 'lib/ibex/cli/racc_migration.rb', line 79 def (settings) OptionParser.new do || . = "Usage: ibex migrate-harness [-o FILE] grammarfile" .on("-o FILE", "--output=FILE", "write the harness atomically") { |value| settings[:output] = value } .on("--help", "show help") { settings[:help] = true } end end |
#run_migrate_check_command(arguments) ⇒ Integer
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ibex/cli/racc_migration.rb', line 28 def run_migrate_check_command(arguments) settings = { format: "text" } #: migration_check_settings parser = (settings) paths = parser.parse(arguments) if settings[:help] @stdout.puts(parser) return 0 end path = input_path(paths) report = RaccMigration::Checker.new.check(File.binread(path), file: path) @stdout.write(settings.fetch(:format) == "json" ? "#{report.to_json}\n" : report.to_text) report.compatible? ? 0 : 1 end |
#run_migrate_harness_command(arguments) ⇒ Integer
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ibex/cli/racc_migration.rb', line 44 def run_migrate_harness_command(arguments) settings = {} #: migration_harness_settings parser = (settings) paths = parser.parse(arguments) if settings[:help] @stdout.puts(parser) return 0 end path = input_path(paths) report = RaccMigration::Checker.new.check(File.binread(path), file: path) unless report.compatible? && report.class_name raise Ibex::Error, "(migration):1:1: grammar must pass migrate-check before harness generation" end source = RaccMigration::Harness.generate(report.class_name) output = settings[:output] if output && same_file_target?(path, output) raise Ibex::Error, "(migration):1:1: grammar and harness output paths must be distinct" end output ? atomic_write_ir(output, source) : @stdout.write(source) 0 end |