vim-rana-local/plugin/packages/wakatime/dependencies/c_cpp.py

52 lines
1.3 KiB
Python
Raw Normal View History

2015-09-29 10:10:32 +00:00
# -*- coding: utf-8 -*-
"""
wakatime.languages.c_cpp
~~~~~~~~~~~~~~~~~~~~~~~~
Parse dependencies from C++ code.
:copyright: (c) 2014 Alan Hamlett.
:license: BSD, see LICENSE for more details.
"""
from . import TokenParser
2016-06-13 14:48:11 +00:00
class CParser(TokenParser):
2015-09-29 10:10:32 +00:00
exclude = [
r'^stdio\.h$',
r'^stdlib\.h$',
r'^string\.h$',
r'^time\.h$',
]
2016-06-13 14:48:11 +00:00
state = None
2015-09-29 10:10:32 +00:00
def parse(self):
for index, token, content in self.tokens:
self._process_token(token, content)
return self.dependencies
def _process_token(self, token, content):
2016-06-13 14:48:11 +00:00
if self.partial(token) == 'Preproc' or self.partial(token) == 'PreprocFile':
2015-09-29 10:10:32 +00:00
self._process_preproc(token, content)
else:
self._process_other(token, content)
def _process_preproc(self, token, content):
2016-06-13 14:48:11 +00:00
if self.state == 'include':
if content != '\n' and content != '#':
content = content.strip().strip('"').strip('<').strip('>').strip()
self.append(content, truncate=True, separator='/')
self.state = None
elif content.strip().startswith('include'):
self.state = 'include'
else:
self.state = None
2015-09-29 10:10:32 +00:00
def _process_other(self, token, content):
pass
2016-06-13 14:48:11 +00:00
class CppParser(CParser):
pass