Sha256: 5b189a13015a53b21f20524fd2d820408ee89e830ca526182a66b20bf6470f28
Contents?: true
Size: 1.56 KB
Versions: 1
Compression:
Stored size: 1.56 KB
Contents
class OboFile::Parser def initialize(lexer, builder) @lexer = lexer @builder = builder end def parse_file # toss everything right now, we just want the terms while !@lexer.peek(OboFile::Tokens::Term) @lexer.pop(OboFile::Tokens::TagValuePair) end i = 0 while !@lexer.peek(OboFile::Tokens::Typedef) && !@lexer.peek(OboFile::Tokens::EndOfFile) raise OboFile::ParseError, "infinite loop in Terms" if i > 10000000 parse_term i += 1 end i = 0 while @lexer.peek(OboFile::Tokens::Typedef) raise OboFile::ParseError,"infinite loop in Terms" if i > 1000000 # there aren't that many words! parse_typedef i += 1 end end def parse_term t = @lexer.pop(OboFile::Tokens::Term) tags = [] while !@lexer.peek(OboFile::Tokens::Term) && !@lexer.peek(OboFile::Tokens::Typedef) && !@lexer.peek(OboFile::Tokens::EndOfFile) if @lexer.peek(OboFile::Tokens::TagValuePair) t = @lexer.pop(OboFile::Tokens::TagValuePair) tags.push [t.tag, t.value] else raise(OboFile::ParseError, "Expected a tag-value pair, but did not get one following this tag/value: [#{t.tag} / #{t.value}]") end end @builder.add_term(tags) end def parse_typedef @lexer.pop(OboFile::Tokens::Typedef) # @t = @builder.stub_typdef tags = [] while !@lexer.peek(OboFile::Tokens::Typedef) && @lexer.peek(OboFile::Tokens::TagValuePair) t = @lexer.pop(OboFile::Tokens::TagValuePair) tags.push [t.tag, t.value] end @builder.add_typedef(tags) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
obo_parser-0.1.0 | lib/parser.rb |