2015-10-26 23:00:52 +03:00
|
|
|
import Cocoa
|
2015-10-27 18:04:00 +03:00
|
|
|
import Darwin
|
2015-10-26 23:00:52 +03:00
|
|
|
import Doubt
|
2015-10-27 18:04:39 +03:00
|
|
|
|
|
|
|
|
2015-10-27 18:04:00 +03:00
|
|
|
extension TSInput {
|
|
|
|
init(path: String) {
|
|
|
|
let file = fopen(path, "r")
|
|
|
|
self.init(
|
|
|
|
payload: file,
|
|
|
|
read_fn: { (payload: UnsafeMutablePointer<Void>, bytesRead: UnsafeMutablePointer<Int>) -> UnsafePointer<Int8> in
|
2015-10-27 18:27:17 +03:00
|
|
|
var string: UnsafeMutablePointer<Int8> = nil
|
|
|
|
bytesRead.memory = getline(&string, nil, UnsafeMutablePointer<FILE>(payload))
|
|
|
|
return UnsafePointer<Int8>(string)
|
2015-10-27 18:04:00 +03:00
|
|
|
},
|
|
|
|
seek_fn: { (payload: UnsafeMutablePointer<Void>, position: TSLength) -> Int32 in
|
|
|
|
fseek(UnsafeMutablePointer<FILE>(payload), position.bytes, SEEK_CUR)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2015-10-26 23:00:52 +03:00
|
|
|
|
2015-10-27 18:04:18 +03:00
|
|
|
let arguments = BoundsCheckedArray(array: Process.arguments)
|
2015-10-27 18:18:05 +03:00
|
|
|
if let a = arguments[1].map(TSInput.init) {
|
2015-10-27 18:04:18 +03:00
|
|
|
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)
|
|
|
|
}
|