Class: N65::Parser
- Inherits:
-
Object
- Object
- N65::Parser
- 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]
Class Method Summary collapse
-
.parse(line) ⇒ Object
Parses a line of program source into an object deriving from base class InstructionBase.
Class Method Details
.parse(line) ⇒ Object
Parses a line of program source into an object
deriving from base class InstructionBase
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/n65/parser.rb', line 35 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) unless label.nil? return label end ## Now check if we have a directive directive = parse_directive(sanitized) unless directive.nil? return directive end ## Now, surely it is an asm instruction? instruction = Instruction.parse(sanitized) unless instruction.nil? return instruction end ## Guess not, we have no idea fail(CannotParse, sanitized) end |