Class: StringParser
- Inherits:
-
Object
show all
- Defined in:
- lib/parser/string.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of StringParser.
5
6
7
8
9
10
11
12
|
# File 'lib/parser/string.rb', line 5
def initialize(line)
raise NilValue if line.nil?
raise ExpectedString unless String === line
@line = line
@len = @line.length
@eos = @len == 0 ? true : false
@i = 0
end
|
Instance Attribute Details
#eos ⇒ Object
Returns the value of attribute eos.
3
4
5
|
# File 'lib/parser/string.rb', line 3
def eos
@eos
end
|
#i ⇒ Object
Returns the value of attribute i.
3
4
5
|
# File 'lib/parser/string.rb', line 3
def i
@i
end
|
#len ⇒ Object
Returns the value of attribute len.
3
4
5
|
# File 'lib/parser/string.rb', line 3
def len
@len
end
|
#line ⇒ Object
Returns the value of attribute line.
3
4
5
|
# File 'lib/parser/string.rb', line 3
def line
@line
end
|
Instance Method Details
#eos? ⇒ Boolean
36
37
38
|
# File 'lib/parser/string.rb', line 36
def eos?
@eos
end
|
#grab ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/parser/string.rb', line 14
def grab
return nil if @eos
char = @line[@i]
@i += 1
check_eos
char
end
|
#next! ⇒ Object
27
28
29
|
# File 'lib/parser/string.rb', line 27
def next!
@line[@i + 1]
end
|
#peek ⇒ Object
40
41
42
43
|
# File 'lib/parser/string.rb', line 40
def peek
return nil if @eos
@line[@i]
end
|
#prev ⇒ Object
31
32
33
34
|
# File 'lib/parser/string.rb', line 31
def prev
return nil if @i <= 0
@line[@i-1]
end
|
#skip_spaces ⇒ Object
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/parser/string.rb', line 45
def skip_spaces
char = nil
loop do
char = peek
break if eos?
break if char != " "
char = grab
end
char
end
|
#ungrab ⇒ Object
22
23
24
25
|
# File 'lib/parser/string.rb', line 22
def ungrab
@i -= 1
check_eos
end
|