Class: N65::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/n65/parser.rb

Overview

This class determines what sort of line of code we are dealing with, parses one line, and returns an object deriving from InstructionBase

Defined Under Namespace

Classes: CannotParse

Constant Summary collapse

DIRECTIVES =
[INESHeader, Org, Segment, IncBin, Inc, DW, Bytes, ASCII, EnterScope, ExitScope, Space].freeze

Class Method Summary collapse

Class Method Details

.parse(line) ⇒ Object

Parses a line of program source into an object deriving from base class InstructionBase

Raises:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/n65/parser.rb', line 28

def self.parse(line)
  sanitized = sanitize_line(line)
  return nil if sanitized.empty?

  # First check to see if we have a label.
  label = Label.parse(sanitized)
  return label unless label.nil?

  # Now check if we have a directive
  directive = parse_directive(sanitized)
  return directive unless directive.nil?

  # Now, surely it is an asm instruction?
  instruction = Instruction.parse(sanitized)
  return instruction unless instruction.nil?

  # Guess not, we have no idea
  raise(CannotParse, sanitized)
end