Module: XcodeResultBundleProcessor::SLF0::Tokenizer
- Defined in:
- lib/xcoderesultbundleprocessor/slf0/tokenizer.rb
Defined Under Namespace
Classes: ClassName, ClassNameRef, ObjectList, Token
Constant Summary
collapse
- TOKEN_INT =
'#'
- TOKEN_CLASS_NAME =
'%'
- TOKEN_CLASS_NAME_REF =
'@'
- TOKEN_STRING =
'"'
- TOKEN_DOUBLE =
'^'
- OBJECT_LIST_NIL =
'-'
- OBJECT_LIST =
'('
Class Method Summary
collapse
Class Method Details
.read_length_and_token_type(io) ⇒ Object
.read_token_stream(io) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/xcoderesultbundleprocessor/slf0/tokenizer.rb', line 16
def self.read_token_stream(io)
raise 'Not an SLF0 file' unless self.valid_slf0_io?(io)
Enumerator.new do |enumerator|
until io.eof?
token = self.read_length_and_token_type(io)
case token.identifier
when TOKEN_INT
enumerator.yield(token.int)
when TOKEN_DOUBLE
enumerator.yield(token.int)
when TOKEN_STRING
enumerator.yield(io.read(token.int).gsub("\r", "\n"))
when TOKEN_CLASS_NAME
enumerator.yield(ClassName.new(io.read(token.int)))
when TOKEN_CLASS_NAME_REF
enumerator.yield(ClassNameRef.new(token.int))
when OBJECT_LIST
enumerator.yield(ObjectList.new(token.int))
when OBJECT_LIST_NIL
enumerator.yield(nil)
else
enumerator.yield(token)
end
end
end
end
|
.valid_slf0_io?(io) ⇒ Boolean
46
47
48
49
|
# File 'lib/xcoderesultbundleprocessor/slf0/tokenizer.rb', line 46
def self.valid_slf0_io?(io)
return false if io.nil?
io.read(4) == 'SLF0'
end
|