| |
|
|
| |
| |
|
|
| |
| |
| |
|
|
| import sys |
| from ctypes import * |
|
|
| |
| libtoken = CDLL('./libtoken.so') |
|
|
| |
| libtoken.C_tokenize.argtypes = (POINTER(c_char_p), |
| POINTER(c_char_p), |
| POINTER(c_uint), |
| POINTER(c_uint), |
| POINTER(c_uint)) |
| libtoken.open_as_stdin.argtypes = (c_char_p,) |
|
|
| |
| _token = c_char_p() |
| _kind = c_char_p() |
| _linenr = c_uint() |
| _column = c_uint() |
| _pos = c_uint() |
|
|
| |
| def token(): |
| global _token, _kind, _linenr, _column, _pos |
|
|
| |
| while int(libtoken.C_tokenize(byref(_token), byref(_kind), byref(_linenr), |
| byref(_column), byref(_pos))): |
| |
| lin = _linenr.value |
| col = _column.value |
| pos = _pos.value |
| clas = _kind.value.decode() |
| text = _token.value.decode() |
| yield (lin,col,clas,text) |
|
|
| if len(sys.argv) == 1: |
| for tok in token(): |
| print('[%u:%u] %s, %s' % tok) |
| else: |
| for file in sys.argv[1:]: |
| |
| b_str = file.encode('utf-8') |
| libtoken.open_as_stdin(b_str) |
|
|
| |
| filename = c_char_p.in_dll(libtoken, 'filename') |
| print('[0:0] filename, %s' % filename.value.decode()) |
|
|
| for tok in token(): |
| print('[%u:%u] %s, %s' % tok) |
|
|
| |
| c_uint.in_dll(libtoken, 'linenr').value = 1 |
| c_uint.in_dll(libtoken, 'column').value = 0 |
| c_uint.in_dll(libtoken, 'char_count').value = 0 |
| c_uint.in_dll(libtoken, 'utf8_count').value = 0 |
|
|