Class: StringParser
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
5
6
7
8
9
10
11
12
|
# File 'lib/livetext/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
Returns the value of attribute eos.
3
4
5
|
# File 'lib/livetext/parser/string.rb', line 3
def eos
@eos
end
|
Returns the value of attribute i.
3
4
5
|
# File 'lib/livetext/parser/string.rb', line 3
def i
@i
end
|
Returns the value of attribute len.
3
4
5
|
# File 'lib/livetext/parser/string.rb', line 3
def len
@len
end
|
Returns the value of attribute line.
3
4
5
|
# File 'lib/livetext/parser/string.rb', line 3
def line
@line
end
|
Instance Method Details
#eos? ⇒ Boolean
43
44
45
|
# File 'lib/livetext/parser/string.rb', line 43
def eos?
@eos
end
|
#grab(n = 1) ⇒ Object
14
15
16
17
18
19
20
21
22
|
# File 'lib/livetext/parser/string.rb', line 14
def grab(n = 1)
raise "n <= 0 for #grab" if n <= 0
return nil if @eos
i2 = @i + n - 1
char = @line[@i..i2]
@i += n
check_eos
char
end
|
#lookahead ⇒ Object
29
30
31
32
|
# File 'lib/livetext/parser/string.rb', line 29
def lookahead
@line[@i + 1]
end
|
#peek(n = 1) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/livetext/parser/string.rb', line 47
def peek(n = 1)
raise "n <= 0 for #grab" if n <= 0
return nil if @eos
i2 = @i + n - 1
@line[@i..i2]
end
|
38
39
40
41
|
# File 'lib/livetext/parser/string.rb', line 38
def prev
return nil if @i <= 0
@line[@i-1]
end
|
#remainder ⇒ Object
34
35
36
|
# File 'lib/livetext/parser/string.rb', line 34
def remainder
@line[@i..-1]
end
|
#skip_spaces ⇒ Object
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/livetext/parser/string.rb', line 54
def skip_spaces
char = nil
loop do
char = peek
break if eos?
break if char != " "
char = grab
end
char
end
|
24
25
26
27
|
# File 'lib/livetext/parser/string.rb', line 24
def ungrab
@i -= 1
check_eos
end
|