rana-cli/wakatime/dependencies/c_cpp.py

52 lines
1.3 KiB
Python
Raw Normal View History

2014-12-23 08:29:58 +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:41:17 +00:00
class CParser(TokenParser):
exclude = [
r'^stdio\.h$',
r'^stdlib\.h$',
r'^string\.h$',
r'^time\.h$',
]
2016-06-13 14:41:17 +00:00
state = None
2014-12-23 08:29:58 +00:00
def parse(self):
2014-12-23 08:29:58 +00:00
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:41:17 +00:00
if self.partial(token) == 'Preproc' or self.partial(token) == 'PreprocFile':
2014-12-23 08:29:58 +00:00
self._process_preproc(token, content)
else:
self._process_other(token, content)
def _process_preproc(self, token, content):
2016-06-13 14:41:17 +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
def _process_other(self, token, content):
pass
2016-06-13 14:41:17 +00:00
class CppParser(CParser):
pass