Module: ZergXcode::Parser
- Defined in:
- lib/zerg_xcode/file_format/parser.rb
Overview
Parser for flattened object graphs stored in .xcodeproj files.
Class Method Summary collapse
Class Method Details
.parse(project_string) ⇒ Object
13 14 15 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 45 46 47 48 49 50 |
# File 'lib/zerg_xcode/file_format/parser.rb', line 13 def self.parse(project_string) tokens = ZergXcode::Lexer.tokenize project_string stack = [[]] tokens.each do |token| case token when '(' stack << Array.new when '{' stack << Hash.new when ')', '}' last_object = stack.pop if stack.last.kind_of? Array stack.last << last_object elsif stack.last.kind_of? String hash_key = stack.pop stack.last[hash_key] = last_object end when Array token_string = token.first if stack.last.kind_of? Hash stack << token_string elsif stack.last.kind_of? Array stack.last << token_string elsif stack.last.kind_of? String key = stack.pop stack.last[key] = token_string else p stack raise 'WTFed' end when '=', ';', ',' else raise "Unknown token #{token}" end end return stack[0][0] end |