Module: LexerKit::CLI::Commands::Disasm
- Defined in:
- lib/lexer_kit/cli/commands.rb
Overview
Disassemble a .lkt1 file
Class Method Summary collapse
Class Method Details
.run(argv) ⇒ Object
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/lexer_kit/cli/commands.rb', line 273 def self.run(argv) = { dfa: nil, jump: nil, keyword: nil } parser = OptionParser.new do |opts| opts. = "Usage: lexer_kit disasm [options] <file.lkt1|file.lkb1>" opts.on("--dfa INDEX", Integer, "Show DFA table at INDEX") do |v| [:dfa] = v end opts.on("--jump INDEX", Integer, "Show jump table at INDEX") do |v| [:jump] = v end opts.on("--keyword INDEX", Integer, "Show keyword table at INDEX") do |v| [:keyword] = v end opts.on("-h", "--help", "Show this help") do puts opts return 0 end end parser.parse!(argv) if argv.empty? warn "error: No input file specified" warn parser. return 1 end path = argv.shift program = CLI.load_lexer(path) require "lexer_kit/debug" if [:dfa] dfa = program.dfa_tables[[:dfa]] raise ArgumentError, "DFA table #{[:dfa]} not found" unless dfa puts Debug::Visualizer.format_dfa(dfa, program: program) elsif [:jump] table = program.jump_tables[[:jump]] raise ArgumentError, "Jump table #{[:jump]} not found" unless table puts Debug::Visualizer.format_jump_table(table) elsif [:keyword] table = program.keyword_tables[[:keyword]] raise ArgumentError, "Keyword table #{[:keyword]} not found" unless table puts Debug::Visualizer.format_keyword_table(table, program: program) else puts Debug::Disassembler.new(program).disassemble end 0 end |