Skip to content

Commit 7880294

Browse files
committed
Implement Parser#command_type
1 parent faac877 commit 7880294

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lib/parser.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
class Parser
2+
class A_COMMAND; end
3+
class C_COMMAND; end
4+
class L_COMMAND; end
5+
26
def initialize(input)
37
@lines = split_lines(input)
48
end
@@ -8,12 +12,22 @@ def has_more_commands?
812
end
913

1014
def advance
11-
lines.shift
15+
@current = lines.shift
16+
end
17+
18+
def command_type
19+
if current.start_with?('@')
20+
A_COMMAND
21+
elsif current.start_with?('(')
22+
L_COMMAND
23+
else
24+
C_COMMAND
25+
end
1226
end
1327

1428
private
1529

16-
attr_reader :lines
30+
attr_reader :lines, :current
1731

1832
def split_lines(input)
1933
input

0 commit comments

Comments
 (0)