import Cocoa import Darwin import Doubt extension TSInput { init(path: String) { let file = fopen(path, "r") self.init( payload: file, read_fn: { (payload: UnsafeMutablePointer, bytesRead: UnsafeMutablePointer) -> UnsafePointer in var string: UnsafeMutablePointer = nil bytesRead.memory = getline(&string, nil, UnsafeMutablePointer(payload)) return UnsafePointer(string) }, seek_fn: { (payload: UnsafeMutablePointer, position: TSLength) -> Int32 in fseek(UnsafeMutablePointer(payload), position.bytes, SEEK_CUR) }) } } let arguments = BoundsCheckedArray(array: Process.arguments) if let a = arguments[1].map(TSInput.init) { let document = ts_document_make() ts_document_set_language(document, ts_language_javascript()) ts_document_set_input(document, a) ts_document_parse(document) let root = ts_document_root_node(document) print(ts_node_name(root, document)) ts_document_free(document) }