<commit_before>//
//  XcodeParser.swift
//  SourceKittenDaemon
//
//  Created by <NAME> on 12/11/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

enum ProjectSourceType: String {
    case Swift = "sourcecode.swift"
    case Plist = "text.plist.xml"
    case Framework = "wrapper.framework"
}

struct ProjectObject {
    let type: ProjectSourceType
    let path: String
    let sourceTree: String
}

struct XcodeParser {
    
    let path: String
    
    let proj: XCProjectFile
    
    var frameworks: [ProjectObject]
    
    var projectFiles: [ProjectObject]
    
    let target: PBXNativeTarget
    
    init?(path: String, targetName: String?) {
        
        let xcodeproj = NSURL(fileURLWithPath: path)
        guard let aProject = try? XCProjectFile(xcodeprojURL: xcodeproj)
            else {
                print("Could not read xcode project: \(path)")
                return nil
        }
        
        self.path = path
        self.proj = aProject
        self.frameworks = []
        self.projectFiles = []
        
        /**<commit_msg>Add more specific error reporting for the parser<commit_after>//
//  XcodeParser.swift
//  SourceKittenDaemon
//
//  Created by <NAME> on 12/11/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

enum ProjectSourceType: String {
    case Swift = "sourcecode.swift"
    case Plist = "text.plist.xml"
    case Framework = "wrapper.framework"
}

struct ProjectObject {
    let type: ProjectSourceType
    let path: String
    let sourceTree: String
}

struct XcodeParser {
    
    let path: String
    
    let proj: XCProjectFile
    
    var frameworks: [ProjectObject]
    
    var projectFiles: [ProjectObject]
    
    let target: PBXNativeTarget
    
    init?(path: String, targetName: String?) {
        
        let xcodeproj = NSURL(fileURLWithPath: path)
        print(xcodeproj.path)

        let aProject: XCProjectFile
        do {
            aProject = try XCProjectFile(xcodeprojURL: xcodeproj)
        } catch (let err as ProjectFileError) {
            print(err.description)
            return nil
        } catch (_ as NSError) {
            print("Could not read xcode project: \(path)")
            return nil
        }
        
        self.path = path
        self.proj = aProject
        self.frameworks = []
        self.projectFiles = []
        
        /**
{'fraction_non_alphanumeric': 0.09007506255212677, 'fraction_numerical': 0.008340283569641367, 'mean_word_length': 1.9950062421972534, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1348689', 'n_tokens_mistral': 740, 'n_tokens_neox': 710, 'n_words': 192}